/** * 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; }
function testPDFAssetWithoutRenditions() { // Create asset file $asset = new binarypool_asset($this->getDummyStorage()); $asset->setBasePath('test/somehashhere'); $asset->setOriginal(realpath(dirname(__FILE__) . '/../res/emil_frey_logo_2.pdf')); $xml = $asset->getXML(); // Load XML $dom = DOMDocument::loadXML($xml); $xp = new DOMXPath($dom); // Test $this->assertXPath($xp, '/registry/@version', '3.0'); $this->assertXPath($xp, '/registry/items/item/@type', 'IMAGE'); $this->assertXPath($xp, '/registry/items/item/@isRendition', 'false'); $this->assertXPath($xp, '/registry/items/item/webobject/@unit', 'mm'); $this->assertXPath($xp, '/registry/items/item/webobject/objectWidth', '203'); $this->assertXPath($xp, '/registry/items/item/webobject/objectHeight', '40'); $this->assertXPath($xp, '/registry/items/item/imageinfo/@isLandscape', 'true'); $this->assertXPath($xp, '/registry/items/item/imageinfo/@unit', 'mm'); $this->assertXPath($xp, '/registry/items/item/imageinfo/width', '203'); $this->assertXPath($xp, '/registry/items/item/imageinfo/height', '40'); $this->assertXPath($xp, '/registry/items/item/location', 'test/somehashhere/emil_frey_logo_2.pdf'); $this->assertXPath($xp, '/registry/items/item/mimetype', 'application/pdf'); $this->assertXPath($xp, '/registry/items/item/size', '28216'); }