Completed
Pull Request — master (#693)
by
unknown
03:28
created

FormatThumbnailTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 33
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\MediaBundle\Tests\Thumbnail;
13
14
use Gaufrette\Adapter\InMemory;
15
use Gaufrette\File;
16
use Gaufrette\Filesystem;
17
use Sonata\MediaBundle\Thumbnail\FormatThumbnail;
18
19
class FormatThumbnailTest extends \PHPUnit_Framework_TestCase
20
{
21
    public function testGenerate()
22
    {
23
        $thumbnail = new FormatThumbnail('foo');
24
25
        $filesystem = new Filesystem(new InMemory(array('myfile' => 'content')));
26
        $referenceFile = new File('myfile', $filesystem);
27
28
        $formats = array(
29
           'admin'                 => array('height' => 50, 'width' => 50, 'quality' => 100),
30
           'mycontext_medium'      => array('height' => 500, 'width' => 500, 'quality' => 100),
31
           'mycontext_large'       => array('height' => 500, 'width' => 500, 'quality' => 100, 'resizer' => 'some.other.resizer'),
32
           'anothercontext_larger' => array('height' => 500, 'width' => 500, 'quality' => 100),
33
        );
34
35
        $resizer = $this->getMock('Sonata\MediaBundle\Resizer\ResizerInterface');
36
        $resizer->expects($this->exactly(2))->method('resize')->will($this->returnValue(true));
37
38
        $customResizer = $this->getMock('Sonata\MediaBundle\Resizer\ResizerInterface');
39
        $customResizer->expects($this->exactly(1))->method('resize')->will($this->returnValue(true));
40
41
        $provider = $this->getMock('Sonata\MediaBundle\Provider\MediaProviderInterface');
42
        $provider->expects($this->once())->method('requireThumbnails')->will($this->returnValue(true));
43
        $provider->expects($this->once())->method('getReferenceFile')->will($this->returnValue($referenceFile));
44
        $provider->expects($this->once())->method('getFormats')->will($this->returnValue($formats));
45
        $provider->expects($this->exactly(2))->method('getResizer')->will($this->returnValue($resizer));
46
        $provider->expects($this->exactly(3))->method('generatePrivateUrl')->will($this->returnValue('/my/private/path'));
47
        $provider->expects($this->exactly(3))->method('getFilesystem')->will($this->returnValue($filesystem));
48
49
        $media = $this->getMock('Sonata\MediaBundle\Model\MediaInterface');
50
        $media->expects($this->exactly(8))->method('getContext')->will($this->returnValue('mycontext'));
51
        $media->expects($this->exactly(3))->method('getExtension')->will($this->returnValue('png'));
52
53
        $thumbnail->addResizer('some.other.resizer', $customResizer);
54
55
        $thumbnail->generate($provider, $media);
56
    }
57
}
58