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

SectionTest::matchLocationProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 25
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\Id;
10
11
use eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Section as SectionIdMatcher;
12
use eZ\Publish\API\Repository\Values\Content\Location;
13
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
14
use eZ\Publish\Core\MVC\Symfony\Matcher\Tests\ContentBased\BaseTest;
15
16 View Code Duplication
class SectionTest extends BaseTest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * @var \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Section
20
     */
21
    private $matcher;
22
23
    protected function setUp()
24
    {
25
        parent::setUp();
26
        $this->matcher = new SectionIdMatcher();
27
    }
28
29
    /**
30
     * @dataProvider matchLocationProvider
31
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Section::matchLocation
32
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig
33
     *
34
     * @param int|int[] $matchingConfig
35
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
36
     * @param bool $expectedResult
37
     */
38
    public function testMatchLocation($matchingConfig, Location $location, $expectedResult)
39
    {
40
        $this->matcher->setMatchingConfig($matchingConfig);
41
        $this->assertSame($expectedResult, $this->matcher->matchLocation($location));
42
    }
43
44
    public function matchLocationProvider()
45
    {
46
        return [
47
            [
48
                123,
49
                $this->generateLocationForSectionId(123),
50
                true,
51
            ],
52
            [
53
                123,
54
                $this->generateLocationForSectionId(456),
55
                false,
56
            ],
57
            [
58
                [123, 789],
59
                $this->generateLocationForSectionId(456),
60
                false,
61
            ],
62
            [
63
                [123, 789],
64
                $this->generateLocationForSectionId(789),
65
                true,
66
            ],
67
        ];
68
    }
69
70
    /**
71
     * Generates a Location mock in respect of a given content Id.
72
     *
73
     * @param int $sectionId
74
     *
75
     * @return \PHPUnit_Framework_MockObject_MockObject
76
     */
77
    private function generateLocationForSectionId($sectionId)
78
    {
79
        $location = $this->getLocationMock();
80
        $location
81
            ->expects($this->any())
82
            ->method('getContentInfo')
83
            ->will(
84
                $this->returnValue(
85
                    $this->getContentInfoMock(['sectionId' => $sectionId])
86
                )
87
            );
88
89
        return $location;
90
    }
91
92
    /**
93
     * @dataProvider matchContentInfoProvider
94
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Section::matchContentInfo
95
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig
96
     *
97
     * @param int|int[] $matchingConfig
98
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
99
     * @param bool $expectedResult
100
     */
101
    public function testMatchContentInfo($matchingConfig, ContentInfo $contentInfo, $expectedResult)
102
    {
103
        $this->matcher->setMatchingConfig($matchingConfig);
104
        $this->assertSame($expectedResult, $this->matcher->matchContentInfo($contentInfo));
105
    }
106
107
    public function matchContentInfoProvider()
108
    {
109
        return [
110
            [
111
                123,
112
                $this->getContentInfoMock(['sectionId' => 123]),
113
                true,
114
            ],
115
            [
116
                123,
117
                $this->getContentInfoMock(['sectionId' => 456]),
118
                false,
119
            ],
120
            [
121
                [123, 789],
122
                $this->getContentInfoMock(['sectionId' => 456]),
123
                false,
124
            ],
125
            [
126
                [123, 789],
127
                $this->getContentInfoMock(['sectionId' => 789]),
128
                true,
129
            ],
130
        ];
131
    }
132
}
133