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\BlockBundle\Block\BlockContext; |
16
|
|
|
use Sonata\BlockBundle\Form\Mapper\FormMapper; |
17
|
|
|
use Sonata\BlockBundle\Model\Block; |
18
|
|
|
use Sonata\BlockBundle\Model\BlockInterface; |
19
|
|
|
use Sonata\BlockBundle\Test\BlockServiceTestCase; |
20
|
|
|
|
21
|
|
|
final class MatomoTrackerBlockServiceTest extends BlockServiceTestCase |
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($this->templating); |
37
|
|
|
$blockService->execute($blockContext); |
38
|
|
|
|
39
|
|
|
static::assertSame('@Core23Matomo/Block/block_matomo_tracker.html.twig', $this->templating->view); |
40
|
|
|
|
41
|
|
|
static::assertSame($blockContext, $this->templating->parameters['context']); |
42
|
|
|
static::assertIsArray($this->templating->parameters['settings']); |
43
|
|
|
static::assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testDefaultSettings(): void |
47
|
|
|
{ |
48
|
|
|
$blockService = new MatomoTrackerBlockService($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 testGetMetadata(): void |
62
|
|
|
{ |
63
|
|
|
$blockService = new MatomoTrackerBlockService($this->templating); |
64
|
|
|
|
65
|
|
|
$metadata = $blockService->getMetadata(); |
66
|
|
|
|
67
|
|
|
static::assertSame('core23_matomo.block.tracker', $metadata->getTitle()); |
68
|
|
|
static::assertNull($metadata->getImage()); |
69
|
|
|
static::assertSame('Core23MatomoBundle', $metadata->getDomain()); |
70
|
|
|
static::assertSame([ |
71
|
|
|
'class' => 'fa fa-code', |
72
|
|
|
], $metadata->getOptions()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testConfigureEditForm(): void |
76
|
|
|
{ |
77
|
|
|
$blockService = new MatomoTrackerBlockService($this->templating); |
78
|
|
|
|
79
|
|
|
$block = new Block(); |
80
|
|
|
|
81
|
|
|
$formMapper = $this->createMock(FormMapper::class); |
82
|
|
|
$formMapper->expects(static::once())->method('add'); |
83
|
|
|
|
84
|
|
|
$blockService->configureEditForm($formMapper, $block); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: