/** * Create an asset XML for a file with 1 rendition. */ function testAssetWithRendition90x90() { $basepath = self::$BUCKET . 'somehashhere/'; mkdir($basepath, 0755, true); // Copy original copy($this->testfile, $basepath . 'vw_golf.jpg'); // Resize image $resizedFile = $basepath . 'resultlist'; $out = binarypool_render_image::render($basepath . 'vw_golf.jpg', $resizedFile, null, array('width' => 90, 'height' => 90)); $this->assertEqual($out, $resizedFile . '.jpg', 'Rendering did not determine the correct file extension for the thumbnail. - %s'); // Create asset file $asset = new binarypool_asset($this->getDummyStorage()); $asset->setBasePath('test/somehashhere'); $asset->setOriginal($basepath . 'vw_golf.jpg'); $asset->setRendition('resultlist', $out); $asset->setExpiry(time() + 1000); $this->assertEqual('096dfa489bc3f21df56eded2143843f135ae967e', $asset->getHash()); $this->assertWithinMargin(time(), $asset->getCreated(), 10); $this->assertWithinMargin(time() + 1000, $asset->getExpiry(), 10); $xml = $asset->getXML(); file_put_contents($basepath . 'index.xml', $xml); // Load XML $dom = DOMDocument::loadXML($xml); $xp = new DOMXPath($dom); $res = $xp->query('/registry/items/item'); $this->assertEqual($res->length, 2); // Test original file $this->assertXPath($xp, '/registry/@version', '3.0'); $this->assertXPath($xp, '/registry/items/item[1]/@type', 'IMAGE'); $this->assertXPath($xp, '/registry/items/item[1]/@isRendition', 'false'); $this->assertXPath($xp, '/registry/items/item[1]/webobject/objectWidth', '557'); $this->assertXPath($xp, '/registry/items/item[1]/webobject/objectHeight', '344'); $this->assertXPath($xp, '/registry/items/item[1]/imageinfo/@isLandscape', 'true'); $this->assertXPath($xp, '/registry/items/item[1]/imageinfo/width', '557'); $this->assertXPath($xp, '/registry/items/item[1]/imageinfo/height', '344'); $this->assertXPath($xp, '/registry/items/item[1]/location', 'test/somehashhere/vw_golf.jpg'); $this->assertXPath($xp, '/registry/items/item[1]/mimetype', 'image/jpeg'); $this->assertXPath($xp, '/registry/items/item[1]/size', '106237'); // Test rendition $this->assertXPath($xp, '/registry/items/item[2]/@type', 'IMAGE'); $this->assertXPath($xp, '/registry/items/item[2]/@isRendition', 'true'); $this->assertXPath($xp, '/registry/items/item[2]/webobject/objectWidth', '90'); $this->assertXPath($xp, '/registry/items/item[2]/webobject/objectHeight', '56'); $this->assertXPath($xp, '/registry/items/item[2]/imageinfo/@isLandscape', 'true'); $this->assertXPath($xp, '/registry/items/item[2]/imageinfo/width', '90'); $this->assertXPath($xp, '/registry/items/item[2]/imageinfo/height', '56'); $this->assertXPath($xp, '/registry/items/item[2]/rendition', 'resultlist'); $this->assertXPath($xp, '/registry/items/item[2]/location', 'test/somehashhere/resultlist.jpg'); $this->assertXPath($xp, '/registry/items/item[2]/mimetype', 'image/jpeg'); $this->assertXPath($xp, '/registry/items/item[2]/size', filesize($out)); // Test attributes $created = intval($this->getXPathValue($xp, '/registry/created')); $this->assertWithinMargin(time(), $created, 10); $expiry = intval($this->getXPathValue($xp, '/registry/expiry')); $this->assertWithinMargin(time() + 1000, $expiry, 10); }
/** * Create a test asset file. * * @param $callbacks: Array of callbacks to register. * @param $age: Age of item in days. */ function createAsset($callbacks = array(), $age = 30) { // Create asset file $asset = new binarypool_asset($this->getDummyStorage()); $asset->setBasePath('test/somehashhere'); $asset->setOriginal($this->testfile); $asset->setExpiry(time() - $age * 24 * 60 * 60); foreach ($callbacks as $callback) { $asset->addCallback($callback); } $xml = $asset->getXML(); mkdir(self::$BUCKET . 'somehashhere', 0755, true); copy($this->testfile, self::$BUCKET . 'somehashhere/vw_golf.jpg'); file_put_contents(self::$BUCKET . 'somehashhere/index.xml', $xml); return 'test/somehashhere/index.xml'; }
private function createAssetFile($assetFile, $assetObj, $dir, $originalFile, $renditions, $type) { $asset = null; if ($originalFile === null || $renditions === null) { // Nothing to save, just writing an existing file return $assetFile; } if (!is_null($assetObj)) { $asset = $assetObj; } else { if ($this->storage->isFile($assetFile)) { // Load existing asset file $asset = $this->getAssetObject($assetFile); } else { $asset = new binarypool_asset($this); } } $storeAbsolute = $this->storage->isAbsoluteStorage(); $asset->setBasePath($dir, $storeAbsolute); $asset->setOriginal($this->storage->absolutize($originalFile)); foreach ($renditions as $rendition => $filename) { $asset->setRendition($rendition, $this->absolutize($filename)); } // Expiry date if (!isset($this->bucketConfig['ttl'])) { throw new BinaryPoolException(116, 500, 'Bucket does not have a defined TTL: ' . $this->bucketName); } $asset->setExpiry(time() + intval($this->bucketConfig['ttl']) * 24 * 60 * 60); $asset->setType($type); // Done $this->saveAsset($asset, $assetFile); return $assetFile; }
/** * 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.'); }