getRenderContentEditableTestData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Ivoaz ContentEditable bundle.
5
 *
6
 * (c) Ivo Azirjans <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Ivoaz\Bundle\ContentEditableBundle\Tests\Twig;
13
14
use Ivoaz\Bundle\ContentEditableBundle\Editor\EditorInterface;
15
use Ivoaz\Bundle\ContentEditableBundle\Manager\ContentManagerInterface;
16
use Ivoaz\Bundle\ContentEditableBundle\Model\Content;
17
use Ivoaz\Bundle\ContentEditableBundle\Twig\ContentEditableExtension;
18
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
19
20
class ContentEditableExtensionTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @var EditorInterface|\PHPUnit_Framework_MockObject_MockObject
24
     */
25
    private $editor;
26
27
    /**
28
     * @var ContentManagerInterface|\PHPUnit_Framework_MockObject_MockObject
29
     */
30
    private $manager;
31
32
    /**
33
     * @var AuthorizationCheckerInterface|\PHPUnit_Framework_MockObject_MockObject
34
     */
35
    private $authorizationChecker;
36
37
    /**
38
     * @var ContentEditableExtension
39
     */
40
    private $extension;
41
42
    public function setUp()
43
    {
44
        $this->editor = $this->getMock(EditorInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
45
        $this->manager = $this->getMock(ContentManagerInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
46
        $this->authorizationChecker = $this->getMock(AuthorizationCheckerInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
47
48
        $this->extension = new ContentEditableExtension($this->manager, $this->authorizationChecker, $this->editor);
49
    }
50
51
    /**
52
     * @dataProvider getRenderContentEditableTestData
53
     *
54
     * @param string $expectedText
55
     * @param string $text
56
     * @param string $name
57
     * @param array  $options
58
     * @param bool   $isAuthorized
59
     * @param string $message
60
     */
61
    public function testRenderContentEditable($expectedText, $text, $name, $options, $isAuthorized, $message)
62
    {
63
        $content = new Content();
64
        $content->setId(1)
65
            ->setName($name)
66
            ->setText($text)
67
            ->setLocale($options['locale']);
68
69
        $this->manager->method('get')
70
            ->with($name, $options['locale'], $text)
71
            ->willReturn($content);
72
73
        $this->authorizationChecker->method('isGranted')
74
            ->with('ROLE_ADMIN')
75
            ->willReturn($isAuthorized);
76
77
        $this->editor->method('renderContent')
78
            ->with($content, $options)
79
            ->willReturn(sprintf('editable_%s', $text));
80
81
        $rendered = $this->extension->render($text, $name, $options);
82
83
        $this->assertSame($expectedText, $rendered, $message);
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function getRenderContentEditableTestData()
90
    {
91
        return [
92
            ['editable_text', 'text', 'name', ['locale' => 'en'], true, 'Should have rendered editable text.'],
93
            ['text', 'text', 'name', ['locale' => 'en'], false, 'Should not have rendered editable text.'],
94
        ];
95
    }
96
}
97