/** * 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); }
/** * Creates a rendition of a PDF file. */ function testRenderPDF() { $targetPath = self::$BUCKET . 'render/'; $sourceFile = dirname(__FILE__) . '/../res/emil_frey_logo.pdf'; $resizedFile = $targetPath . 'test_pdf'; mkdir($targetPath, 0755, true); $out = binarypool_render_image::render($sourceFile, $resizedFile, null, array('width' => 300, 'height' => 300)); $this->assertEqual($out, $resizedFile . '.png', 'Rendering did not determine the correct file extension for the thumbnail. - %s'); $this->assertTrue(file_exists($out), "Resized file was not created"); list($width, $height) = getimagesize($out); $this->assertEqual(92, $width); $this->assertEqual(21, $height); }