function cleanSymlinks() { // Do symlink cleanup printf("[%10s] Cleaning up symlinks.\n", 'FINAL'); $cmd = binarypool_config::getUtilityPath('symlinks'); system("{$cmd} -cdrs " . binarypool_config::getRoot() . "*/created"); system("{$cmd} -cdrs " . binarypool_config::getRoot() . "*/expiry"); system("{$cmd} -cdrsv " . binarypool_config::getRoot() . "*/downloaded |grep '/dev/null' |xargs -0 rm"); }
/** * The getExpired call should return an asset which file expired * yesterday. */ function testGetExpiredYesterday() { $assetId = '096dfa489bc3f21df56eded2143843f135ae967e'; $asset = $this->storage->save('IMAGE', array('_' => array('file' => $this->testfile))); $date = date('Y/m/d', strtotime('-1 days')); $viewToday = self::$BUCKET . 'expiry/' . $date . '/' . $assetId; mkdir(dirname($viewToday), 0755, true); symlink(dirname(binarypool_config::getRoot() . $asset), $viewToday); $this->assertEqual(array('test/09/096dfa489bc3f21df56eded2143843f135ae967e/index.xml'), binarypool_browser::getExpired('test')); }
public function __construct($root = null) { if (is_null($root)) { if (binarypool_config::getRoot() == '') { throw new binarypool_exception(107, 500, "Binary Pool path is not configured."); } $root = binarypool_config::getRoot(); } if ($root[strlen($root) - 1] !== '/') { $root .= '/'; } $this->root = $root; }
function setUp() { parent::setUp(); // Remove bucket $bucket = binarypool_config::getRoot() . 'test/'; if (file_exists($bucket)) { $this->deltree($bucket); } // Remove trash if (file_exists(binarypool_config::getRoot() . 'Trash/')) { $this->deltree(binarypool_config::getRoot() . 'Trash/'); } }
function setUp() { self::$BUCKET = binarypool_config::getRoot() . 'test/'; // Remove bucket if (file_exists(self::$BUCKET)) { $this->deltree(self::$BUCKET); } // Remove trash if (file_exists(binarypool_config::getRoot() . 'Trash/')) { $this->deltree(binarypool_config::getRoot() . 'Trash/'); } $this->testfile = realpath(dirname(__FILE__) . '/res/vw_golf.jpg'); }
function walk_dir($root, $callback, $exclude = array()) { $fsroot = binarypool_config::getRoot(); $root = rtrim($root, '/') . '/'; $queue = array($root); foreach ($exclude as &$path) { $path = $root . trim($path, '/') . '/'; } while ($base = array_shift($queue)) { $relative = substr($base, strlen($fsroot)); $callback($relative); if ($handle = opendir($base)) { while (($child = readdir($handle)) !== FALSE) { if (is_dir($base . $child) && $child != '.' && $child != '..') { $combined_path = $base . $child . '/'; if (!in_array($combined_path, $exclude)) { array_push($queue, $combined_path); } } } closedir($handle); } } }
function testGetRenditionDirectory() { $storage = new binarypool_storage_driver_file(); $this->assertEqual($storage->getRenditionsDirectory('files/abc/def'), binarypool_config::getRoot() . 'files/abc/def/'); }
/** * Create an asset XML with an absolute base path and reload it. */ function testAssetPersistanceWithAbsoluteBasePath() { $basepath = 'test/somehashhere/'; $absBasepath = binarypool_config::getRoot() . $basepath; mkdir($absBasepath, 0755, true); $asset = $this->testAssetWithAbsoluteBasePath(); file_put_contents($absBasepath . 'index.xml', $asset->getXML()); // Load XML from FS $asset = new binarypool_asset($this->getDummyStorage(), $basepath . 'index.xml'); $xml = $asset->getXML(); $dom = DOMDocument::loadXML($xml); $xp = new DOMXPath($dom); // Test that the same information is still around $this->assertXPath($xp, '/registry/@version', '3.0'); $this->assertXPath($xp, '/registry/items/item/location', 'http://bin.staticlocal.ch/vw_golf.jpg'); $this->assertXPath($xp, '/registry/items/item/location/@absolute', 'true'); $this->assertXPath($xp, '/registry/items/item/mimetype', 'image/jpeg'); $this->assertXPath($xp, '/registry/items/item/size', '51941'); return $asset; }
/** * Checks the correct behaviour when updating an asset's expiry date. * The old symbolic link should be deleted and the new one created. */ function testUpdateExpireDateView() { // Paths to assert against $date = date('Y/m/d', strtotime('+2 days')); $viewExpires2Days = self::$BUCKET . 'expiry/' . $date . '/' . $this->assetId; $date = date('Y/m/d', strtotime('+9 days')); $viewExpires9Days = self::$BUCKET . 'expiry/' . $date . '/' . $this->assetId; $asset = new binarypool_asset($this->getDummyStorage(), $this->assetFile); $asset->setExpiry(strtotime('+2 days')); file_put_contents(binarypool_config::getRoot() . $this->assetFile, $asset->getXML()); // First view correctly created? binarypool_views::created('test', $this->assetFile, array()); $this->assertTrue(file_exists($viewExpires2Days), 'Asset was not put into the first expiration date view.'); $this->assertTrue(file_exists($viewExpires2Days . '/index.xml'), 'Asset file does not exist in the first expiration date view.'); // Update $oldAsset = new binarypool_asset($this->getDummyStorage(), $this->assetFile); $asset = new binarypool_asset($this->getDummyStorage(), $this->assetFile); $asset->setExpiry(strtotime('+9 days')); file_put_contents(binarypool_config::getRoot() . $this->assetFile, $asset->getXML()); // Second view correctly created? binarypool_views::updated('test', $this->assetFile, $oldAsset); $this->assertTrue(file_exists($viewExpires9Days), 'Asset was not put into the new expiration date view.'); $this->assertTrue(file_exists($viewExpires9Days . '/index.xml'), 'Asset file does not exist in the new expiration date view.'); // First view correctly deleted? binarypool_views::created('test', $this->assetFile, array()); $this->assertFalse(file_exists($viewExpires2Days), 'Asset was not deleted from the first expiration date view.'); }
/** * Fix the extension of manually uploaded renditions. */ function testSaveRenditionFixExtension() { $this->assertFalse(file_exists(self::$BUCKET . 'cb/cbf9f9f453acaba556e00b48951815da5611f975/vw_golf_smaller.jpg')); $asset = $this->storage->save('IMAGE', array('_' => array('file' => dirname(__FILE__) . '/../res/vw_golf_smaller.jpg'), 'detailpage' => array('file' => dirname(__FILE__) . '/../res/upload1.bin'))); $this->assertNotNull($asset); $this->assertEqual('test/cb/cbf9f9f453acaba556e00b48951815da5611f975/index.xml', $asset); $this->assertTrue(file_exists(self::$BUCKET . 'cb/cbf9f9f453acaba556e00b48951815da5611f975/vw_golf_smaller.jpg'), 'Original file was not written to file system.'); $this->assertTrue(file_exists(self::$BUCKET . 'cb/cbf9f9f453acaba556e00b48951815da5611f975/upload1.jpg'), 'detailpage rendition file was not written to file system.'); $this->assertFalse(file_exists(self::$BUCKET . 'cb/cbf9f9f453acaba556e00b48951815da5611f975/upload1.bin'), 'detailpage rendition file was written to file system with the wrong extension.'); $this->assertTrue(file_exists(binarypool_config::getRoot() . $asset), 'Asset file was not written to file system.'); }
/** * Tests that the correct rendition is saved. */ function testUploadRenditionVerify() { $this->testUploadRendition(); $this->get('/test/cb/cbf9f9f453acaba556e00b48951815da5611f975/index.xml'); $this->assertEqual(api_response::getInstance()->getCode(), 200); $localHash = sha1_file(dirname(__FILE__) . '/../res/vw_golf_blur.jpg'); $remoteFile = $this->getText('/registry/items/item[rendition="detailpage"]/location'); $remoteHash = sha1_file(binarypool_config::getRoot() . '/' . $remoteFile); $this->assertEqual($localHash, $remoteHash); }