Code Duplication    Length = 115-115 lines in 2 locations

eZ/Publish/Core/MVC/Symfony/Matcher/Tests/ContentBased/Id/ContentTest.php 1 location

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

eZ/Publish/Core/MVC/Symfony/Matcher/Tests/ContentBased/Id/SectionTest.php 1 location

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