Completed
Push — 6.13 ( 9c335d...8c8805 )
by
unknown
16:33
created

SectionTest::matchSectionProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the SectionTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\MVC\Symfony\Matcher\Tests\ContentBased\Identifier;
10
11
use eZ\Publish\API\Repository\SectionService;
12
use eZ\Publish\API\Repository\Values\Content\Section;
13
use eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Identifier\Section as SectionIdentifierMatcher;
14
use eZ\Publish\Core\MVC\Symfony\Matcher\Tests\ContentBased\BaseTest;
15
use eZ\Publish\API\Repository\Repository;
16
17
class SectionTest extends BaseTest
18
{
19
    /**
20
     * @var \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Identifier\Section
21
     */
22
    private $matcher;
23
24
    protected function setUp()
25
    {
26
        parent::setUp();
27
        $this->matcher = new SectionIdentifierMatcher();
28
    }
29
30
    /**
31
     * Returns a Repository mock configured to return the appropriate Section object with given section identifier.
32
     *
33
     * @param string $sectionIdentifier
34
     *
35
     * @return \PHPUnit_Framework_MockObject_MockObject
36
     */
37 View Code Duplication
    private function generateRepositoryMockForSectionIdentifier($sectionIdentifier)
38
    {
39
        $sectionServiceMock = $this->createMock(SectionService::class);
40
        $sectionServiceMock->expects($this->once())
41
            ->method('loadSection')
42
            ->will(
43
                $this->returnValue(
44
                    $this
45
                        ->getMockBuilder(Section::class)
46
                        ->setConstructorArgs(
47
                            [
48
                                ['identifier' => $sectionIdentifier],
49
                            ]
50
                        )
51
                        ->getMockForAbstractClass()
52
                )
53
            );
54
55
        $repository = $this->getRepositoryMock();
56
        $repository
57
            ->expects($this->once())
58
            ->method('getSectionService')
59
            ->will($this->returnValue($sectionServiceMock));
60
        $repository
61
            ->expects($this->any())
62
            ->method('getPermissionResolver')
63
            ->will($this->returnValue($this->getPermissionResolverMock()));
64
65
        return $repository;
66
    }
67
68
    /**
69
     * @dataProvider matchSectionProvider
70
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Identifier\Section::matchLocation
71
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig
72
     * @covers \eZ\Publish\Core\MVC\RepositoryAware::setRepository
73
     *
74
     * @param string|string[] $matchingConfig
75
     * @param \eZ\Publish\API\Repository\Repository $repository
76
     * @param bool $expectedResult
77
     */
78
    public function testMatchLocation($matchingConfig, Repository $repository, $expectedResult)
79
    {
80
        $this->matcher->setRepository($repository);
81
        $this->matcher->setMatchingConfig($matchingConfig);
82
        $location = $this->getLocationMock();
83
        $location
84
            ->expects($this->once())
85
            ->method('getContentInfo')
86
            ->will(
87
                $this->returnValue(
88
                    $this->getContentInfoMock()
89
                )
90
            );
91
        $this->assertSame(
92
            $expectedResult,
93
            $this->matcher->matchLocation($location)
94
        );
95
    }
96
97
    public function matchSectionProvider()
98
    {
99
        return [
100
            [
101
                'foo',
102
                $this->generateRepositoryMockForSectionIdentifier('foo'),
103
                true,
104
            ],
105
            [
106
                'foo',
107
                $this->generateRepositoryMockForSectionIdentifier('bar'),
108
                false,
109
            ],
110
            [
111
                ['foo', 'baz'],
112
                $this->generateRepositoryMockForSectionIdentifier('bar'),
113
                false,
114
            ],
115
            [
116
                ['foo', 'baz'],
117
                $this->generateRepositoryMockForSectionIdentifier('baz'),
118
                true,
119
            ],
120
        ];
121
    }
122
123
    /**
124
     * @dataProvider matchSectionProvider
125
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Identifier\Section::matchContentInfo
126
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig
127
     * @covers \eZ\Publish\Core\MVC\RepositoryAware::setRepository
128
     *
129
     * @param string|string[] $matchingConfig
130
     * @param \eZ\Publish\API\Repository\Repository $repository
131
     * @param bool $expectedResult
132
     */
133 View Code Duplication
    public function testMatchContentInfo($matchingConfig, Repository $repository, $expectedResult)
134
    {
135
        $this->matcher->setRepository($repository);
136
        $this->matcher->setMatchingConfig($matchingConfig);
137
        $this->assertSame(
138
            $expectedResult,
139
            $this->matcher->matchContentInfo($this->getContentInfoMock())
140
        );
141
    }
142
}
143