|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace eZ\Publish\Core\LocationReference\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use eZ\Publish\Core\LocationReference\LimitedLocationService; |
|
8
|
|
|
use eZ\Publish\API\Repository\LocationService; |
|
9
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
final class LimitedLocationServiceTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private const LOCATION_ID = 54; |
|
15
|
|
|
private const LOCATION_REMOTE_ID = 'babe4a915b1dd5d369e79adb9d6c0c6a'; |
|
16
|
|
|
private const LOCATION_PATH = '/1/2/54/'; |
|
17
|
|
|
|
|
18
|
|
|
/** @var \eZ\Publish\API\Repository\LocationService|\PHPUnit\Framework\MockObject\MockObject */ |
|
19
|
|
|
private $locationService; |
|
20
|
|
|
|
|
21
|
|
|
/** @var \eZ\Publish\API\Repository\Values\Content\Location */ |
|
22
|
|
|
private $expectedLocation; |
|
23
|
|
|
|
|
24
|
|
|
/** @var \eZ\Publish\Core\LocationReference\LimitedLocationService */ |
|
25
|
|
|
private $limitedLocationService; |
|
26
|
|
|
|
|
27
|
|
|
protected function setUp(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->locationService = $this->createMock(LocationService::class); |
|
30
|
|
|
$this->expectedLocation = $this->createMock(Location::class); |
|
|
|
|
|
|
31
|
|
|
$this->limitedLocationService = new LimitedLocationService($this->locationService); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testLoadLocation(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->locationService |
|
37
|
|
|
->method('loadLocation') |
|
38
|
|
|
->with(self::LOCATION_ID) |
|
39
|
|
|
->willReturn($this->expectedLocation); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertEquals( |
|
42
|
|
|
$this->expectedLocation, |
|
43
|
|
|
$this->limitedLocationService->loadLocation(self::LOCATION_ID) |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testLocationByRemoteId(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$this->locationService |
|
50
|
|
|
->method('loadLocationByRemoteId') |
|
51
|
|
|
->with(self::LOCATION_REMOTE_ID) |
|
52
|
|
|
->willReturn($this->expectedLocation); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertEquals( |
|
55
|
|
|
$this->expectedLocation, |
|
56
|
|
|
$this->limitedLocationService->loadLocationByRemoteId(self::LOCATION_REMOTE_ID) |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testLocationByPathString(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->locationService |
|
63
|
|
|
->method('loadLocation') |
|
64
|
|
|
->with(self::LOCATION_ID) |
|
65
|
|
|
->willReturn($this->expectedLocation); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertEquals( |
|
68
|
|
|
$this->expectedLocation, |
|
69
|
|
|
$this->limitedLocationService->loadLocationByPathString(self::LOCATION_PATH) |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testParentLocation(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$location = $this->createMock(Location::class); |
|
76
|
|
|
$location |
|
|
|
|
|
|
77
|
|
|
->method('__get') |
|
78
|
|
|
->with('parentLocationId') |
|
79
|
|
|
->willReturn(self::LOCATION_ID); |
|
80
|
|
|
|
|
81
|
|
|
$this->locationService |
|
82
|
|
|
->method('loadLocation') |
|
83
|
|
|
->with(self::LOCATION_ID) |
|
84
|
|
|
->willReturn($this->expectedLocation); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertEquals( |
|
87
|
|
|
$this->expectedLocation, |
|
88
|
|
|
$this->limitedLocationService->loadParentLocation($location) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
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..