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

LocationTest::testMatchLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 5
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the LocationTest 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\Location as LocationIdMatcher;
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 LocationTest 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\Location
20
     */
21
    private $matcher;
22
23
    protected function setUp()
24
    {
25
        parent::setUp();
26
        $this->matcher = new LocationIdMatcher();
27
    }
28
29
    /**
30
     * @dataProvider matchLocationProvider
31
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Location::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->getLocationMock(['id' => 123]),
50
                true,
51
            ],
52
            [
53
                123,
54
                $this->getLocationMock(['id' => 456]),
55
                false,
56
            ],
57
            [
58
                [123, 789],
59
                $this->getLocationMock(['id' => 456]),
60
                false,
61
            ],
62
            [
63
                [123, 789],
64
                $this->getLocationMock(['id' => 789]),
65
                true,
66
            ],
67
        ];
68
    }
69
70
    /**
71
     * @dataProvider matchContentInfoProvider
72
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Location::matchContentInfo
73
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig
74
     *
75
     * @param int|int[] $matchingConfig
76
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
77
     * @param bool $expectedResult
78
     */
79
    public function testMatchContentInfo($matchingConfig, ContentInfo $contentInfo, $expectedResult)
80
    {
81
        $this->matcher->setMatchingConfig($matchingConfig);
82
        $this->assertSame($expectedResult, $this->matcher->matchContentInfo($contentInfo));
83
    }
84
85
    public function matchContentInfoProvider()
86
    {
87
        return [
88
            [
89
                123,
90
                $this->getContentInfoMock(['mainLocationId' => 123]),
91
                true,
92
            ],
93
            [
94
                123,
95
                $this->getContentInfoMock(['mainLocationId' => 456]),
96
                false,
97
            ],
98
            [
99
                [123, 789],
100
                $this->getContentInfoMock(['mainLocationId' => 456]),
101
                false,
102
            ],
103
            [
104
                [123, 789],
105
                $this->getContentInfoMock(['mainLocationId' => 789]),
106
                true,
107
            ],
108
        ];
109
    }
110
}
111