Completed
Pull Request — master (#812)
by
unknown
05:20 queued 01:45
created

AuditBlockServiceTest::testDefaultSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
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 Prophecy\Argument;
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\AbstractBlockServiceTestCase;
22
use Sonata\DoctrineORMAdminBundle\Block\AuditBlockService;
23
24
/**
25
 * @author Marko Kunic <[email protected]>
26
 */
27
class AuditBlockServiceTest extends AbstractBlockServiceTestCase
28
{
29
    private $simpleThingsAuditReader;
30
    private $blockService;
31
32
    protected function setUp(): void
33
    {
34
        parent::setUp();
35
        $this->simpleThingsAuditReader = $this->prophesize(SimpleThingsAuditReader::class);
36
37
        $this->blockService = new AuditBlockService(
38
            'block.service',
39
            $this->templating,
40
            $this->simpleThingsAuditReader->reveal()
41
        );
42
    }
43
44
    /**
45
     * @group legacy
46
     */
47
    public function testExecute(): void
48
    {
49
        $blockContext = $this->prophesize(BlockContext::class);
50
51
        $blockContext->getBlock()->willReturn($block = new Block())->shouldBeCalledTimes(1);
52
        $blockContext->getSetting('limit')->willReturn($limit = 10)->shouldBeCalledTimes(1);
53
54
        $this->simpleThingsAuditReader->findRevisionHistory($limit, 0)
55
            ->willReturn([$revision = new Revision('test', '123', 'test')])
56
            ->shouldBeCalledTimes(1);
57
58
        $this->simpleThingsAuditReader->findEntitesChangedAtRevision(Argument::cetera())
59
            ->willReturn([])
60
            ->shouldBeCalledTimes(1);
61
62
        $blockContext->getTemplate()->willReturn('template')->shouldBeCalledTimes(1);
63
        $blockContext->getSettings()->willReturn([])->shouldBeCalledTimes(1);
64
65
        $this->blockService->execute($blockContext->reveal());
66
67
        $this->assertSame('template', $this->templating->view);
68
        $this->assertInternalType('array', $this->templating->parameters['settings']);
69
        $this->assertSame($revision, $this->templating->parameters['revisions'][0]['revision']);
70
        $this->assertSame($block, $this->templating->parameters['block']);
71
    }
72
73
    public function testDefaultSettings(): void
74
    {
75
        $blockContext = $this->getBlockContext($this->blockService);
76
77
        $this->assertSettings([
78
            'attr' => [],
79
            'extra_cache_keys' => [],
80
            'limit' => 10,
81
            'template' => '@SonataDoctrineORMAdmin/Block/block_audit.html.twig',
82
            'ttl' => 0,
83
            'use_cache' => true,
84
        ], $blockContext);
85
    }
86
}
87