|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\DoctrineORMAdminBundle\Tests\Block; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
17
|
|
|
use SimpleThings\EntityAudit\AuditReader as SimpleThingsAuditReader; |
|
18
|
|
|
use SimpleThings\EntityAudit\Revision; |
|
19
|
|
|
use Sonata\BlockBundle\Block\BlockContext; |
|
20
|
|
|
use Sonata\BlockBundle\Model\Block; |
|
21
|
|
|
use Sonata\BlockBundle\Test\BlockServiceTestCase; |
|
22
|
|
|
use Sonata\DoctrineORMAdminBundle\Block\AuditBlockService; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Marko Kunic <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class AuditBlockServiceTest extends BlockServiceTestCase |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var SimpleThingsAuditReader&MockObject |
|
31
|
|
|
*/ |
|
32
|
|
|
private $simpleThingsAuditReader; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var AuditBlockService |
|
36
|
|
|
*/ |
|
37
|
|
|
private $blockService; |
|
38
|
|
|
|
|
39
|
|
|
protected function setUp(): void |
|
40
|
|
|
{ |
|
41
|
|
|
parent::setUp(); |
|
42
|
|
|
$this->simpleThingsAuditReader = $this->createMock(SimpleThingsAuditReader::class); |
|
43
|
|
|
|
|
44
|
|
|
$this->blockService = new AuditBlockService( |
|
45
|
|
|
$this->twig, |
|
46
|
|
|
$this->simpleThingsAuditReader |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @group legacy |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testExecute(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$blockContext = $this->createMock(BlockContext::class); |
|
56
|
|
|
|
|
57
|
|
|
$blockContext->expects($this->once())->method('getBlock')->willReturn($block = new Block()); |
|
58
|
|
|
$blockContext->expects($this->once())->method('getSetting')->with('limit')->willReturn($limit = 10); |
|
59
|
|
|
|
|
60
|
|
|
$this->simpleThingsAuditReader |
|
61
|
|
|
->expects($this->once()) |
|
62
|
|
|
->method('findRevisionHistory') |
|
63
|
|
|
->with($limit, 0) |
|
64
|
|
|
->willReturn([$revision = new Revision('test', '123', 'test')]); |
|
65
|
|
|
|
|
66
|
|
|
$this->simpleThingsAuditReader |
|
67
|
|
|
->expects($this->once()) |
|
68
|
|
|
->method('findEntitiesChangedAtRevision') |
|
69
|
|
|
->willReturn([]); |
|
70
|
|
|
|
|
71
|
|
|
$blockContext->expects($this->once())->method('getTemplate')->willReturn('template'); |
|
72
|
|
|
$blockContext->expects($this->once())->method('getSettings')->willReturn([]); |
|
73
|
|
|
|
|
74
|
|
|
$this->twig |
|
|
|
|
|
|
75
|
|
|
->expects($this->once()) |
|
76
|
|
|
->method('render') |
|
77
|
|
|
->with('template', [ |
|
78
|
|
|
'block' => $block, |
|
79
|
|
|
'settings' => [], |
|
80
|
|
|
'revisions' => [['revision' => $revision, 'entities' => []]], |
|
81
|
|
|
]) |
|
82
|
|
|
->willReturn('content'); |
|
83
|
|
|
|
|
84
|
|
|
$response = $this->blockService->execute($blockContext); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertSame('content', $response->getContent()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testDefaultSettings(): void |
|
90
|
|
|
{ |
|
91
|
|
|
$blockContext = $this->getBlockContext($this->blockService); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertSettings([ |
|
94
|
|
|
'attr' => [], |
|
95
|
|
|
'extra_cache_keys' => [], |
|
96
|
|
|
'limit' => 10, |
|
97
|
|
|
'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig', |
|
98
|
|
|
'ttl' => 0, |
|
99
|
|
|
'use_cache' => true, |
|
100
|
|
|
], $blockContext); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.