1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
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\Helper\Tests; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\ContentService; |
12
|
|
|
use eZ\Publish\API\Repository\LocationService; |
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo as APIContentInfo; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location as APILocation; |
15
|
|
|
use eZ\Publish\Core\Helper\PreviewLocationProvider; |
16
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Content; |
17
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Location; |
18
|
|
|
use eZ\Publish\Core\Repository\Values\Content\VersionInfo; |
19
|
|
|
use eZ\Publish\SPI\Persistence\Content\Location\Handler as SPILocationHandler; |
20
|
|
|
use PHPUnit\Framework\TestCase; |
21
|
|
|
|
22
|
|
|
class PreviewLocationProviderTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** @var \eZ\Publish\API\Repository\LocationService|\PHPUnit\Framework\MockObject\MockObject */ |
25
|
|
|
private $contentService; |
26
|
|
|
|
27
|
|
|
/** @var \eZ\Publish\API\Repository\LocationService|\PHPUnit\Framework\MockObject\MockObject */ |
28
|
|
|
private $locationService; |
29
|
|
|
|
30
|
|
|
/** @var \eZ\Publish\SPI\Persistence\Content\Location\Handler|\PHPUnit\Framework\MockObject\MockObject */ |
31
|
|
|
private $locationHandler; |
32
|
|
|
|
33
|
|
|
/** @var \eZ\Publish\Core\Helper\PreviewLocationProvider */ |
34
|
|
|
private $provider; |
35
|
|
|
|
36
|
|
|
protected function setUp() |
37
|
|
|
{ |
38
|
|
|
parent::setUp(); |
39
|
|
|
|
40
|
|
|
$this->contentService = $this->createMock(ContentService::class); |
41
|
|
|
$this->locationService = $this->createMock(LocationService::class); |
42
|
|
|
$this->locationHandler = $this->createMock(SPILocationHandler::class); |
43
|
|
|
$this->provider = new PreviewLocationProvider($this->locationService, $this->contentService, $this->locationHandler); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testGetPreviewLocationDraft() |
47
|
|
|
{ |
48
|
|
|
$contentId = 123; |
49
|
|
|
$parentLocationId = 456; |
50
|
|
|
$content = $this->getContentMock($contentId); |
51
|
|
|
|
52
|
|
|
$this->contentService |
53
|
|
|
->expects($this->once()) |
54
|
|
|
->method('loadContent') |
55
|
|
|
->with($contentId) |
56
|
|
|
->willReturn($content); |
57
|
|
|
|
58
|
|
|
$this->locationService |
59
|
|
|
->expects($this->never()) |
60
|
|
|
->method('loadLocation'); |
61
|
|
|
|
62
|
|
|
$this->locationHandler |
63
|
|
|
->expects($this->once()) |
64
|
|
|
->method('loadParentLocationsForDraftContent') |
65
|
|
|
->with($contentId) |
66
|
|
|
->will($this->returnValue([new Location(['id' => $parentLocationId])])); |
67
|
|
|
|
68
|
|
|
$location = $this->provider->loadMainLocation($contentId); |
|
|
|
|
69
|
|
|
$this->assertInstanceOf(APILocation::class, $location); |
70
|
|
|
$this->assertSame($content, $location->getContent()); |
71
|
|
|
$this->assertNull($location->id); |
72
|
|
|
$this->assertEquals($parentLocationId, $location->parentLocationId); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetPreviewLocation() |
76
|
|
|
{ |
77
|
|
|
$contentId = 123; |
78
|
|
|
$locationId = 456; |
79
|
|
|
$content = $this->getContentMock($contentId, $locationId); |
80
|
|
|
|
81
|
|
|
$location = $this |
82
|
|
|
->getMockBuilder(Location::class) |
83
|
|
|
->setConstructorArgs([['id' => $locationId, 'content' => $content]]) |
84
|
|
|
->getMockForAbstractClass(); |
85
|
|
|
|
86
|
|
|
$this->contentService |
87
|
|
|
->expects($this->once()) |
88
|
|
|
->method('loadContent') |
89
|
|
|
->with($contentId) |
90
|
|
|
->willReturn($content); |
91
|
|
|
|
92
|
|
|
$this->locationService |
93
|
|
|
->expects($this->once()) |
94
|
|
|
->method('loadLocation') |
95
|
|
|
->with($locationId) |
96
|
|
|
->will($this->returnValue($location)); |
97
|
|
|
|
98
|
|
|
$this->locationHandler->expects($this->never())->method('loadParentLocationsForDraftContent'); |
99
|
|
|
|
100
|
|
|
$returnedLocation = $this->provider->loadMainLocation($contentId); |
|
|
|
|
101
|
|
|
$this->assertSame($location, $returnedLocation); |
102
|
|
|
$this->assertSame($content, $location->getContent()); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testGetPreviewLocationNoLocation() |
106
|
|
|
{ |
107
|
|
|
$contentId = 123; |
108
|
|
|
$content = $this->getContentMock($contentId); |
109
|
|
|
|
110
|
|
|
$this->contentService |
111
|
|
|
->expects($this->once()) |
112
|
|
|
->method('loadContent') |
113
|
|
|
->with($contentId) |
114
|
|
|
->willReturn($content); |
115
|
|
|
|
116
|
|
|
$this->locationHandler |
117
|
|
|
->expects($this->once()) |
118
|
|
|
->method('loadParentLocationsForDraftContent') |
119
|
|
|
->with($contentId) |
120
|
|
|
->will($this->returnValue([])); |
121
|
|
|
|
122
|
|
|
$this->locationHandler->expects($this->never())->method('loadLocationsByContent'); |
123
|
|
|
|
124
|
|
|
$this->assertNull($this->provider->loadMainLocation($contentId)); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
private function getContentMock(int $contentId, ?int $mainLocationId = null, bool $published = false): Content |
128
|
|
|
{ |
129
|
|
|
$contentInfo = new APIContentInfo([ |
130
|
|
|
'id' => $contentId, |
131
|
|
|
'mainLocationId' => $mainLocationId, |
132
|
|
|
'published' => $published, |
133
|
|
|
]); |
134
|
|
|
|
135
|
|
|
$versionInfo = $this->createMock(VersionInfo::class); |
136
|
|
|
$versionInfo->expects($this->once()) |
137
|
|
|
->method('getContentInfo') |
138
|
|
|
->willReturn($contentInfo); |
139
|
|
|
|
140
|
|
|
$content = $this->createMock(Content::class); |
141
|
|
|
$content->expects($this->once()) |
142
|
|
|
->method('getVersionInfo') |
143
|
|
|
->willReturn($versionInfo); |
144
|
|
|
|
145
|
|
|
return $content; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.