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\MatomoBundle\Tests\Block\Service; |
13
|
|
|
|
14
|
|
|
use Core23\MatomoBundle\Block\Service\MatomoTrackerBlockService; |
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 MatomoTrackerBlockServiceTest extends AbstractBlockServiceTestCase |
22
|
|
|
{ |
23
|
|
|
public function testExecute(): void |
24
|
|
|
{ |
25
|
|
|
$block = new Block(); |
26
|
|
|
|
27
|
|
|
$blockContext = new BlockContext($block, [ |
28
|
|
|
'host' => null, |
29
|
|
|
'site' => null, |
30
|
|
|
'domaintitle' => false, |
31
|
|
|
'donottrack' => false, |
32
|
|
|
'nocookies' => false, |
33
|
|
|
'template' => '@Core23Matomo/Block/block_matomo_tracker.html.twig', |
34
|
|
|
]); |
35
|
|
|
|
36
|
|
|
$blockService = new MatomoTrackerBlockService('block.service', $this->templating); |
37
|
|
|
$blockService->execute($blockContext); |
38
|
|
|
|
39
|
|
|
$this->assertSame('@Core23Matomo/Block/block_matomo_tracker.html.twig', $this->templating->view); |
40
|
|
|
|
41
|
|
|
$this->assertSame($blockContext, $this->templating->parameters['context']); |
42
|
|
|
$this->assertInternalType('array', $this->templating->parameters['settings']); |
|
|
|
|
43
|
|
|
$this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testDefaultSettings(): void |
47
|
|
|
{ |
48
|
|
|
$blockService = new MatomoTrackerBlockService('block.service', $this->templating); |
49
|
|
|
$blockContext = $this->getBlockContext($blockService); |
50
|
|
|
|
51
|
|
|
$this->assertSettings([ |
52
|
|
|
'host' => null, |
53
|
|
|
'site' => null, |
54
|
|
|
'domaintitle' => false, |
55
|
|
|
'donottrack' => false, |
56
|
|
|
'nocookies' => false, |
57
|
|
|
'template' => '@Core23Matomo/Block/block_matomo_tracker.html.twig', |
58
|
|
|
], $blockContext); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testGetBlockMetadata(): void |
62
|
|
|
{ |
63
|
|
|
$blockService = new MatomoTrackerBlockService('block.service', $this->templating); |
64
|
|
|
|
65
|
|
|
$metadata = $blockService->getBlockMetadata('description'); |
66
|
|
|
|
67
|
|
|
$this->assertSame('block.service', $metadata->getTitle()); |
68
|
|
|
$this->assertSame('description', $metadata->getDescription()); |
69
|
|
|
$this->assertNotNull($metadata->getImage()); |
70
|
|
|
$this->assertStringStartsWith('data:image/png;base64,', $metadata->getImage() ?? ''); |
71
|
|
|
$this->assertSame('Core23MatomoBundle', $metadata->getDomain()); |
72
|
|
|
$this->assertSame([ |
73
|
|
|
'class' => 'fa fa-code', |
74
|
|
|
], $metadata->getOptions()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testBuildEditForm(): void |
78
|
|
|
{ |
79
|
|
|
$blockService = new MatomoTrackerBlockService('block.service', $this->templating); |
80
|
|
|
|
81
|
|
|
$block = new Block(); |
82
|
|
|
|
83
|
|
|
$formMapper = $this->createMock(FormMapper::class); |
84
|
|
|
$formMapper->expects($this->once())->method('add'); |
85
|
|
|
|
86
|
|
|
$blockService->buildEditForm($formMapper, $block); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.