-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathAbstractCollectionsBlockServiceTest.php
More file actions
128 lines (107 loc) · 4.71 KB
/
AbstractCollectionsBlockServiceTest.php
File metadata and controls
128 lines (107 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\ClassificationBundle\Tests\Block\Service;
use PHPUnit\Framework\MockObject\MockObject;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Test\BlockServiceTestCase;
use Sonata\ClassificationBundle\Admin\CollectionAdmin;
use Sonata\ClassificationBundle\Block\Service\AbstractCollectionsBlockService;
use Sonata\ClassificationBundle\Model\CollectionInterface;
use Sonata\ClassificationBundle\Model\CollectionManagerInterface;
use Sonata\ClassificationBundle\Model\ContextManagerInterface;
use Twig\Environment;
/**
* @author Christian Gripp <mail@core23.de>
*/
final class AbstractCollectionsBlockServiceTest extends BlockServiceTestCase
{
/**
* @var ContextManagerInterface&MockObject
*/
private ContextManagerInterface $contextManager;
/**
* @var CollectionManagerInterface&MockObject
*/
private CollectionManagerInterface $collectionManager;
private CollectionAdmin $collectionAdmin;
protected function setUp(): void
{
parent::setUp();
$this->twig = $this->createMock(Environment::class);
$this->contextManager = $this->createMock(ContextManagerInterface::class);
$this->collectionManager = $this->createMock(CollectionManagerInterface::class);
$this->collectionAdmin = new CollectionAdmin($this->contextManager);
}
public function testDefaultSettings(): void
{
$blockService = new class($this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin) extends AbstractCollectionsBlockService {};
$blockContext = $this->getBlockContext($blockService);
$this->assertSettings([
'title' => null,
'translation_domain' => null,
'icon' => 'fa fa-inpanel',
'class' => null,
'collection' => false,
'collectionId' => null,
'context' => null,
'template' => '@SonataClassification/Block/base_block_collections.html.twig',
], $blockContext);
}
public function testLoad(): void
{
$collection = $this->createMock(CollectionInterface::class);
$collection->expects(static::any())->method('getId')->willReturn(23);
$this->collectionManager->expects(static::any())
->method('find')
->with(static::equalTo('23'))
->willReturn($collection);
$block = $this->createMock(BlockInterface::class);
$block->expects(static::any())
->method('getSetting')
->with(static::equalTo('collectionId'))
->willReturn(23);
$block->expects(static::once())
->method('setSetting')
->with(static::equalTo('collectionId'), static::equalTo($collection));
$blockService = new class($this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin) extends AbstractCollectionsBlockService {};
$blockService->load($block);
}
public function testPrePersist(): void
{
$collection = $this->createMock(CollectionInterface::class);
$collection->expects(static::any())->method('getId')->willReturn(23);
$block = $this->createMock(BlockInterface::class);
$block->expects(static::any())
->method('getSetting')
->with(static::equalTo('collectionId'))
->willReturn($collection);
$block->expects(static::once())
->method('setSetting')
->with(static::equalTo('collectionId'), static::equalTo(23));
$blockService = new class($this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin) extends AbstractCollectionsBlockService {};
$blockService->prePersist($block);
}
public function testPreUpdate(): void
{
$collection = $this->createMock(CollectionInterface::class);
$collection->expects(static::any())->method('getId')->willReturn(23);
$block = $this->createMock(BlockInterface::class);
$block->expects(static::any())
->method('getSetting')
->with(static::equalTo('collectionId'))
->willReturn($collection);
$block->expects(static::once())
->method('setSetting')
->with(static::equalTo('collectionId'), static::equalTo(23));
$blockService = new class($this->twig, $this->contextManager, $this->collectionManager, $this->collectionAdmin) extends AbstractCollectionsBlockService {};
$blockService->preUpdate($block);
}
}