/** * testPermissions method * * @return void */ public function testPermissions() { $this->skipIf(DIRECTORY_SEPARATOR === '\\', 'File permissions tests not supported on Windows.'); $dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'permissions' . DIRECTORY_SEPARATOR; $old = umask(); umask(02); $filename = $dir . 'permission_' . uniqid(); $expecting = decoct(0664 & ~umask()); $file = new File($filename, true); $fileInfo = new FileInfo($file); $result = $fileInfo->permissions(); $this->assertEquals($expecting, $result); $file->delete(); umask(022); $filename = $dir . 'permission_' . uniqid(); $expecting = decoct(0644 & ~umask()); $file = new File($filename, true); $fileInfo = new FileInfo($file); $result = $fileInfo->permissions(); $this->assertEquals($expecting, $result); $file->delete(); umask(0422); $filename = $dir . 'permission_' . uniqid(); $expecting = decoct(0244 & ~umask()); $file = new File($filename, true); $fileInfo = new FileInfo($file); $result = $fileInfo->permissions(); $this->assertEquals($expecting, $result); $file->delete(); umask(0444); $filename = $dir . 'permission_' . uniqid(); $expecting = decoct(0222 & ~umask()); $file = new File($filename, true); $fileInfo = new FileInfo($file); $result = $fileInfo->permissions(); $this->assertEquals($expecting, $result); $file->delete(); umask($old); }
/** * testReplaceText method * * @return void */ public function testReplaceText() { $TestFile = new File(TEST_ROOT . '/Fixture/FileTest.txt'); $TmpFile = new File(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'cakephp.file.test.tmp', true); // Copy the test file to the temporary location $TestFile->copy($TmpFile->getPath(), true); // Replace the contents of the temporary file $result = $TmpFile->replaceText('welcome.php', 'welcome.tmp'); $this->assertTrue($result); // Double check $expected = 'This is the welcome.tmp file in vendors directory'; $contents = $TmpFile->read(); $this->assertContains($expected, $contents); $search = ['This is the', 'welcome.php file', 'in tmp directory']; $replace = ['This should be a', 'welcome.tmp file', 'in the Lib directory']; // Replace the contents of the temporary file $result = $TmpFile->replaceText($search, $replace); $this->assertTrue($result); // Double check $expected = 'This should be a welcome.tmp file in vendors directory'; $contents = $TmpFile->read(); $this->assertContains($expected, $contents); $TmpFile->delete(); }