1*bd539124SAndreas Gohr<?php 2*bd539124SAndreas Gohr 3*bd539124SAndreas Gohrclass init_creationmodes_test extends DokuWikiTest 4*bd539124SAndreas Gohr{ 5*bd539124SAndreas Gohr 6*bd539124SAndreas Gohr protected $oldumask; 7*bd539124SAndreas Gohr protected $dir; 8*bd539124SAndreas Gohr protected $file; 9*bd539124SAndreas Gohr 10*bd539124SAndreas Gohr /** @inheritDoc */ 11*bd539124SAndreas Gohr public static function setUpBeforeClass(): void 12*bd539124SAndreas Gohr { 13*bd539124SAndreas Gohr parent::setUpBeforeClass(); 14*bd539124SAndreas Gohr if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 15*bd539124SAndreas Gohr self::markTestSkipped('Permission checks skipped on Windows'); 16*bd539124SAndreas Gohr } 17*bd539124SAndreas Gohr } 18*bd539124SAndreas Gohr 19*bd539124SAndreas Gohr /** 20*bd539124SAndreas Gohr * set up the file and directory we use for testing 21*bd539124SAndreas Gohr */ 22*bd539124SAndreas Gohr protected function init() 23*bd539124SAndreas Gohr { 24*bd539124SAndreas Gohr $this->dir = getCacheName('dir', '.creationmode_test'); 25*bd539124SAndreas Gohr $this->file = getCacheName('bar', '.creationmode_test'); 26*bd539124SAndreas Gohr } 27*bd539124SAndreas Gohr 28*bd539124SAndreas Gohr /** @inheritDoc */ 29*bd539124SAndreas Gohr public function setUp(): void 30*bd539124SAndreas Gohr { 31*bd539124SAndreas Gohr parent::setUp(); 32*bd539124SAndreas Gohr 33*bd539124SAndreas Gohr if (!isset($this->dir)) $this->init(); 34*bd539124SAndreas Gohr $this->oldumask = umask(); 35*bd539124SAndreas Gohr } 36*bd539124SAndreas Gohr 37*bd539124SAndreas Gohr /** @inheritDoc */ 38*bd539124SAndreas Gohr protected function tearDown(): void 39*bd539124SAndreas Gohr { 40*bd539124SAndreas Gohr umask($this->oldumask); 41*bd539124SAndreas Gohr 42*bd539124SAndreas Gohr chmod($this->dir, 0777); 43*bd539124SAndreas Gohr rmdir($this->dir); 44*bd539124SAndreas Gohr 45*bd539124SAndreas Gohr chmod($this->file, 0777); 46*bd539124SAndreas Gohr unlink($this->file); 47*bd539124SAndreas Gohr 48*bd539124SAndreas Gohr parent::tearDown(); 49*bd539124SAndreas Gohr 50*bd539124SAndreas Gohr } 51*bd539124SAndreas Gohr 52*bd539124SAndreas Gohr /** 53*bd539124SAndreas Gohr * @return Generator|string[] 54*bd539124SAndreas Gohr * @see testFilemodes 55*bd539124SAndreas Gohr */ 56*bd539124SAndreas Gohr public function provideFilemodes() 57*bd539124SAndreas Gohr { 58*bd539124SAndreas Gohr $umasks = [0000, 0022, 0002, 0007]; 59*bd539124SAndreas Gohr $fmodes = [0777, 0666, 0644, 0640, 0664, 0660]; 60*bd539124SAndreas Gohr $dmodes = [0777, 0775, 0755, 0750, 0770, 0700]; 61*bd539124SAndreas Gohr 62*bd539124SAndreas Gohr foreach ($umasks as $umask) { 63*bd539124SAndreas Gohr foreach ($dmodes as $dmode) { 64*bd539124SAndreas Gohr foreach ($fmodes as $fmode) { 65*bd539124SAndreas Gohr yield [$umask, $dmode, $fmode]; 66*bd539124SAndreas Gohr } 67*bd539124SAndreas Gohr } 68*bd539124SAndreas Gohr } 69*bd539124SAndreas Gohr } 70*bd539124SAndreas Gohr 71*bd539124SAndreas Gohr /** 72*bd539124SAndreas Gohr * @dataProvider provideFilemodes 73*bd539124SAndreas Gohr */ 74*bd539124SAndreas Gohr public function testFilemodes($umask, $dmode, $fmode) 75*bd539124SAndreas Gohr { 76*bd539124SAndreas Gohr global $conf; 77*bd539124SAndreas Gohr 78*bd539124SAndreas Gohr // setup 79*bd539124SAndreas Gohr $conf['dmode'] = $dmode; 80*bd539124SAndreas Gohr $conf['fmode'] = $fmode; 81*bd539124SAndreas Gohr umask($umask); 82*bd539124SAndreas Gohr 83*bd539124SAndreas Gohr // create 84*bd539124SAndreas Gohr init_creationmodes(); 85*bd539124SAndreas Gohr io_mkdir_p($this->dir); 86*bd539124SAndreas Gohr io_saveFile($this->file, 'test'); 87*bd539124SAndreas Gohr 88*bd539124SAndreas Gohr // get actual values (removing the status bits) 89*bd539124SAndreas Gohr clearstatcache(); 90*bd539124SAndreas Gohr $dperm = fileperms($this->dir) - 0x4000; 91*bd539124SAndreas Gohr $fperm = fileperms($this->file) - 0x8000; 92*bd539124SAndreas Gohr 93*bd539124SAndreas Gohr 94*bd539124SAndreas Gohr $this->assertSame($dmode, $dperm, 95*bd539124SAndreas Gohr sprintf( 96*bd539124SAndreas Gohr 'dir had %04o, expected %04o with umask %04o (fperm: %04o)', 97*bd539124SAndreas Gohr $dperm, $dmode, $umask, $conf['dperm'] 98*bd539124SAndreas Gohr ) 99*bd539124SAndreas Gohr ); 100*bd539124SAndreas Gohr $this->assertSame($fmode, $fperm, 101*bd539124SAndreas Gohr sprintf( 102*bd539124SAndreas Gohr 'file had %04o, expected %04o with umask %04o (fperm: %04o)', 103*bd539124SAndreas Gohr $fperm, $fmode, $umask, $conf['fperm'] 104*bd539124SAndreas Gohr ) 105*bd539124SAndreas Gohr ); 106*bd539124SAndreas Gohr } 107*bd539124SAndreas Gohr 108*bd539124SAndreas Gohr} 109*bd539124SAndreas Gohr 110