Completed
Push — master ( 14bd4d...eb12ea )
by Thomas
22:31
created

GalleryListBlockServiceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 5
dl 0
loc 70
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
B testExecute() 0 27 1
A testDefaultSettings() 0 15 1
1
<?php
2
3
namespace Sonata\MediaBundle\Tests\Block\Service;
4
5
use Sonata\BlockBundle\Block\BlockContext;
6
use Sonata\BlockBundle\Model\Block;
7
use Sonata\BlockBundle\Tests\Block\AbstractBlockServiceTest;
8
use Sonata\BlockBundle\Tests\Block\Service\FakeTemplating;
9
use Sonata\MediaBundle\Block\GalleryListBlockService;
10
use Sonata\MediaBundle\Model\GalleryManagerInterface;
11
use Sonata\MediaBundle\Provider\Pool;
12
13
class GalleryListBlockServiceTest extends AbstractBlockServiceTest
14
{
15
    /**
16
     * @var \PHPUnit_Framework_MockObject_MockObject|GalleryManagerInterface
17
     */
18
    protected $galleryManager;
19
20
    /**
21
     * @var \PHPUnit_Framework_MockObject_MockObject|Pool
22
     */
23
    protected $pool;
24
25
    /**
26
     * @var FakeTemplating
27
     */
28
    protected $templating;
29
30
    protected function setUp()
31
    {
32
        parent::setUp();
33
34
        $this->galleryManager = $this->getMock('Sonata\MediaBundle\Model\GalleryManagerInterface');
35
        $this->pool           = $this->getMockBuilder('Sonata\MediaBundle\Provider\Pool')->disableOriginalConstructor()->getMock();
36
        $this->templating     = new FakeTemplating();
37
    }
38
39
    public function testExecute()
40
    {
41
        $pager = $this->getMock('Sonata\DatagridBundle\Pager\PagerInterface');
42
        $this->galleryManager->expects($this->once())->method('getPager')->will($this->returnValue($pager));
43
44
        $block = new Block();
45
46
        $blockContext = new BlockContext($block, array(
47
            'number'   => 15,
48
            'mode'     => 'public',
49
            'order'    => 'createdAt',
50
            'sort'     => 'desc',
51
            'context'  => false,
52
            'title'    => 'Gallery List',
53
            'template' => 'SonataMediaBundle:Block:block_gallery_list.html.twig',
54
        ));
55
56
        $blockService = new GalleryListBlockService('block.service', $this->templating, $this->galleryManager, $this->pool);
57
        $blockService->execute($blockContext);
58
59
        $this->assertSame('SonataMediaBundle:Block:block_gallery_list.html.twig', $this->templating->view);
60
61
        $this->assertSame($blockContext, $this->templating->parameters['context']);
62
        $this->assertInternalType('array', $this->templating->parameters['settings']);
63
        $this->assertInstanceOf('Sonata\BlockBundle\Model\BlockInterface', $this->templating->parameters['block']);
64
        $this->assertSame($pager, $this->templating->parameters['pager']);
65
    }
66
67
    public function testDefaultSettings()
68
    {
69
        $blockService = new GalleryListBlockService('block.service', $this->templating, $this->galleryManager, $this->pool);
70
        $blockContext = $this->getBlockContext($blockService);
71
72
        $this->assertSettings(array(
73
            'number'   => 15,
74
            'mode'     => 'public',
75
            'order'    => 'createdAt',
76
            'sort'     => 'desc',
77
            'context'  => false,
78
            'title'    => 'Gallery List',
79
            'template' => 'SonataMediaBundle:Block:block_gallery_list.html.twig',
80
        ), $blockContext);
81
    }
82
}
83