/** * @covers Imbo\Model\Image::setBlob * @covers Imbo\Model\Image::getBlob * @covers Imbo\Model\Image::getFilesize * @covers Imbo\Model\Image::setFilesize * @covers Imbo\Model\Image::getChecksum * @covers Imbo\Model\Image::setChecksum */ public function testCanSetAndGetBlob() { $blob = 'some string'; $hash = md5($blob); $this->assertSame($this->image, $this->image->setBlob($blob)); $this->assertSame($blob, $this->image->getBlob()); $this->assertSame(11, $this->image->getFilesize()); $this->assertSame($hash, $this->image->getChecksum()); $blob = 'some other string'; $hash = md5($blob); $this->assertSame($this->image, $this->image->setBlob($blob)); $this->assertSame($blob, $this->image->getBlob()); $this->assertSame(17, $this->image->getFilesize()); $this->assertSame($hash, $this->image->getChecksum()); }
/** * Insert some images to test the query functionality * * All images added is owned by "publickey", unless $alternatePublicKey is set to true * * @param boolean $alternatePublicKey Whether to alternate between 'publickey' and * 'publickey2' when inserting images * @return array Returns an array with two elements where the first is the timestamp of when * the first image was added, and the second is the timestamp of when the last * image was added */ private function insertImages($alternatePublicKey = false) { $now = time(); $start = $now; $images = array(); foreach (array('image.jpg', 'image.png', 'image1.png', 'image2.png', 'image3.png', 'image4.png') as $i => $fileName) { $path = FIXTURES_DIR . '/' . $fileName; $info = getimagesize($path); $publicKey = 'publickey'; if ($alternatePublicKey && $i % 2 === 0) { $publickey2 = 'publickey2'; } $image = new Image(); $image->setMimeType($info['mime'])->setExtension(substr($fileName, strrpos($fileName, '.') + 1))->setWidth($info[0])->setHeight($info[1])->setBlob(file_get_contents($path))->setAddedDate(new DateTime('@' . $now++, new DateTimeZone('UTC')))->setOriginalChecksum(md5_file($path)); $imageIdentifier = md5($image->getBlob()); // Add the image $this->adapter->insertImage($publicKey, $imageIdentifier, $image); // Insert some metadata $this->adapter->updateMetadata($publicKey, $imageIdentifier, array('key' . $i => 'value' . $i)); } // Remove the last increment to get the timestamp for when the last image was added $end = $now - 1; return array($start, $end); }
/** * {@inheritdoc} */ public function generate(Image $image) { return md5($image->getBlob()); }