summaryrefslogtreecommitdiff
path: root/tests/unit/Web/TAssetManagerTest.php
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2014-01-15 19:05:25 +0100
committerFabio Bas <ctrlaltca@gmail.com>2014-01-15 19:05:25 +0100
commit2fdb1e997f030155bd6648f9d72a77ccecda0324 (patch)
treede5d34a1c45bb99fa973e7577969a26cb65155ad /tests/unit/Web/TAssetManagerTest.php
parentfa51a0a2e3ce4ec4a82a5d2f53fbd50cfcb16528 (diff)
Removed ?> from tests
Diffstat (limited to 'tests/unit/Web/TAssetManagerTest.php')
-rw-r--r--tests/unit/Web/TAssetManagerTest.php57
1 files changed, 28 insertions, 29 deletions
diff --git a/tests/unit/Web/TAssetManagerTest.php b/tests/unit/Web/TAssetManagerTest.php
index 89349a0d..13d2d6c1 100644
--- a/tests/unit/Web/TAssetManagerTest.php
+++ b/tests/unit/Web/TAssetManagerTest.php
@@ -26,26 +26,26 @@ class TAssetManagerTest extends PHPUnit_Framework_TestCase {
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3';
$_SERVER['REMOTE_HOST'] = 'localhost';
-
+
if (self::$app===null) {
self::$app=new TApplication(dirname(__FILE__).'/app');
}
-
+
if (self::$assetDir===null) self::$assetDir= dirname(__FILE__).'/assets';
- // Make asset directory if not exists
+ // Make asset directory if not exists
if (!file_exists (self::$assetDir)) {
- if (is_writable(dirname(self::$assetDir)))
+ if (is_writable(dirname(self::$assetDir)))
mkdir (self::$assetDir) ;
- else
+ else
throw new Exception ('Directory '.dirname(self::$assetDir).' is not writable');
} elseif (!is_dir (self::$assetDir)) {
throw new Exception (self::$assetDir.' exists and is not a directory');
}
// Define an alias to asset directory
prado::setPathofAlias('AssetAlias', self::$assetDir);
-
+
}
-
+
private function removeDirectory ($dir) {
// Let's be sure $dir is a directory to avoir any error. Clear the cache !
clearstatcache();
@@ -53,7 +53,7 @@ class TAssetManagerTest extends PHPUnit_Framework_TestCase {
foreach (scandir($dir) as $content) {
if ($content==='.' or $content==='..') continue; // skip . and ..
$content=$dir.'/'.$content;
- if (is_dir($content))
+ if (is_dir($content))
$this->removeDirectory ($content); // Recursivly remove directories
else
unlink ($content); // Remove file
@@ -62,21 +62,21 @@ class TAssetManagerTest extends PHPUnit_Framework_TestCase {
rmdir ($dir);
}
}
-
+
public function tearDown () {
// Make some cleaning :)
- $this->removeDirectory(self::$assetDir);
+ $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 {
@@ -92,12 +92,12 @@ class TAssetManagerTest extends PHPUnit_Framework_TestCase {
$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 {
@@ -111,20 +111,20 @@ class TAssetManagerTest extends PHPUnit_Framework_TestCase {
$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);
@@ -132,19 +132,19 @@ class TAssetManagerTest extends PHPUnit_Framework_TestCase {
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);
@@ -153,23 +153,23 @@ class TAssetManagerTest extends PHPUnit_Framework_TestCase {
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;
@@ -178,5 +178,4 @@ class TAssetManagerTest extends PHPUnit_Framework_TestCase {
self::assertTrue(is_file($publishedDir.'/aTarFile.md5'));
}
-}
-?> \ No newline at end of file
+} \ No newline at end of file