How to use testUnlink method of file class

Best Atoum code snippet using file.testUnlink

SugarAutoLoaderTest.php

Source:SugarAutoLoaderTest.php Github

copy

Full Screen

1<?php2/*3 * Your installation or use of this SugarCRM file is subject to the applicable4 * terms available at5 * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.6 * If you do not agree to all of the applicable terms or do not have the7 * authority to bind the entity as an authorized representative, then do not8 * install or use this SugarCRM file.9 *10 * Copyright (C) SugarCRM Inc. All rights reserved.11 */12class SugarAutoLoaderTest extends Sugar_PHPUnit_Framework_TestCase13{14 protected $todelete = array();15 public static function tearDownAfterClass()16 {17 // rebuild the map JIC18 SugarAutoLoader::buildCache();19 }20 public function tearDown()21 {22 foreach($this->todelete as $file) {23 if(is_dir($file)) {24 rmdir_recursive($file);25 SugarAutoLoader::delFromMap($file, false);26 continue;27 }28 @SugarAutoLoader::unlink($file);29 }30 $this->todelete = array();31 }32 protected function touch($file)33 {34 $this->todelete[] = $file;35 SugarAutoLoader::touch($file);36 }37 protected function put($file, $data)38 {39 $this->todelete[] = $file;40 SugarAutoLoader::put($file, $data);41 }42 public function testFileExists()43 {44 $this->assertTrue(SugarAutoLoader::fileExists("index.php"));45 $this->assertTrue(SugarAutoLoader::fileExists("custom///modules"));46 }47 public function testExisting()48 {49 $this->assertEquals(array('index.php'), SugarAutoLoader::existing("index.php", "index-foo.php"));50 }51 public function testNotExisting()52 {53 $this->assertEmpty(SugarAutoLoader::existing("nosuchfile.test1"));54 }55 public function testAdd()56 {57 $this->assertEmpty(SugarAutoLoader::existing("nosuchfile.test2", "some/dir/nosuchfile.test3"));58 SugarAutoLoader::addToMap("nosuchfile.test2");59 $this->assertTrue(SugarAutoLoader::fileExists("nosuchfile.test2"));60 SugarAutoLoader::addToMap("some/dir/nosuchfile.test3");61 $this->assertTrue(SugarAutoLoader::fileExists("some/dir/nosuchfile.test3"));62 }63 public function testDel()64 {65 $this->assertEmpty(SugarAutoLoader::existing("nosuchfile.test4", "some/dir/nosuchfile.test5"));66 SugarAutoLoader::addToMap("nosuchfile.test4");67 SugarAutoLoader::addToMap("some/dir/nosuchfile.test5");68 $this->assertTrue(SugarAutoLoader::fileExists("some/dir/nosuchfile.test5"));69 SugarAutoLoader::delFromMap("nosuchfile.test4", false);70 SugarAutoLoader::delFromMap("some/dir/nosuchfile.test5", false);71 $this->assertEmpty(SugarAutoLoader::existing("nosuchfile.test4", "some/dir/nosuchfile.test5"));72 }73 // load74 public function testLoad()75 {76 $res = SugarAutoLoader::load("include/JSON.php");77 $this->assertTrue($res);78 // test second time still returns true79 $res = SugarAutoLoader::load("include/JSON.php");80 $this->assertTrue($res);81 // not existing82 $res = SugarAutoLoader::load("nosuchfile.php");83 $this->assertFalse($res);84 }85 // requireWithCustom86 public function testRequireWithCustom()87 {88 $this->put("_test.php", "<?php class TestAutoLoader {}");89 SugarAutoLoader::requireWithCustom("_test.php");90 $this->assertTrue(class_exists("TestAutoLoader"), "Class TestAutoLoader does not exist!");91 $this->assertFalse(class_exists("CustomTestAutoLoader"), "Class TestAutoLoader should not exist!");92 $this->put("custom/_test.php", "<?php class CustomTestAutoLoader {}");93 SugarAutoLoader::requireWithCustom("_test.php");94 $this->assertTrue(class_exists("CustomTestAutoLoader"), "Class TestAutoLoader does not exist!");95 }96 // existingCustom97 public function testExistingCustom()98 {99 $this->touch("custom/index.php");100 $this->touch("custom/index2.php");101 $this->assertEquals(102 array('index.php', "custom/index.php", "custom/index2.php"),103 SugarAutoLoader::existingCustom("index.php", "index2.php", "index-foo.php"));104 }105 // existingCustomOne106 public function testExistingCustomOne()107 {108 // none109 $this->assertEmpty( SugarAutoLoader::existingCustomOne("index-foo.php", "blah.php"));110 // only root111 $this->assertEquals("index.php", SugarAutoLoader::existingCustomOne("index.php", "index2.php", "index-foo.php"));112 // only custom113 $this->touch("custom/index2.php");114 $this->assertEquals("custom/index2.php", SugarAutoLoader::existingCustomOne("index.php", "index2.php", "index-foo.php"));115 // custom & root116 $this->touch("index2.php");117 $this->assertEquals("custom/index2.php", SugarAutoLoader::existingCustomOne("index.php", "index2.php", "index-foo.php"));118 }119 // getDirFiles120 public function testGetDirFiles()121 {122 $this->touch("custom/blah1.php");123 $this->touch("custom/blah2.php");124 $this->touch("custom/blah3.php");125 $res = SugarAutoLoader::getDirFiles("custom");126 $this->assertContains("custom/blah1.php", $res);127 $this->assertContains("custom/blah2.php", $res);128 $this->assertContains("custom/blah3.php", $res);129 // directories130 $res = SugarAutoLoader::getDirFiles("custom/", true);131 $this->assertContains("custom/modules", $res);132 }133 // getDirFilesExt134 public function testGetDirFilesExt()135 {136 $this->touch("custom/blah1.php");137 $this->touch("custom/blah2.txt");138 $this->touch("custom/blah3.php");139 $res = SugarAutoLoader::getDirFiles("custom", false, ".php");140 $this->assertContains("custom/blah1.php", $res);141 $this->assertNotContains("custom/blah2.txt", $res);142 $this->assertContains("custom/blah3.php", $res);143 $res = SugarAutoLoader::getDirFiles("custom", false, "txt");144 $this->assertContains("custom/blah2.txt", $res);145 }146 // getFilesCustom147 public function testGetFilesCustom()148 {149 $this->touch("custom/include/blah1.php");150 $this->touch("include/blah2.php");151 $this->touch("include/blah3.php");152 $this->touch("custom/include/blah3.php");153 $res = SugarAutoLoader::getFilesCustom("include");154 $this->assertContains("custom/include/blah1.php", $res);155 $this->assertContains("include/blah2.php", $res);156 $this->assertContains("include/blah3.php", $res);157 $this->assertContains("custom/include/blah3.php", $res);158 // directories159 if(!is_dir("custom/include/language")) {160 mkdir_recursive("custom/include/language");161 SugarAutoLoader::addToMap("custom/include/language/dummy.php");162 }163 $res = SugarAutoLoader::getFilesCustom("include", true);164 $this->assertContains("include/utils", $res);165 $this->assertContains("custom/include/language", $res);166 }167 // customClass168 public function testCustomClass()169 {170 $this->assertEquals("BlahBlahNotExisting", SugarAutoLoader::customClass("BlahBlahNotExisting"));171 $this->assertEquals("Exception", SugarAutoLoader::customClass("Exception"));172 $this->put("custom/_test.php", "<?php class CustomTestAutoLoader {}");173 SugarAutoLoader::requireWithCustom("_test.php");174 $this->assertEquals("CustomTestAutoLoader", SugarAutoLoader::customClass("TestAutoLoader"));175 }176 // lookupFile177 public function testLookupFile()178 {179 $this->touch("custom/include/blah1.php");180 $this->assertEquals("custom/include/blah1.php", SugarAutoLoader::lookupFile(array("modules", "include", "Zend"), "blah1.php"));181 $this->touch("include/blah2.php");182 $this->assertEquals("include/blah2.php", SugarAutoLoader::lookupFile(array("modules", "include", "Zend"), "blah2.php"));183 $this->touch("custom/include/blah2.php");184 $this->assertEquals("custom/include/blah2.php", SugarAutoLoader::lookupFile(array("modules", "include", "Zend"), "blah2.php"));185 }186 // touch & unlink187 public function testTouchUnlink()188 {189 $this->todelete[] = "custom/testunlink.php";190 SugarAutoLoader::touch("custom/testunlink.php");191 $this->assertTrue(file_exists("custom/testunlink.php"), "File does not exist!");192 $this->assertTrue(SugarAutoLoader::fileExists("custom/testunlink.php"), "File does not exist in the map!");193 SugarAutoLoader::unlink("custom/testunlink.php");194 $this->assertFalse(file_exists("custom/testunlink.php"), "File should not exist!");195 $this->assertFalse(SugarAutoLoader::fileExists("custom/testunlink.php"), "File should not exist in the map!");196 array_pop($this->todelete);197 }198 // put & unlink199 public function testPutUnlink()200 {201 $this->todelete[] = "custom/testunlink.php";202 SugarAutoLoader::put("custom/testunlink.php", "TESTDATA");203 $this->assertTrue(file_exists("custom/testunlink.php"), "File does not exist!");204 $this->assertEquals("TESTDATA", file_get_contents("custom/testunlink.php"));205 $this->assertTrue(SugarAutoLoader::fileExists("custom/testunlink.php"), "File does not exist in the map!");206 SugarAutoLoader::unlink("custom/testunlink.php");207 $this->assertFalse(file_exists("custom/testunlink.php"), "File should not exist!");208 $this->assertFalse(SugarAutoLoader::fileExists("custom/testunlink.php"), "File should not exist in the map!");209 array_pop($this->todelete);210 }211 // loadExtension212 public function testLoadExtension()213 {214 mkdir_recursive("custom/modules/AutoLoaderTest/Ext/Layoutdefs/");215 $this->touch("custom/modules/AutoLoaderTest/Ext/Layoutdefs/layoutdefs.ext.php");216 $this->todelete[] = "custom/modules/AutoLoaderTest/";217 $this->assertEquals("custom/modules/AutoLoaderTest/Ext/Layoutdefs/layoutdefs.ext.php", SugarAutoLoader::loadExtension("layoutdefs", "AutoLoaderTest"));218 $this->assertEmpty(SugarAutoLoader::loadExtension("vardefs", "AutoLoaderTest"));219 if(!file_exists("custom/application/Ext/Layoutdefs/layoutdefs.ext.php")) {220 mkdir_recursive("custom/application/Ext/Layoutdefs/");221 $this->touch("custom/application/Ext/Layoutdefs/layoutdefs.ext.php");222 }223 $this->assertEquals("custom/application/Ext/Layoutdefs/layoutdefs.ext.php", SugarAutoLoader::loadExtension("layoutdefs"));224 if(!file_exists("custom/modules/Schedulers/Ext/ScheduledTasks/scheduledtasks.ext.php")) {225 mkdir_recursive("custom/modules/Schedulers/Ext/ScheduledTasks/");226 $this->touch("custom/modules/Schedulers/Ext/ScheduledTasks/scheduledtasks.ext.php");227 }228 $this->assertEquals("custom/modules/Schedulers/Ext/ScheduledTasks/scheduledtasks.ext.php", SugarAutoLoader::loadExtension("schedulers", "AutoLoaderTest"));229 }230 // loadWithMetafiles231 public function testLoadWithMetafiles()232 {233 /*234 * 1. Check custom/module/metadata/$varname.php235 * 2. If not there, check metafiles.php236 * 3. If still not found, use module/metadata/$varname.php237 */238 mkdir_recursive("custom/modules/AutoLoaderTest/metadata");239 mkdir_recursive("modules/AutoLoaderTest/metadata");240 $this->todelete[] = "custom/modules/AutoLoaderTest/";241 $this->todelete[] = "modules/AutoLoaderTest/";242 $this->assertEmpty(SugarAutoLoader::loadWithMetafiles("AutoLoaderTest", "editviewdefs"));243 // root244 $this->touch("modules/AutoLoaderTest/metadata/editviewdefs.php");245 $this->assertEquals("modules/AutoLoaderTest/metadata/editviewdefs.php", SugarAutoLoader::loadWithMetafiles("AutoLoaderTest", "editviewdefs"));246 $this->assertEmpty(SugarAutoLoader::loadWithMetafiles("AutoLoaderTest", "editviewdefsblah", "editviewdefs"));247 // metafiles248 $metafiles['AutoLoaderTest'] = array("editviewdefs" => "modules/AutoLoaderTest/metadata/meta-editviewdefs.php");249 $this->put("modules/AutoLoaderTest/metadata/metafiles.php", "<?php \$metafiles = ".var_export($metafiles, true).";");250 $this->assertEquals("modules/AutoLoaderTest/metadata/editviewdefs.php",251 SugarAutoLoader::loadWithMetafiles("AutoLoaderTest", "editviewdefs"));252 $this->assertEmpty(SugarAutoLoader::loadWithMetafiles("AutoLoaderTest", "editviewdefsblah", "editviewdefs"));253 // now create meta-defs254 $this->touch("modules/AutoLoaderTest/metadata/meta-editviewdefs.php");255 $this->assertEquals("modules/AutoLoaderTest/metadata/meta-editviewdefs.php",256 SugarAutoLoader::loadWithMetafiles("AutoLoaderTest", "editviewdefs"));257 // now custom258 $this->touch("custom/modules/AutoLoaderTest/metadata/editviewdefs.php");259 $this->assertEquals("custom/modules/AutoLoaderTest/metadata/editviewdefs.php",260 SugarAutoLoader::loadWithMetafiles("AutoLoaderTest", "editviewdefs"));261 // other def262 $this->touch("modules/AutoLoaderTest/metadata/detailviewdefs.php");263 $this->assertEquals("modules/AutoLoaderTest/metadata/detailviewdefs.php",264 SugarAutoLoader::loadWithMetafiles("AutoLoaderTest", "detailviewdefs"));265 }266 // loadPopupMeta267 public function testLoadPopupMeta()268 {269 mkdir_recursive("custom/modules/AutoLoaderTest/metadata");270 $this->todelete[] = "custom/modules/AutoLoaderTest/";271 $this->assertEmpty(SugarAutoLoader::loadPopupMeta("AutoLoaderTest", "editviewdefs"));272 // popup273 $this->put("custom/modules/AutoLoaderTest/metadata/popupdefs.php", "<?php \$popupMeta = 'TEST1'; ");274 $this->assertEquals("TEST1", SugarAutoLoader::loadPopupMeta("AutoLoaderTest", "editviewdefs"));275 // other276 $this->put("custom/modules/AutoLoaderTest/metadata/otherdefs.php", "<?php \$popupMeta = 'TEST2'; ");277 $this->assertEquals("TEST2", SugarAutoLoader::loadPopupMeta("AutoLoaderTest", "otherdefs"));278 }279 public function ensureDirTest()280 {281 SugarAutoLoader::ensureDir("custom/testdir/testdir2");282 $this->todelete[] = "custom/testdir";283 $this->asserTrue(is_dir("custom/testdir/testdir2"), "test dir create failed");284 $this->asserTrue(SugarAutoLoader::fileExists("custom/testdir/testdir2"), "test dir not in cache");285 SugarAutoLoader::put("custom/testdir/testdir2/testfile.php", "test");286 $this->asserTrue(SugarAutoLoader::fileExists("custom/testdir/testdir2/testfile.php"), "test file not in cache");287 }288 /**289 * @dataProvider providerPaths290 */291 public function testNormalizeFilePath($baseDir, $fileName, $ds, $expected)292 {293 $baseDirsOriginal = SugarAutoLoaderMock::getBaseDirs();294 SugarAutoLoaderMock::setDs($ds);295 SugarAutoLoaderMock::setBaseDirs(array($baseDir));296 $path = SugarAutoLoaderMock::normalizeFilePath($fileName);297 // Should convert absolute path to relative298 $this->assertEquals($expected, $path);299 SugarAutoLoaderMock::setBaseDirs($baseDirsOriginal);300 SugarAutoLoaderMock::setDs(DIRECTORY_SEPARATOR);301 }302 public function providerPaths()303 {304 return array(305 // Windows network path306 array(307 // All slashes are converted to forward slashes, due to entryPoint.php308 "//VMSTACK127/WWWROOT/SugarPro-Full-7.6.1.0",309 "\\\\VMSTACK127\\WWWROOT\\SugarPro-Full-7.6.1.0/include",310 "\\",311 "include"312 ),313 // Windows local path314 array(315 "C:/inetpub/wwwroot/SugarPro-Full-7.6.1.0",316 "C:\\inetpub\\wwwroot/SugarPro-Full-7.6.1.0/include",317 "\\",318 "include"319 ),320 // Linux/UNIX path321 array(322 "/Users/boro/dev/www/sugar1.com",323 "/Users/boro/dev/www/sugar1.com/include",324 "/",325 "include"326 )327 );328 }329}330/**331 * Mock class for SugarAutoLoader332 */333class SugarAutoLoaderMock extends SugarAutoLoader334{335 public static function getBaseDirs()336 {337 return self::$baseDirs;338 }339 public static function setBaseDirs($value)340 {341 self::$baseDirs = $value;342 }343 public static function setDs($value)344 {345 self::$ds = $value;346 }347}...

Full Screen

Full Screen

StreamWrapperTest.php

Source:StreamWrapperTest.php Github

copy

Full Screen

...85 }86 /**87 * Tests if the stream wrapper unlinks a file.88 */89 public function testUnlink()90 {91 $this->assertTrue(unlink('test://domain/directory/with-a-file.ext'));92 $this->assertFileNotExists(__DIR__.'/../Resources/directory/with-a-file.ext');93 }94 /**95 * Tests if unlinking a file fails on a read-only stream.96 */97 public function testUnlinkFailsOnReadOnlyStream()98 {99 $this->assertFalse(touch('test-read://domain/file.ext'));100 }101 /**102 * Tests if the stream wrapper reads a file.103 */104 public function testReadFile()105 {106 $this->assertSame("contents\n", file_get_contents('test://domain/file.ext'));107 }108 /**109 * Tests if the stream wrapper writes to a file.110 *111 * @depends testUnlink112 */113 public function testWriteFile()114 {115 $this->assertSame(9, file_put_contents('test://domain/written-file.ext', "contents\n"));116 $this->assertFileExists(__DIR__.'/../Resources/written-file.ext');117 unlink('test://domain/written-file.ext');118 }119 /**120 * Tests if writing to a file fails on a read-only stream.121 */122 public function testWriteFileFailsOnReadOnlyStream()123 {124 $this->assertFalse(@file_put_contents('test-read://domain/written-file.ext', "contents\n"));125 }...

Full Screen

Full Screen

ManifestManagerTest.php

Source:ManifestManagerTest.php Github

copy

Full Screen

...21 $this->vendorPath = __DIR__.'/__fixtures__/vendor/',22 $this->manifestPath = __DIR__.'/__fixtures__/extensions.php'23 );24 }25 public function testUnlink()26 {27 $this->assertInstanceOf(ManifestManager::class, $this->getManifestManager()->unlink());28 $this->assertFalse(file_exists($this->manifestPath));29 }30}...

Full Screen

Full Screen

testUnlink

Using AI Code Generation

copy

Full Screen

1require_once 'file.php';2$file = new File();3$file->testUnlink();4require_once 'file.php';5$file = new File();6$file->testUnlink();7{8 public function testUnlink()9 {10 $file = 'test.txt';11 $file = fopen($file, 'w');12 fclose($file);13 $file = 'test.txt';14 if (unlink($file)) {15 echo 'File deleted successfully';16 } else {17 echo 'Failed to delete the file';18 }19 }20}21require_once 'file.php';22$file = new File();23$file->testUnlink();24require_once 'file.php';25$file = new File();26$file->testUnlink();27{28 public function testUnlink()29 {30 $file = 'test.txt';31 $file = fopen($file, 'w');32 fclose($file);33 $file = 'test.txt';34 if (unlink($file)) {35 echo 'File deleted successfully';36 } else {37 echo 'Failed to delete the file';38 }39 }40}41require_once 'file.php';42$file = new File();43$file->testUnlink();44require_once 'file.php';45$file = new File();46$file->testUnlink();47{48 public function testUnlink()49 {50 $file = 'test.txt';51 $file = fopen($file, 'w');52 fclose($file);53 $file = 'test.txt';54 if (unlink($file)) {55 echo 'File deleted successfully';56 } else {57 echo 'Failed to delete the file';58 }59 }60}61require_once 'file.php';62$file = new File();63$file->testUnlink();

Full Screen

Full Screen

testUnlink

Using AI Code Generation

copy

Full Screen

1require_once('file.php');2$test = new file();3$test->testUnlink('test.txt');4require_once('file.php');5$test = new file();6$test->testRename('test.txt', 'test1.txt');7require_once('file.php');8$test = new file();9$test->testCopy('test.txt', 'test1.txt');10require_once('file.php');11$test = new file();12$test->testFileExists('test.txt');13require_once('file.php');14$test = new file();15$test->testIsFile('test.txt');16require_once('file.php');17$test = new file();18$test->testIsDir('test');19require_once('file.php');20$test = new file();21$test->testIsReadable('test.txt');22require_once('file.php');23$test = new file();24$test->testIsWritable('test.txt');25require_once('file.php');26$test = new file();27$test->testIsExecutable('test.txt');

Full Screen

Full Screen

testUnlink

Using AI Code Generation

copy

Full Screen

1require_once('file.php');2$obj = new file();3$obj->testUnlink();4unlink('1.php'): 15PHP File Handling: PHP fopen() Function6PHP File Handling: PHP fwrite() Function7PHP File Handling: PHP fread() Function8PHP File Handling: PHP feof() Function9PHP File Handling: PHP fclose() Function10PHP File Handling: PHP copy() Function11PHP File Handling: PHP rename() Function12PHP File Handling: PHP file_exists() Function13PHP File Handling: PHP filesize() Function14PHP File Handling: PHP file() Function15PHP File Handling: PHP file_get_contents() Function16PHP File Handling: PHP file_put_contents() Function17PHP File Handling: PHP fileatime() Function18PHP File Handling: PHP filectime() Function19PHP File Handling: PHP filemtime() Function20PHP File Handling: PHP fileowner() Function21PHP File Handling: PHP filegroup() Function22PHP File Handling: PHP fileperms() Function23PHP File Handling: PHP fileinode() Function24PHP File Handling: PHP filetype() Function25PHP File Handling: PHP is_writable() Function26PHP File Handling: PHP is_readable() Function27PHP File Handling: PHP is_executable() Function28PHP File Handling: PHP is_file() Function29PHP File Handling: PHP is_dir() Function30PHP File Handling: PHP is_link() Function31PHP File Handling: PHP stat() Function32PHP File Handling: PHP lstat() Function33PHP File Handling: PHP chown() Function34PHP File Handling: PHP chgrp() Function35PHP File Handling: PHP chmod() Function36PHP File Handling: PHP touch() Function37PHP File Handling: PHP clearstatcache() Function38PHP File Handling: PHP disk_total_space() Function39PHP File Handling: PHP disk_free_space() Function40PHP File Handling: PHP diskfreespace() Function41PHP File Handling: PHP realpath() Function42PHP File Handling: PHP link() Function43PHP File Handling: PHP readlink() Function44PHP File Handling: PHP symlink() Function45PHP File Handling: PHP linkinfo() Function46PHP File Handling: PHP tempnam() Function47PHP File Handling: PHP tmpfile() Function48PHP File Handling: PHP parse_ini_file() Function49PHP File Handling: PHP parse_ini_string() Function

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful