removeDirectory ($content); // Recursivly remove directories else unlink ($content); // Remove file } // Now, directory should be empty, remove it rmdir ($dir); } } public function tearDown () { // Make some cleaning :) $this->removeDirectory(self::$assetDir); } public function testInit() { $manager=new TAssetManager (); $manager->init (null); self::assertEquals(self::$assetDir, $manager->getBasePath()); self::assertEquals($manager, self::$app->getAssetManager()); // No, remove asset directory, and catch the exception if (is_dir(self::$assetDir)) $this->removeDirectory (self::$assetDir); try { $manager->init (null); self::fail ('Expected TConfigurationException not thrown'); } catch (TConfigurationException $e) {} } public function testSetBasePath() { $manager = new TAssetManager (); // First try, invalid directory try { $manager->setBasePath('invalid'); self::fail('Expected TInvalidDataValueException not thrown'); } catch (TInvalidDataValueException $e) {} // Next, standard asset directory, should work $manager->setBasePath ('AssetAlias'); self::assertEquals(self::$assetDir, $manager->getBasePath()); // Finally, test to change after init $manager->init (null); try { $manager->setBasePath ('test'); self::fail ('Expected TInvalidOperationException not thrown'); } catch (TInvalidOperationException $e) {} } public function testSetBaseUrl() { $manager=new TAssetManager (); $manager->setBaseUrl ('/assets/'); self::assertEquals("/assets", $manager->getBaseUrl()); $manager->init (null); try { $manager->setBaseUrl ('/test'); self::fail ('Expected TInvalidOperationException not thrown'); } catch (TInvalidOperationException $e) {} } public function testPublishFilePath() { $manager=new TAssetManager(); $manager->setBaseUrl('/'); $manager->init (null); // Try to publish a single file $fileToPublish=dirname(__FILE__).'/data/pradoheader.gif'; $publishedUrl = $manager->publishFilePath($fileToPublish); $publishedFile=self::$assetDir.$publishedUrl; self::assertEquals($publishedFile, $manager->getPublishedPath($fileToPublish)); self::assertEquals($publishedUrl, $manager->getPublishedUrl($fileToPublish)); self::assertTrue(is_file($publishedFile)); // try to publish invalid file try { $manager->publishFilePath('invalid_file'); self::fail('Expected TInvalidDataValueException not thrown'); } catch (TInvalidDataValueException $e) {} } public function testPublishFilePathWithDirectory () { $manager=new TAssetManager(); $manager->setBaseUrl('/'); $manager->init (null); // Try to publish a directory $dirToPublish=dirname(__FILE__).'/data'; $publishedUrl = $manager->publishFilePath($dirToPublish); $publishedDir=self::$assetDir.$publishedUrl; self::assertEquals($publishedDir, $manager->getPublishedPath($dirToPublish)); self::assertEquals($publishedUrl, $manager->getPublishedUrl($dirToPublish)); self::assertTrue(is_dir($publishedDir)); self::assertTrue(is_file($publishedDir.'/pradoheader.gif')); } public function testPublishTarFile() { $manager=new TAssetManager(); $manager->setBaseUrl('/'); $manager->init (null); $tarFile=dirname(__FILE__).'/data/aTarFile.tar'; $md5File=dirname(__FILE__).'/data/aTarFile.md5'; // First, try with bad md5 try { $manager->publishTarFile($tarFile, 'badMd5File'); self::fail('Expected TInvalidDataValueException not thrown'); } catch (TInvalidDataValueException $e) {} // Then, try with real md5 file $publishedUrl=$manager->publishTarFile($tarFile, $md5File); $publishedDir=self::$assetDir.$publishedUrl; self::assertTrue(is_dir($publishedDir)); self::assertTrue(is_file($publishedDir.'/pradoheader.gif')); self::assertTrue(is_file($publishedDir.'/aTarFile.md5')); } } ?>