1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[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 Core23\ShariffBundle\Tests\Block\Service; |
13
|
|
|
|
14
|
|
|
use Core23\ShariffBundle\Block\Service\ShariffShareBlockService; |
15
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
16
|
|
|
use Sonata\BlockBundle\Block\BlockContext; |
17
|
|
|
use Sonata\BlockBundle\Model\Block; |
18
|
|
|
use Sonata\BlockBundle\Model\BlockInterface; |
19
|
|
|
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase; |
20
|
|
|
|
21
|
|
|
final class ShariffShareBlockServiceTest extends AbstractBlockServiceTestCase |
22
|
|
|
{ |
23
|
|
|
public function testDefaultSettings(): void |
24
|
|
|
{ |
25
|
|
|
$blockService = new ShariffShareBlockService('block.service', $this->templating); |
26
|
|
|
$blockContext = $this->getBlockContext($blockService); |
27
|
|
|
|
28
|
|
|
$this->assertSettings([ |
29
|
|
|
'url' => null, |
30
|
|
|
'class' => null, |
31
|
|
|
'services' => ['twitter', 'facebook', 'googleplus'], |
32
|
|
|
'theme' => 'standard', |
33
|
|
|
'orientation' => 'horizontal', |
34
|
|
|
'flattrUser' => null, |
35
|
|
|
'flattrCategory' => null, |
36
|
|
|
'template' => '@Core23Shariff/Block/block_shariff.html.twig', |
37
|
|
|
], $blockContext); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testExecute(): void |
41
|
|
|
{ |
42
|
|
|
$block = new Block(); |
43
|
|
|
|
44
|
|
|
$blockContext = new BlockContext($block, [ |
45
|
|
|
'url' => null, |
46
|
|
|
'class' => null, |
47
|
|
|
'services' => ['twitter', 'facebook', 'googleplus'], |
48
|
|
|
'theme' => 'standard', |
49
|
|
|
'orientation' => 'horizontal', |
50
|
|
|
'flattrUser' => null, |
51
|
|
|
'flattrCategory' => null, |
52
|
|
|
'template' => '@Core23Shariff/Block/block_shariff.html.twig', |
53
|
|
|
]); |
54
|
|
|
|
55
|
|
|
$blockService = new ShariffShareBlockService('block.service', $this->templating); |
56
|
|
|
$blockService->execute($blockContext); |
57
|
|
|
|
58
|
|
|
$this->assertSame('@Core23Shariff/Block/block_shariff.html.twig', $this->templating->view); |
59
|
|
|
|
60
|
|
|
$this->assertSame($blockContext, $this->templating->parameters['context']); |
61
|
|
|
$this->assertInternalType('array', $this->templating->parameters['settings']); |
|
|
|
|
62
|
|
|
$this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testGetBlockMetadata(): void |
66
|
|
|
{ |
67
|
|
|
$blockService = new ShariffShareBlockService('block.service', $this->templating); |
68
|
|
|
|
69
|
|
|
$metadata = $blockService->getBlockMetadata('description'); |
70
|
|
|
|
71
|
|
|
$this->assertSame('block.service', $metadata->getTitle()); |
72
|
|
|
$this->assertSame('description', $metadata->getDescription()); |
73
|
|
|
$this->assertNotNull($metadata->getImage()); |
74
|
|
|
$this->assertStringStartsWith('data:image/png;base64,', $metadata->getImage() ?? ''); |
75
|
|
|
$this->assertSame('Core23ShariffBundle', $metadata->getDomain()); |
76
|
|
|
$this->assertSame([ |
77
|
|
|
'class' => 'fa fa-share-square-o', |
78
|
|
|
], $metadata->getOptions()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testBuildEditForm(): void |
82
|
|
|
{ |
83
|
|
|
$blockService = new ShariffShareBlockService('block.service', $this->templating); |
84
|
|
|
|
85
|
|
|
$block = new Block(); |
86
|
|
|
|
87
|
|
|
$formMapper = $this->createMock(FormMapper::class); |
88
|
|
|
$formMapper->expects($this->once())->method('add'); |
89
|
|
|
|
90
|
|
|
$blockService->buildEditForm($formMapper, $block); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.