Completed
Push — EZP-31584 ( 18fefe )
by
unknown
19:33
created

PermissionAwareLocationResolverTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 56
c 0
b 0
f 0
rs 10
wmc 3
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testResolveMainLocation() 0 12 1
A testResolveSecondaryLocation() 0 17 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Repository\Tests\LocationResolver;
10
11
use eZ\Publish\API\Repository\Exceptions\UnauthorizedException;
12
use eZ\Publish\API\Repository\LocationService;
13
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
14
use eZ\Publish\Core\Repository\LocationResolver\PermissionAwareLocationResolver;
15
use eZ\Publish\Core\Repository\Values\Content\Location;
16
use PHPUnit\Framework\TestCase;
17
18
final class PermissionAwareLocationResolverTest extends TestCase
19
{
20
    /** @var \eZ\Publish\API\Repository\LocationService */
21
    private $locationService;
22
23
    /** @var \eZ\Publish\Core\Repository\LocationResolver\LocationResolver */
24
    private $locationResolver;
25
26
    public function setUp(): void
27
    {
28
        $this->locationService = $this->createMock(LocationService::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\eZ\Pu...LocationService::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<eZ\Publish\API\Repository\LocationService> of property $locationService.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
29
30
        $this->locationResolver = new PermissionAwareLocationResolver($this->locationService);
31
    }
32
33
    /**
34
     * Test for the resolveLocation() method.
35
     *
36
     * @covers \eZ\Publish\Core\Repository\LocationResolver\PermissionAwareLocationResolver::resolveLocation()
37
     */
38
    public function testResolveMainLocation(): void
39
    {
40
        $contentInfo = new ContentInfo(['mainLocationId' => 42]);
41
        $location = new Location(['id' => 42]);
42
43
        // User has access to the main Location
44
        $this->locationService
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<eZ\Publish\API\Repository\LocationService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
            ->method('loadLocation')
46
            ->willReturn($location);
47
48
        $this->assertSame($location, $this->locationResolver->resolveLocation($contentInfo));
49
    }
50
51
    /**
52
     * Test for the resolveLocation() method.
53
     *
54
     * @covers \eZ\Publish\Core\Repository\LocationResolver\PermissionAwareLocationResolver::resolveLocation()
55
     */
56
    public function testResolveSecondaryLocation(): void
57
    {
58
        $contentInfo = new ContentInfo(['mainLocationId' => 42]);
59
        $location1 = new Location(['id' => 43]);
60
        $location2 = new Location(['id' => 44]);
61
62
        // User doesn't have access to main location but to the third Content's location
63
        $this->locationService
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<eZ\Publish\API\Repository\LocationService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
            ->method('loadLocation')
65
            ->willThrowException($this->createMock(UnauthorizedException::class));
66
67
        $this->locationService
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<eZ\Publish\API\Repository\LocationService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
            ->method('loadLocations')
69
            ->willReturn([$location1, $location2]);
70
71
        $this->assertSame($location1, $this->locationResolver->resolveLocation($contentInfo));
72
    }
73
}
74