Completed
Pull Request — 3.x (#807)
by
unknown
01:48
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
/*
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 SimpleThings\EntityAudit\Revision;
16
use Sonata\BlockBundle\Block\BlockContext;
17
use Sonata\BlockBundle\Model\Block;
18
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
19
use Sonata\DoctrineORMAdminBundle\Block\AuditBlockService;
20
21
/**
22
 * @author Marko Kunic <[email protected]>
23
 */
24
class AuditBlockServiceTest extends AbstractBlockServiceTestCase
25
{
26
    private $simpleThingsAuditReader;
27
    private $blockService;
28
29
    protected function setUp()
30
    {
31
        parent::setUp();
32
        $this->simpleThingsAuditReader = $this->prophesize(SimpleThingsAuditReader::class);
33
34
        $this->blockService = new AuditBlockService(
35
            'block.service',
36
            $this->templating,
37
            $this->simpleThingsAuditReader->reveal()
38
        );
39
    }
40
41
    /**
42
     * @group legacy
43
     */
44
    public function testExecute()
45
    {
46
        $block = $this->prophesize(Block::class);
47
        $revision = $this->prophesize(Revision::class);
48
        $blockContext = $this->prophesize(BlockContext::class);
49
50
        $blockContext->getBlock()->willReturn($block->reveal())->shouldBeCalledTimes(1);
51
        $blockContext->getSetting('limit')->willReturn($limit = 10)->shouldBeCalledTimes(1);
52
        $revision->getRev()->willReturn($rev = 2)->shouldBeCalledTimes(1);
53
54
        $this->simpleThingsAuditReader->findRevisionHistory($limit, 0)
55
            ->willReturn([$revision->reveal()])
56
            ->shouldBeCalledTimes(1);
57
58
        $this->simpleThingsAuditReader->findEntitesChangedAtRevision($rev)
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->reveal(), $this->templating->parameters['revisions'][0]['revision']);
70
        $this->assertSame($block->reveal(), $this->templating->parameters['block']);
71
    }
72
73
    public function testDefaultSettings()
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