1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata Project package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[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 Sonata\DoctrineORMAdminBundle\Tests\Block; |
13
|
|
|
|
14
|
|
|
use SimpleThings\EntityAudit\AuditReader as SimpleThingsAuditReader; |
15
|
|
|
use Sonata\BlockBundle\Block\BlockContext; |
16
|
|
|
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase; |
17
|
|
|
use Sonata\DoctrineORMAdminBundle\Block\AuditBlockService; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Marko Kunic <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class AuditBlockServiceTest extends AbstractBlockServiceTestCase |
23
|
|
|
{ |
24
|
|
|
private $simpleThingsAuditReader; |
25
|
|
|
private $blockService; |
26
|
|
|
|
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
parent::setUp(); |
30
|
|
|
$this->simpleThingsAuditReader = $this->prophesize(SimpleThingsAuditReader::class); |
31
|
|
|
|
32
|
|
|
$this->blockService = new AuditBlockService( |
33
|
|
|
'block.service', |
34
|
|
|
$this->templating, |
35
|
|
|
$this->simpleThingsAuditReader->reveal() |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @group legacy |
41
|
|
|
*/ |
42
|
|
|
public function testExecute() |
43
|
|
|
{ |
44
|
|
|
$blockContext = $this->prophesize(BlockContext::class); |
45
|
|
|
|
46
|
|
|
$blockContext->getSetting('limit')->willReturn($limit = 10)->shouldBeCalledTimes(1); |
47
|
|
|
$blockContext->getBlock()->shouldBeCalledTimes(1); |
48
|
|
|
|
49
|
|
|
$this->simpleThingsAuditReader->findRevisionHistory($limit, 0) |
50
|
|
|
->willReturn([]) |
51
|
|
|
->shouldBeCalledTimes(1); |
52
|
|
|
|
53
|
|
|
$blockContext->getTemplate()->willReturn('template')->shouldBeCalledTimes(1); |
54
|
|
|
$blockContext->getSettings()->willReturn([])->shouldBeCalledTimes(1); |
55
|
|
|
|
56
|
|
|
$this->blockService->execute($blockContext->reveal()); |
57
|
|
|
|
58
|
|
|
$this->assertSame('template', $this->templating->view); |
59
|
|
|
$this->assertInternalType('array', $this->templating->parameters['settings']); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testDefaultSettings() |
63
|
|
|
{ |
64
|
|
|
$blockContext = $this->getBlockContext($this->blockService); |
65
|
|
|
|
66
|
|
|
$this->assertSettings([ |
67
|
|
|
'attr' => [], |
68
|
|
|
'extra_cache_keys' => [], |
69
|
|
|
'limit' => 10, |
70
|
|
|
'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig', |
71
|
|
|
'ttl' => 0, |
72
|
|
|
'use_cache' => true, |
73
|
|
|
], $blockContext); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|