1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\MediaBundle\Tests\Block; |
15
|
|
|
|
16
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
17
|
|
|
use Sonata\BlockBundle\Block\BlockContext; |
18
|
|
|
use Sonata\BlockBundle\Model\Block; |
19
|
|
|
use Sonata\BlockBundle\Test\BlockServiceTestCase; |
20
|
|
|
use Sonata\MediaBundle\Admin\BaseMediaAdmin; |
21
|
|
|
use Sonata\MediaBundle\Block\MediaBlockService; |
22
|
|
|
use Sonata\MediaBundle\Model\GalleryManagerInterface; |
23
|
|
|
use Sonata\MediaBundle\Model\MediaInterface; |
24
|
|
|
use Sonata\MediaBundle\Provider\Pool; |
25
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
26
|
|
|
|
27
|
|
|
class MediaBlockServiceTest extends BlockServiceTestCase |
28
|
|
|
{ |
29
|
|
|
protected $container; |
30
|
|
|
|
31
|
|
|
private $galleryManager; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var MediaBlockService |
35
|
|
|
*/ |
36
|
|
|
private $blockService; |
37
|
|
|
|
38
|
|
|
protected function setUp(): void |
39
|
|
|
{ |
40
|
|
|
parent::setUp(); |
41
|
|
|
|
42
|
|
|
$this->container = $this->prophesize(ContainerInterface::class); |
43
|
|
|
$this->galleryManager = $this->prophesize(GalleryManagerInterface::class); |
44
|
|
|
|
45
|
|
|
$this->blockService = new MediaBlockService( |
46
|
|
|
$this->twig, |
47
|
|
|
null, |
48
|
|
|
$this->container->reveal(), |
49
|
|
|
$this->galleryManager->reveal() |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testExecute(): void |
54
|
|
|
{ |
55
|
|
|
$block = $this->prophesize(Block::class); |
56
|
|
|
$media = $this->prophesize(MediaInterface::class); |
57
|
|
|
$blockContext = $this->prophesize(BlockContext::class); |
58
|
|
|
|
59
|
|
|
$this->configureGetFormatChoices($media, ['format1' => 'format1']); |
60
|
|
|
$blockContext->getBlock()->willReturn($block->reveal()); |
61
|
|
|
$blockContext->getSetting('format')->willReturn('format'); |
62
|
|
|
$blockContext->setSetting('format', 'format1')->shouldBeCalled(); |
63
|
|
|
$blockContext->getSettings()->willReturn([]); |
64
|
|
|
$blockContext->getTemplate()->willReturn('template'); |
65
|
|
|
$blockContext->getSetting('mediaId')->willReturn($media->reveal()); |
66
|
|
|
$block->getSetting('mediaId')->willReturn($media->reveal()); |
67
|
|
|
|
68
|
|
|
$this->twig |
|
|
|
|
69
|
|
|
->expects($this->once()) |
70
|
|
|
->method('render') |
71
|
|
|
->with('template', [ |
72
|
|
|
'media' => $media->reveal(), |
73
|
|
|
'block' => $block->reveal(), |
74
|
|
|
'settings' => [], |
75
|
|
|
]); |
76
|
|
|
|
77
|
|
|
$this->blockService->execute($blockContext->reveal()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testDefaultSettings(): void |
81
|
|
|
{ |
82
|
|
|
$blockContext = $this->getBlockContext($this->blockService); |
83
|
|
|
|
84
|
|
|
$this->assertSettings([ |
85
|
|
|
'attr' => [], |
86
|
|
|
'context' => false, |
87
|
|
|
'extra_cache_keys' => [], |
88
|
|
|
'format' => false, |
89
|
|
|
'media' => false, |
90
|
|
|
'mediaId' => null, |
91
|
|
|
'template' => '@SonataMedia/Block/block_media.html.twig', |
92
|
|
|
'title' => null, |
93
|
|
|
'translation_domain' => null, |
94
|
|
|
'icon' => null, |
95
|
|
|
'class' => null, |
96
|
|
|
'ttl' => 0, |
97
|
|
|
'use_cache' => true, |
98
|
|
|
], $blockContext); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function configureGetFormatChoices(ObjectProphecy $media, array $choices): void |
102
|
|
|
{ |
103
|
|
|
$mediaAdmin = $this->prophesize(BaseMediaAdmin::class); |
104
|
|
|
$pool = $this->prophesize(Pool::class); |
105
|
|
|
|
106
|
|
|
$this->container->get('sonata.media.admin.media')->willReturn($mediaAdmin->reveal()); |
107
|
|
|
$mediaAdmin->getPool()->willReturn($pool->reveal()); |
108
|
|
|
$media->getContext()->willReturn('context'); |
109
|
|
|
$pool->getFormatNamesByContext('context')->willReturn($choices); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.