ImboUnitTest\Http\Response\Formatter\JSONTest::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));
        $json = $this->formatter->format($model);
        $data = json_decode($json, true);
        $this->assertSame(['hits' => 100, 'page' => 2, 'limit' => 20, 'count' => 1], $data['search']);
        $this->assertCount(1, $data['images']);
        $image = $data['images'][0];
        $this->assertSame($formattedDate, $image['added']);
        $this->assertSame($formattedDate, $image['updated']);
        $this->assertSame($user, $image['user']);
        $this->assertSame($filesize, $image['size']);
        $this->assertSame($width, $image['width']);
        $this->assertSame($height, $image['height']);
        $this->assertSame($imageIdentifier, $image['imageIdentifier']);
        $this->assertSame($checksum, $image['checksum']);
        $this->assertSame($extension, $image['extension']);
        $this->assertSame($mimeType, $image['mime']);
        $this->assertSame($metadata, $image['metadata']);
    }