ImboUnitTest\Http\Response\Formatter\XMLTest::testCanFormatAnImagesModel PHP Method

testCanFormatAnImagesModel() public method

    public function testCanFormatAnImagesModel()
    {
        $formattedDate = 'Wed, 30 Jan 2013 10:53:11 GMT';
        $date = new DateTime();
        $addedDate = $date;
        $updatedDate = $date;
        $user = 'christer';
        $imageIdentifier = 'identifier';
        $checksum = 'checksum';
        $extension = 'png';
        $mimeType = 'image/png';
        $filesize = 123123;
        $width = 800;
        $height = 600;
        $metadata = ['some key' => 'some value', 'some other key' => 'some other value'];
        $image = $this->getMock('Imbo\\Model\\Image');
        $image->expects($this->once())->method('getUser')->will($this->returnValue($user));
        $image->expects($this->once())->method('getImageIdentifier')->will($this->returnValue($imageIdentifier));
        $image->expects($this->once())->method('getChecksum')->will($this->returnValue($checksum));
        $image->expects($this->once())->method('getExtension')->will($this->returnValue($extension));
        $image->expects($this->once())->method('getMimeType')->will($this->returnValue($mimeType));
        $image->expects($this->once())->method('getAddedDate')->will($this->returnValue($addedDate));
        $image->expects($this->once())->method('getUpdatedDate')->will($this->returnValue($updatedDate));
        $image->expects($this->once())->method('getFilesize')->will($this->returnValue($filesize));
        $image->expects($this->once())->method('getWidth')->will($this->returnValue($width));
        $image->expects($this->once())->method('getHeight')->will($this->returnValue($height));
        $image->expects($this->once())->method('getMetadata')->will($this->returnValue($metadata));
        $images = [$image];
        $model = $this->getMock('Imbo\\Model\\Images');
        $model->expects($this->once())->method('getImages')->will($this->returnValue($images));
        $model->expects($this->once())->method('getHits')->will($this->returnValue(100));
        $model->expects($this->once())->method('getPage')->will($this->returnValue(2));
        $model->expects($this->once())->method('getLimit')->will($this->returnValue(20));
        $model->expects($this->once())->method('getCount')->will($this->returnValue(1));
        $this->dateFormatter->expects($this->any())->method('formatDate')->with($this->isInstanceOf('DateTime'))->will($this->returnValue($formattedDate));
        $xml = $this->formatter->format($model);
        // Check the search data
        foreach (['hits' => 100, 'page' => 2, 'limit' => 20, 'count' => 1] as $tag => $value) {
            $this->assertXPathMatches('/imbo/search/' . $tag . '[.="' . $value . '"]', $xml, $tag . ' is not correct');
        }
        // Check image
        foreach (['user' => $user, 'imageIdentifier' => $imageIdentifier, 'checksum' => $checksum, 'mime' => $mimeType, 'extension' => $extension, 'added' => $formattedDate, 'updated' => $formattedDate, 'size' => (string) $filesize, 'width' => (string) $width, 'height' => (string) $height] as $tag => $value) {
            $this->assertXPathMatches('/imbo/images/image/' . $tag . '[.="' . $value . '"]', $xml);
        }
        // Check metadata
        foreach ($metadata as $key => $value) {
            $this->assertXPathMatches('//images/image/metadata/tag[@key="' . $key . '" and .="' . $value . '"]', $xml, 'element "tag" with value "' . $value . '" and attr key="' . $key . '" not found');
        }
    }