|
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
|
|
|
|