Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ContentTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ContentTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 59 | class ContentTest extends BaseServiceMockTest  | 
            ||
| 60 | { | 
            ||
| 61 | /**  | 
            ||
| 62 | * Represents empty Field Value.  | 
            ||
| 63 | */  | 
            ||
| 64 | const EMPTY_FIELD_VALUE = 'empty';  | 
            ||
| 65 | |||
| 66 | /**  | 
            ||
| 67 | * Test for the __construct() method.  | 
            ||
| 68 | *  | 
            ||
| 69 | * @covers \eZ\Publish\Core\Repository\ContentService::__construct  | 
            ||
| 70 | */  | 
            ||
| 71 | public function testConstructor(): void  | 
            ||
| 72 |     { | 
            ||
| 73 | $repositoryMock = $this->getRepositoryMock();  | 
            ||
| 74 | /** @var \eZ\Publish\SPI\Persistence\Handler $persistenceHandlerMock */  | 
            ||
| 75 |         $persistenceHandlerMock = $this->getPersistenceMockHandler('Handler'); | 
            ||
| 76 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 77 | $relationProcessorMock = $this->getRelationProcessorMock();  | 
            ||
| 78 | $nameSchemaServiceMock = $this->getNameSchemaServiceMock();  | 
            ||
| 79 | $fieldTypeRegistryMock = $this->getFieldTypeRegistryMock();  | 
            ||
| 80 | $permissionResolverMock = $this->getPermissionResolverMock();  | 
            ||
| 81 | $settings = ['default_version_archive_limit' => 10];  | 
            ||
| 82 | |||
| 83 | $service = new ContentService(  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 84 | $repositoryMock,  | 
            ||
| 85 | $persistenceHandlerMock,  | 
            ||
| 86 | $domainMapperMock,  | 
            ||
| 87 | $relationProcessorMock,  | 
            ||
| 88 | $nameSchemaServiceMock,  | 
            ||
| 89 | $fieldTypeRegistryMock,  | 
            ||
| 90 | $permissionResolverMock,  | 
            ||
| 91 | $settings  | 
            ||
| 92 | );  | 
            ||
| 93 | }  | 
            ||
| 94 | |||
| 95 | /**  | 
            ||
| 96 | * Test for the loadVersionInfo() method, of published version.  | 
            ||
| 97 | *  | 
            ||
| 98 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById  | 
            ||
| 99 | */  | 
            ||
| 100 | public function testLoadVersionInfoById()  | 
            ||
| 101 |     { | 
            ||
| 102 | $contentServiceMock = $this->getPartlyMockedContentService(['loadContentInfo']);  | 
            ||
| 103 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */  | 
            ||
| 104 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 105 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 106 | $versionInfoMock = $this->createMock(APIVersionInfo::class);  | 
            ||
| 107 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 108 | |||
| 109 | $versionInfoMock->expects($this->once())  | 
            ||
| 110 |             ->method('isPublished') | 
            ||
| 111 | ->willReturn(true);  | 
            ||
| 112 | |||
| 113 | $contentServiceMock->expects($this->never())  | 
            ||
| 114 |             ->method('loadContentInfo'); | 
            ||
| 115 | |||
| 116 | $contentHandler->expects($this->once())  | 
            ||
| 117 |             ->method('loadVersionInfo') | 
            ||
| 118 | ->with(  | 
            ||
| 119 | $this->equalTo(42),  | 
            ||
| 120 | $this->equalTo(null)  | 
            ||
| 121 | )->will(  | 
            ||
| 122 | $this->returnValue(new SPIVersionInfo())  | 
            ||
| 123 | );  | 
            ||
| 124 | |||
| 125 | $domainMapperMock->expects($this->once())  | 
            ||
| 126 |             ->method('buildVersionInfoDomainObject') | 
            ||
| 127 | ->with(new SPIVersionInfo())  | 
            ||
| 128 | ->will($this->returnValue($versionInfoMock));  | 
            ||
| 129 | |||
| 130 | $permissionResolver->expects($this->once())  | 
            ||
| 131 |             ->method('canUser') | 
            ||
| 132 | ->with(  | 
            ||
| 133 |                 $this->equalTo('content'), | 
            ||
| 134 |                 $this->equalTo('read'), | 
            ||
| 135 | $this->equalTo($versionInfoMock)  | 
            ||
| 136 | )->will($this->returnValue(true));  | 
            ||
| 137 | |||
| 138 | $result = $contentServiceMock->loadVersionInfoById(42);  | 
            ||
| 139 | |||
| 140 | $this->assertEquals($versionInfoMock, $result);  | 
            ||
| 141 | }  | 
            ||
| 142 | |||
| 143 | /**  | 
            ||
| 144 | * Test for the loadVersionInfo() method, of a draft.  | 
            ||
| 145 | *  | 
            ||
| 146 | * @depends testLoadVersionInfoById  | 
            ||
| 147 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById  | 
            ||
| 148 | */  | 
            ||
| 149 | public function testLoadVersionInfoByIdAndVersionNumber()  | 
            ||
| 150 |     { | 
            ||
| 151 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 152 | $contentServiceMock = $this->getPartlyMockedContentService(['loadContentInfo']);  | 
            ||
| 153 | /** @var \PHPUnit_Framework_MockObject_MockObject $contentHandler */  | 
            ||
| 154 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 155 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 156 | $versionInfoMock = $this->createMock(APIVersionInfo::class);  | 
            ||
| 157 | |||
| 158 | $versionInfoMock->expects($this->any())  | 
            ||
| 159 |             ->method('__get') | 
            ||
| 160 |             ->with('status') | 
            ||
| 161 | ->willReturn(APIVersionInfo::STATUS_DRAFT);  | 
            ||
| 162 | |||
| 163 | $contentServiceMock->expects($this->never())  | 
            ||
| 164 |             ->method('loadContentInfo'); | 
            ||
| 165 | |||
| 166 | $contentHandler->expects($this->once())  | 
            ||
| 167 |             ->method('loadVersionInfo') | 
            ||
| 168 | ->with(  | 
            ||
| 169 | $this->equalTo(42),  | 
            ||
| 170 | $this->equalTo(2)  | 
            ||
| 171 | )->willReturn(new SPIVersionInfo());  | 
            ||
| 172 | |||
| 173 | $domainMapperMock->expects($this->once())  | 
            ||
| 174 |             ->method('buildVersionInfoDomainObject') | 
            ||
| 175 | ->with(new SPIVersionInfo())  | 
            ||
| 176 | ->willReturn($versionInfoMock);  | 
            ||
| 177 | |||
| 178 | $permissionResolver->expects($this->once())  | 
            ||
| 179 |             ->method('canUser') | 
            ||
| 180 | ->with(  | 
            ||
| 181 |                 $this->equalTo('content'), | 
            ||
| 182 |                 $this->equalTo('versionread'), | 
            ||
| 183 | $this->equalTo($versionInfoMock)  | 
            ||
| 184 | )->willReturn(true);  | 
            ||
| 185 | |||
| 186 | $result = $contentServiceMock->loadVersionInfoById(42, 2);  | 
            ||
| 187 | |||
| 188 | $this->assertEquals($versionInfoMock, $result);  | 
            ||
| 189 | }  | 
            ||
| 190 | |||
| 191 | /**  | 
            ||
| 192 | * Test for the loadVersionInfo() method.  | 
            ||
| 193 | *  | 
            ||
| 194 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById  | 
            ||
| 195 | */  | 
            ||
| 196 | public function testLoadVersionInfoByIdThrowsNotFoundException()  | 
            ||
| 197 |     { | 
            ||
| 198 | $this->expectException(\eZ\Publish\Core\Base\Exceptions\NotFoundException::class);  | 
            ||
| 199 | |||
| 200 | $contentServiceMock = $this->getPartlyMockedContentService(['loadContentInfo']);  | 
            ||
| 201 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */  | 
            ||
| 202 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 203 | |||
| 204 | $contentHandler->expects($this->once())  | 
            ||
| 205 |             ->method('loadVersionInfo') | 
            ||
| 206 | ->with(  | 
            ||
| 207 | $this->equalTo(42),  | 
            ||
| 208 | $this->equalTo(24)  | 
            ||
| 209 | )->will(  | 
            ||
| 210 | $this->throwException(  | 
            ||
| 211 | new NotFoundException(  | 
            ||
| 212 | 'Content',  | 
            ||
| 213 | [  | 
            ||
| 214 | 'contentId' => 42,  | 
            ||
| 215 | 'versionNo' => 24,  | 
            ||
| 216 | ]  | 
            ||
| 217 | )  | 
            ||
| 218 | )  | 
            ||
| 219 | );  | 
            ||
| 220 | |||
| 221 | $contentServiceMock->loadVersionInfoById(42, 24);  | 
            ||
| 222 | }  | 
            ||
| 223 | |||
| 224 | /**  | 
            ||
| 225 | * Test for the loadVersionInfo() method.  | 
            ||
| 226 | *  | 
            ||
| 227 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById  | 
            ||
| 228 | */  | 
            ||
| 229 | public function testLoadVersionInfoByIdThrowsUnauthorizedExceptionNonPublishedVersion()  | 
            ||
| 230 |     { | 
            ||
| 231 | $this->expectException(\eZ\Publish\Core\Base\Exceptions\UnauthorizedException::class);  | 
            ||
| 232 | |||
| 233 | $contentServiceMock = $this->getPartlyMockedContentService();  | 
            ||
| 234 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */  | 
            ||
| 235 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 236 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 237 | $versionInfoMock = $this->createMock(APIVersionInfo::class);  | 
            ||
| 238 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 239 | |||
| 240 | $versionInfoMock->expects($this->any())  | 
            ||
| 241 |             ->method('isPublished') | 
            ||
| 242 | ->willReturn(false);  | 
            ||
| 243 | |||
| 244 | $contentHandler->expects($this->once())  | 
            ||
| 245 |             ->method('loadVersionInfo') | 
            ||
| 246 | ->with(  | 
            ||
| 247 | $this->equalTo(42),  | 
            ||
| 248 | $this->equalTo(24)  | 
            ||
| 249 | )->will(  | 
            ||
| 250 | $this->returnValue(new SPIVersionInfo())  | 
            ||
| 251 | );  | 
            ||
| 252 | |||
| 253 | $domainMapperMock->expects($this->once())  | 
            ||
| 254 |             ->method('buildVersionInfoDomainObject') | 
            ||
| 255 | ->with(new SPIVersionInfo())  | 
            ||
| 256 | ->will($this->returnValue($versionInfoMock));  | 
            ||
| 257 | |||
| 258 | $permissionResolver->expects($this->once())  | 
            ||
| 259 |             ->method('canUser') | 
            ||
| 260 | ->with(  | 
            ||
| 261 |                 $this->equalTo('content'), | 
            ||
| 262 |                 $this->equalTo('versionread'), | 
            ||
| 263 | $this->equalTo($versionInfoMock)  | 
            ||
| 264 | )->will($this->returnValue(false));  | 
            ||
| 265 | |||
| 266 | $contentServiceMock->loadVersionInfoById(42, 24);  | 
            ||
| 267 | }  | 
            ||
| 268 | |||
| 269 | /**  | 
            ||
| 270 | * Test for the loadVersionInfo() method.  | 
            ||
| 271 | *  | 
            ||
| 272 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById  | 
            ||
| 273 | */  | 
            ||
| 274 | View Code Duplication | public function testLoadVersionInfoByIdPublishedVersion()  | 
            |
| 275 |     { | 
            ||
| 276 | $contentServiceMock = $this->getPartlyMockedContentService();  | 
            ||
| 277 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */  | 
            ||
| 278 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 279 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 280 | $versionInfoMock = $this->createMock(APIVersionInfo::class);  | 
            ||
| 281 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 282 | |||
| 283 | $versionInfoMock->expects($this->once())  | 
            ||
| 284 |             ->method('isPublished') | 
            ||
| 285 | ->willReturn(true);  | 
            ||
| 286 | |||
| 287 | $contentHandler->expects($this->once())  | 
            ||
| 288 |             ->method('loadVersionInfo') | 
            ||
| 289 | ->with(  | 
            ||
| 290 | $this->equalTo(42),  | 
            ||
| 291 | $this->equalTo(24)  | 
            ||
| 292 | )->will(  | 
            ||
| 293 | $this->returnValue(new SPIVersionInfo())  | 
            ||
| 294 | );  | 
            ||
| 295 | |||
| 296 | $domainMapperMock->expects($this->once())  | 
            ||
| 297 |             ->method('buildVersionInfoDomainObject') | 
            ||
| 298 | ->with(new SPIVersionInfo())  | 
            ||
| 299 | ->will($this->returnValue($versionInfoMock));  | 
            ||
| 300 | |||
| 301 | $permissionResolver->expects($this->once())  | 
            ||
| 302 |             ->method('canUser') | 
            ||
| 303 | ->with(  | 
            ||
| 304 |                 $this->equalTo('content'), | 
            ||
| 305 |                 $this->equalTo('read'), | 
            ||
| 306 | $this->equalTo($versionInfoMock)  | 
            ||
| 307 | )->will($this->returnValue(true));  | 
            ||
| 308 | |||
| 309 | $result = $contentServiceMock->loadVersionInfoById(42, 24);  | 
            ||
| 310 | |||
| 311 | $this->assertEquals($versionInfoMock, $result);  | 
            ||
| 312 | }  | 
            ||
| 313 | |||
| 314 | /**  | 
            ||
| 315 | * Test for the loadVersionInfo() method.  | 
            ||
| 316 | *  | 
            ||
| 317 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfoById  | 
            ||
| 318 | */  | 
            ||
| 319 | View Code Duplication | public function testLoadVersionInfoByIdNonPublishedVersion()  | 
            |
| 320 |     { | 
            ||
| 321 | $contentServiceMock = $this->getPartlyMockedContentService();  | 
            ||
| 322 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */  | 
            ||
| 323 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 324 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 325 | $versionInfoMock = $this->createMock(APIVersionInfo::class);  | 
            ||
| 326 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 327 | |||
| 328 | $versionInfoMock->expects($this->once())  | 
            ||
| 329 |             ->method('isPublished') | 
            ||
| 330 | ->willReturn(false);  | 
            ||
| 331 | |||
| 332 | $contentHandler->expects($this->once())  | 
            ||
| 333 |             ->method('loadVersionInfo') | 
            ||
| 334 | ->with(  | 
            ||
| 335 | $this->equalTo(42),  | 
            ||
| 336 | $this->equalTo(24)  | 
            ||
| 337 | )->will(  | 
            ||
| 338 | $this->returnValue(new SPIVersionInfo())  | 
            ||
| 339 | );  | 
            ||
| 340 | |||
| 341 | $domainMapperMock->expects($this->once())  | 
            ||
| 342 |             ->method('buildVersionInfoDomainObject') | 
            ||
| 343 | ->with(new SPIVersionInfo())  | 
            ||
| 344 | ->will($this->returnValue($versionInfoMock));  | 
            ||
| 345 | |||
| 346 | $permissionResolver->expects($this->once())  | 
            ||
| 347 |             ->method('canUser') | 
            ||
| 348 | ->with(  | 
            ||
| 349 |                 $this->equalTo('content'), | 
            ||
| 350 |                 $this->equalTo('versionread'), | 
            ||
| 351 | $this->equalTo($versionInfoMock)  | 
            ||
| 352 | )->will($this->returnValue(true));  | 
            ||
| 353 | |||
| 354 | $result = $contentServiceMock->loadVersionInfoById(42, 24);  | 
            ||
| 355 | |||
| 356 | $this->assertEquals($versionInfoMock, $result);  | 
            ||
| 357 | }  | 
            ||
| 358 | |||
| 359 | /**  | 
            ||
| 360 | * Test for the loadVersionInfo() method.  | 
            ||
| 361 | *  | 
            ||
| 362 | * @covers \eZ\Publish\Core\Repository\ContentService::loadVersionInfo  | 
            ||
| 363 | * @depends eZ\Publish\Core\Repository\Tests\Service\Mock\ContentTest::testLoadVersionInfoById  | 
            ||
| 364 | * @depends eZ\Publish\Core\Repository\Tests\Service\Mock\ContentTest::testLoadVersionInfoByIdThrowsNotFoundException  | 
            ||
| 365 | * @depends eZ\Publish\Core\Repository\Tests\Service\Mock\ContentTest::testLoadVersionInfoByIdThrowsUnauthorizedExceptionNonPublishedVersion  | 
            ||
| 366 | * @depends eZ\Publish\Core\Repository\Tests\Service\Mock\ContentTest::testLoadVersionInfoByIdPublishedVersion  | 
            ||
| 367 | * @depends eZ\Publish\Core\Repository\Tests\Service\Mock\ContentTest::testLoadVersionInfoByIdNonPublishedVersion  | 
            ||
| 368 | */  | 
            ||
| 369 | public function testLoadVersionInfo()  | 
            ||
| 370 |     { | 
            ||
| 371 | $contentServiceMock = $this->getPartlyMockedContentService(  | 
            ||
| 372 | ['loadVersionInfoById']  | 
            ||
| 373 | );  | 
            ||
| 374 | $contentServiceMock->expects(  | 
            ||
| 375 | $this->once()  | 
            ||
| 376 | )->method(  | 
            ||
| 377 | 'loadVersionInfoById'  | 
            ||
| 378 | )->with(  | 
            ||
| 379 | $this->equalTo(42),  | 
            ||
| 380 | $this->equalTo(7)  | 
            ||
| 381 | )->will(  | 
            ||
| 382 |             $this->returnValue('result') | 
            ||
| 383 | );  | 
            ||
| 384 | |||
| 385 | $result = $contentServiceMock->loadVersionInfo(  | 
            ||
| 386 | new ContentInfo(['id' => 42]),  | 
            ||
| 387 | 7  | 
            ||
| 388 | );  | 
            ||
| 389 | |||
| 390 |         $this->assertEquals('result', $result); | 
            ||
| 391 | }  | 
            ||
| 392 | |||
| 393 | public function testLoadContent()  | 
            ||
| 394 |     { | 
            ||
| 395 | $contentService = $this->getPartlyMockedContentService(['internalLoadContent']);  | 
            ||
| 396 | $content = $this->createMock(APIContent::class);  | 
            ||
| 397 | $versionInfo = $this->createMock(APIVersionInfo::class);  | 
            ||
| 398 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 399 | |||
| 400 | $content  | 
            ||
| 401 | ->expects($this->once())  | 
            ||
| 402 |             ->method('getVersionInfo') | 
            ||
| 403 | ->will($this->returnValue($versionInfo));  | 
            ||
| 404 | $versionInfo  | 
            ||
| 405 | ->expects($this->once())  | 
            ||
| 406 |             ->method('isPublished') | 
            ||
| 407 | ->willReturn(true);  | 
            ||
| 408 | $contentId = 123;  | 
            ||
| 409 | $contentService  | 
            ||
| 410 | ->expects($this->once())  | 
            ||
| 411 |             ->method('internalLoadContent') | 
            ||
| 412 | ->with($contentId)  | 
            ||
| 413 | ->will($this->returnValue($content));  | 
            ||
| 414 | |||
| 415 | $permissionResolver  | 
            ||
| 416 | ->expects($this->once())  | 
            ||
| 417 |             ->method('canUser') | 
            ||
| 418 |             ->with('content', 'read', $content) | 
            ||
| 419 | ->will($this->returnValue(true));  | 
            ||
| 420 | |||
| 421 | $this->assertSame($content, $contentService->loadContent($contentId));  | 
            ||
| 422 | }  | 
            ||
| 423 | |||
| 424 | View Code Duplication | public function testLoadContentNonPublished()  | 
            |
| 425 |     { | 
            ||
| 426 | $contentService = $this->getPartlyMockedContentService(['internalLoadContent']);  | 
            ||
| 427 | $content = $this->createMock(APIContent::class);  | 
            ||
| 428 | $versionInfo = $this->createMock(APIVersionInfo::class);  | 
            ||
| 429 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 430 | |||
| 431 | $content  | 
            ||
| 432 | ->expects($this->once())  | 
            ||
| 433 |             ->method('getVersionInfo') | 
            ||
| 434 | ->will($this->returnValue($versionInfo));  | 
            ||
| 435 | $contentId = 123;  | 
            ||
| 436 | $contentService  | 
            ||
| 437 | ->expects($this->once())  | 
            ||
| 438 |             ->method('internalLoadContent') | 
            ||
| 439 | ->with($contentId)  | 
            ||
| 440 | ->will($this->returnValue($content));  | 
            ||
| 441 | |||
| 442 | $permissionResolver  | 
            ||
| 443 | ->expects($this->exactly(2))  | 
            ||
| 444 |             ->method('canUser') | 
            ||
| 445 | ->will(  | 
            ||
| 446 | $this->returnValueMap(  | 
            ||
| 447 | [  | 
            ||
| 448 | ['content', 'read', $content, [], true],  | 
            ||
| 449 | ['content', 'versionread', $content, [], true],  | 
            ||
| 450 | ]  | 
            ||
| 451 | )  | 
            ||
| 452 | );  | 
            ||
| 453 | |||
| 454 | $this->assertSame($content, $contentService->loadContent($contentId));  | 
            ||
| 455 | }  | 
            ||
| 456 | |||
| 457 | public function testLoadContentUnauthorized()  | 
            ||
| 458 |     { | 
            ||
| 459 | $this->expectException(\eZ\Publish\Core\Base\Exceptions\UnauthorizedException::class);  | 
            ||
| 460 | |||
| 461 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 462 | |||
| 463 | $contentService = $this->getPartlyMockedContentService(['internalLoadContent']);  | 
            ||
| 464 | $content = $this->createMock(APIContent::class);  | 
            ||
| 465 | $contentId = 123;  | 
            ||
| 466 | $contentService  | 
            ||
| 467 | ->expects($this->once())  | 
            ||
| 468 |             ->method('internalLoadContent') | 
            ||
| 469 | ->with($contentId)  | 
            ||
| 470 | ->will($this->returnValue($content));  | 
            ||
| 471 | |||
| 472 | $permissionResolver  | 
            ||
| 473 | ->expects($this->once())  | 
            ||
| 474 |             ->method('canUser') | 
            ||
| 475 |             ->with('content', 'read', $content) | 
            ||
| 476 | ->will($this->returnValue(false));  | 
            ||
| 477 | |||
| 478 | $contentService->loadContent($contentId);  | 
            ||
| 479 | }  | 
            ||
| 480 | |||
| 481 | View Code Duplication | public function testLoadContentNotPublishedStatusUnauthorized()  | 
            |
| 482 |     { | 
            ||
| 483 | $this->expectException(\eZ\Publish\Core\Base\Exceptions\UnauthorizedException::class);  | 
            ||
| 484 | |||
| 485 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 486 | $contentService = $this->getPartlyMockedContentService(['internalLoadContent']);  | 
            ||
| 487 | $content = $this->createMock(APIContent::class);  | 
            ||
| 488 | $versionInfo = $this  | 
            ||
| 489 | ->getMockBuilder(APIVersionInfo::class)  | 
            ||
| 490 | ->getMockForAbstractClass();  | 
            ||
| 491 | $content  | 
            ||
| 492 | ->expects($this->once())  | 
            ||
| 493 |             ->method('getVersionInfo') | 
            ||
| 494 | ->will($this->returnValue($versionInfo));  | 
            ||
| 495 | $contentId = 123;  | 
            ||
| 496 | $contentService  | 
            ||
| 497 | ->expects($this->once())  | 
            ||
| 498 |             ->method('internalLoadContent') | 
            ||
| 499 | ->with($contentId)  | 
            ||
| 500 | ->will($this->returnValue($content));  | 
            ||
| 501 | |||
| 502 | $permissionResolver  | 
            ||
| 503 | ->expects($this->exactly(2))  | 
            ||
| 504 |             ->method('canUser') | 
            ||
| 505 | ->will(  | 
            ||
| 506 | $this->returnValueMap(  | 
            ||
| 507 | [  | 
            ||
| 508 | ['content', 'read', $content, [], true],  | 
            ||
| 509 | ['content', 'versionread', $content, [], false],  | 
            ||
| 510 | ]  | 
            ||
| 511 | )  | 
            ||
| 512 | );  | 
            ||
| 513 | |||
| 514 | $contentService->loadContent($contentId);  | 
            ||
| 515 | }  | 
            ||
| 516 | |||
| 517 | /**  | 
            ||
| 518 | * @dataProvider internalLoadContentProvider  | 
            ||
| 519 | */  | 
            ||
| 520 | public function testInternalLoadContent($id, $languages, $versionNo, $isRemoteId, $useAlwaysAvailable)  | 
            ||
| 521 |     { | 
            ||
| 522 | $contentService = $this->getPartlyMockedContentService();  | 
            ||
| 523 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */  | 
            ||
| 524 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 525 | $realId = $id;  | 
            ||
| 526 | |||
| 527 |         if ($isRemoteId) { | 
            ||
| 528 | $realId = 123;  | 
            ||
| 529 | $spiContentInfo = new SPIContentInfo(['currentVersionNo' => $versionNo ?: 7, 'id' => $realId]);  | 
            ||
| 530 | $contentHandler  | 
            ||
| 531 | ->expects($this->once())  | 
            ||
| 532 |                 ->method('loadContentInfoByRemoteId') | 
            ||
| 533 | ->with($id)  | 
            ||
| 534 | ->will($this->returnValue($spiContentInfo));  | 
            ||
| 535 |         } elseif (!empty($languages) && $useAlwaysAvailable) { | 
            ||
| 536 | $spiContentInfo = new SPIContentInfo(['alwaysAvailable' => false]);  | 
            ||
| 537 | $contentHandler  | 
            ||
| 538 | ->expects($this->once())  | 
            ||
| 539 |                 ->method('loadContentInfo') | 
            ||
| 540 | ->with($id)  | 
            ||
| 541 | ->will($this->returnValue($spiContentInfo));  | 
            ||
| 542 | }  | 
            ||
| 543 | |||
| 544 | $spiContent = new SPIContent([  | 
            ||
| 545 | 'versionInfo' => new VersionInfo([  | 
            ||
| 546 | 'contentInfo' => new ContentInfo(['id' => 42, 'contentTypeId' => 123]),  | 
            ||
| 547 | ]),  | 
            ||
| 548 | ]);  | 
            ||
| 549 | $contentHandler  | 
            ||
| 550 | ->expects($this->once())  | 
            ||
| 551 |             ->method('load') | 
            ||
| 552 | ->with($realId, $versionNo, $languages)  | 
            ||
| 553 | ->willReturn($spiContent);  | 
            ||
| 554 | |||
| 555 | $content = $this->mockBuildContentDomainObject($spiContent, $languages);  | 
            ||
| 556 | |||
| 557 | $this->assertSame(  | 
            ||
| 558 | $content,  | 
            ||
| 559 | $contentService->internalLoadContent($id, $languages, $versionNo, $isRemoteId, $useAlwaysAvailable)  | 
            ||
| 560 | );  | 
            ||
| 561 | }  | 
            ||
| 562 | |||
| 563 | public function internalLoadContentProvider()  | 
            ||
| 564 |     { | 
            ||
| 565 | return [  | 
            ||
| 566 | [123, null, null, false, false],  | 
            ||
| 567 | [123, null, 456, false, false],  | 
            ||
| 568 | [456, null, 123, false, true],  | 
            ||
| 569 | [456, null, 2, false, false],  | 
            ||
| 570 | [456, ['eng-GB'], 2, false, true],  | 
            ||
| 571 | [456, ['eng-GB', 'fre-FR'], null, false, false],  | 
            ||
| 572 | [456, ['eng-GB', 'fre-FR', 'nor-NO'], 2, false, false],  | 
            ||
| 573 | // With remoteId  | 
            ||
| 574 | [123, null, null, true, false],  | 
            ||
| 575 | ['someRemoteId', null, 456, true, false],  | 
            ||
| 576 | [456, null, 123, true, false],  | 
            ||
| 577 | ['someRemoteId', null, 2, true, false],  | 
            ||
| 578 | ['someRemoteId', ['eng-GB'], 2, true, false],  | 
            ||
| 579 | [456, ['eng-GB', 'fre-FR'], null, true, false],  | 
            ||
| 580 | ['someRemoteId', ['eng-GB', 'fre-FR', 'nor-NO'], 2, true, false],  | 
            ||
| 581 | ];  | 
            ||
| 582 | }  | 
            ||
| 583 | |||
| 584 | public function testInternalLoadContentNotFound()  | 
            ||
| 585 |     { | 
            ||
| 586 | $this->expectException(\eZ\Publish\Core\Base\Exceptions\NotFoundException::class);  | 
            ||
| 587 | |||
| 588 | $contentService = $this->getPartlyMockedContentService();  | 
            ||
| 589 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */  | 
            ||
| 590 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 591 | $id = 123;  | 
            ||
| 592 | $versionNo = 7;  | 
            ||
| 593 | $languages = null;  | 
            ||
| 594 | $contentHandler  | 
            ||
| 595 | ->expects($this->once())  | 
            ||
| 596 |             ->method('load') | 
            ||
| 597 | ->with($id, $versionNo, $languages)  | 
            ||
| 598 | ->will(  | 
            ||
| 599 | $this->throwException(  | 
            ||
| 600 | $this->createMock(APINotFoundException::class)  | 
            ||
| 601 | )  | 
            ||
| 602 | );  | 
            ||
| 603 | |||
| 604 | $contentService->internalLoadContent($id, $languages, $versionNo);  | 
            ||
| 605 | }  | 
            ||
| 606 | |||
| 607 | /**  | 
            ||
| 608 | * Test for the loadContentByContentInfo() method.  | 
            ||
| 609 | *  | 
            ||
| 610 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByContentInfo  | 
            ||
| 611 | */  | 
            ||
| 612 | public function testLoadContentByContentInfo()  | 
            ||
| 613 |     { | 
            ||
| 614 | $contentServiceMock = $this->getPartlyMockedContentService(  | 
            ||
| 615 | ['loadContent']  | 
            ||
| 616 | );  | 
            ||
| 617 | $contentServiceMock->expects(  | 
            ||
| 618 | $this->once()  | 
            ||
| 619 | )->method(  | 
            ||
| 620 | 'loadContent'  | 
            ||
| 621 | )->with(  | 
            ||
| 622 | $this->equalTo(42),  | 
            ||
| 623 | $this->equalTo(['cro-HR']),  | 
            ||
| 624 | $this->equalTo(7),  | 
            ||
| 625 | $this->equalTo(false)  | 
            ||
| 626 | )->will(  | 
            ||
| 627 |             $this->returnValue('result') | 
            ||
| 628 | );  | 
            ||
| 629 | |||
| 630 | $result = $contentServiceMock->loadContentByContentInfo(  | 
            ||
| 631 | new ContentInfo(['id' => 42]),  | 
            ||
| 632 | ['cro-HR'],  | 
            ||
| 633 | 7  | 
            ||
| 634 | );  | 
            ||
| 635 | |||
| 636 |         $this->assertEquals('result', $result); | 
            ||
| 637 | }  | 
            ||
| 638 | |||
| 639 | /**  | 
            ||
| 640 | * Test for the loadContentByVersionInfo() method.  | 
            ||
| 641 | *  | 
            ||
| 642 | * @covers \eZ\Publish\Core\Repository\ContentService::loadContentByVersionInfo  | 
            ||
| 643 | */  | 
            ||
| 644 | public function testLoadContentByVersionInfo()  | 
            ||
| 645 |     { | 
            ||
| 646 | $contentServiceMock = $this->getPartlyMockedContentService(  | 
            ||
| 647 | ['loadContent']  | 
            ||
| 648 | );  | 
            ||
| 649 | $contentServiceMock->expects(  | 
            ||
| 650 | $this->once()  | 
            ||
| 651 | )->method(  | 
            ||
| 652 | 'loadContent'  | 
            ||
| 653 | )->with(  | 
            ||
| 654 | $this->equalTo(42),  | 
            ||
| 655 | $this->equalTo(['cro-HR']),  | 
            ||
| 656 | $this->equalTo(7),  | 
            ||
| 657 | $this->equalTo(false)  | 
            ||
| 658 | )->will(  | 
            ||
| 659 |             $this->returnValue('result') | 
            ||
| 660 | );  | 
            ||
| 661 | |||
| 662 | $result = $contentServiceMock->loadContentByVersionInfo(  | 
            ||
| 663 | new VersionInfo(  | 
            ||
| 664 | [  | 
            ||
| 665 | 'contentInfo' => new ContentInfo(['id' => 42]),  | 
            ||
| 666 | 'versionNo' => 7,  | 
            ||
| 667 | ]  | 
            ||
| 668 | ),  | 
            ||
| 669 | ['cro-HR']  | 
            ||
| 670 | );  | 
            ||
| 671 | |||
| 672 |         $this->assertEquals('result', $result); | 
            ||
| 673 | }  | 
            ||
| 674 | |||
| 675 | /**  | 
            ||
| 676 | * Test for the deleteContent() method.  | 
            ||
| 677 | *  | 
            ||
| 678 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteContent  | 
            ||
| 679 | */  | 
            ||
| 680 | public function testDeleteContentThrowsUnauthorizedException()  | 
            ||
| 681 |     { | 
            ||
| 682 | $this->expectException(\eZ\Publish\Core\Base\Exceptions\UnauthorizedException::class);  | 
            ||
| 683 | |||
| 684 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 685 | $contentService = $this->getPartlyMockedContentService(['internalLoadContentInfo']);  | 
            ||
| 686 | $contentInfo = $this->createMock(APIContentInfo::class);  | 
            ||
| 687 | |||
| 688 | $contentInfo->expects($this->any())  | 
            ||
| 689 |             ->method('__get') | 
            ||
| 690 |             ->with('id') | 
            ||
| 691 | ->will($this->returnValue(42));  | 
            ||
| 692 | |||
| 693 | $contentService->expects($this->once())  | 
            ||
| 694 |             ->method('internalLoadContentInfo') | 
            ||
| 695 | ->with(42)  | 
            ||
| 696 | ->will($this->returnValue($contentInfo));  | 
            ||
| 697 | |||
| 698 | $permissionResolver->expects($this->once())  | 
            ||
| 699 |             ->method('canUser') | 
            ||
| 700 |             ->with('content', 'remove') | 
            ||
| 701 | ->will($this->returnValue(false));  | 
            ||
| 702 | |||
| 703 | /* @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */  | 
            ||
| 704 | $contentService->deleteContent($contentInfo);  | 
            ||
| 705 | }  | 
            ||
| 706 | |||
| 707 | /**  | 
            ||
| 708 | * Test for the deleteContent() method.  | 
            ||
| 709 | *  | 
            ||
| 710 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteContent  | 
            ||
| 711 | */  | 
            ||
| 712 | public function testDeleteContent()  | 
            ||
| 713 |     { | 
            ||
| 714 | $repository = $this->getRepositoryMock();  | 
            ||
| 715 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 716 | |||
| 717 | $permissionResolver->expects($this->once())  | 
            ||
| 718 |             ->method('canUser') | 
            ||
| 719 |             ->with('content', 'remove') | 
            ||
| 720 | ->will($this->returnValue(true));  | 
            ||
| 721 | |||
| 722 | $contentService = $this->getPartlyMockedContentService(['internalLoadContentInfo']);  | 
            ||
| 723 | /** @var \PHPUnit\Framework\MockObject\MockObject $urlAliasHandler */  | 
            ||
| 724 | $urlAliasHandler = $this->getPersistenceMock()->urlAliasHandler();  | 
            ||
| 725 | /** @var \PHPUnit\Framework\MockObject\MockObject $locationHandler */  | 
            ||
| 726 | $locationHandler = $this->getPersistenceMock()->locationHandler();  | 
            ||
| 727 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */  | 
            ||
| 728 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 729 | |||
| 730 | $contentInfo = $this->createMock(APIContentInfo::class);  | 
            ||
| 731 | |||
| 732 | $contentService->expects($this->once())  | 
            ||
| 733 |             ->method('internalLoadContentInfo') | 
            ||
| 734 | ->with(42)  | 
            ||
| 735 | ->will($this->returnValue($contentInfo));  | 
            ||
| 736 | |||
| 737 | $contentInfo->expects($this->any())  | 
            ||
| 738 |             ->method('__get') | 
            ||
| 739 |             ->with('id') | 
            ||
| 740 | ->will($this->returnValue(42));  | 
            ||
| 741 | |||
| 742 |         $repository->expects($this->once())->method('beginTransaction'); | 
            ||
| 743 | |||
| 744 | $spiLocations = [  | 
            ||
| 745 | new SPILocation(['id' => 1]),  | 
            ||
| 746 | new SPILocation(['id' => 2]),  | 
            ||
| 747 | ];  | 
            ||
| 748 | $locationHandler->expects($this->once())  | 
            ||
| 749 |             ->method('loadLocationsByContent') | 
            ||
| 750 | ->with(42)  | 
            ||
| 751 | ->will($this->returnValue($spiLocations));  | 
            ||
| 752 | |||
| 753 | $contentHandler->expects($this->once())  | 
            ||
| 754 |             ->method('deleteContent') | 
            ||
| 755 | ->with(42);  | 
            ||
| 756 | |||
| 757 |         foreach ($spiLocations as $index => $spiLocation) { | 
            ||
| 758 | $urlAliasHandler->expects($this->at($index))  | 
            ||
| 759 |                 ->method('locationDeleted') | 
            ||
| 760 | ->with($spiLocation->id);  | 
            ||
| 761 | }  | 
            ||
| 762 | |||
| 763 |         $repository->expects($this->once())->method('commit'); | 
            ||
| 764 | |||
| 765 | /* @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */  | 
            ||
| 766 | $contentService->deleteContent($contentInfo);  | 
            ||
| 767 | }  | 
            ||
| 768 | |||
| 769 | /**  | 
            ||
| 770 | * Test for the deleteContent() method.  | 
            ||
| 771 | *  | 
            ||
| 772 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteContent  | 
            ||
| 773 | */  | 
            ||
| 774 | public function testDeleteContentWithRollback()  | 
            ||
| 775 |     { | 
            ||
| 776 | $this->expectException(\Exception::class);  | 
            ||
| 777 | |||
| 778 | $repository = $this->getRepositoryMock();  | 
            ||
| 779 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 780 | |||
| 781 | $permissionResolver->expects($this->once())  | 
            ||
| 782 |             ->method('canUser') | 
            ||
| 783 |             ->with('content', 'remove') | 
            ||
| 784 | ->will($this->returnValue(true));  | 
            ||
| 785 | |||
| 786 | $contentService = $this->getPartlyMockedContentService(['internalLoadContentInfo']);  | 
            ||
| 787 | /** @var \PHPUnit\Framework\MockObject\MockObject $locationHandler */  | 
            ||
| 788 | $locationHandler = $this->getPersistenceMock()->locationHandler();  | 
            ||
| 789 | |||
| 790 | $contentInfo = $this->createMock(APIContentInfo::class);  | 
            ||
| 791 | |||
| 792 | $contentService->expects($this->once())  | 
            ||
| 793 |             ->method('internalLoadContentInfo') | 
            ||
| 794 | ->with(42)  | 
            ||
| 795 | ->will($this->returnValue($contentInfo));  | 
            ||
| 796 | |||
| 797 | $contentInfo->expects($this->any())  | 
            ||
| 798 |             ->method('__get') | 
            ||
| 799 |             ->with('id') | 
            ||
| 800 | ->will($this->returnValue(42));  | 
            ||
| 801 | |||
| 802 |         $repository->expects($this->once())->method('beginTransaction'); | 
            ||
| 803 | |||
| 804 | $locationHandler->expects($this->once())  | 
            ||
| 805 |             ->method('loadLocationsByContent') | 
            ||
| 806 | ->with(42)  | 
            ||
| 807 | ->will($this->throwException(new \Exception()));  | 
            ||
| 808 | |||
| 809 |         $repository->expects($this->once())->method('rollback'); | 
            ||
| 810 | |||
| 811 | /* @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */  | 
            ||
| 812 | $contentService->deleteContent($contentInfo);  | 
            ||
| 813 | }  | 
            ||
| 814 | |||
| 815 | /**  | 
            ||
| 816 | * Test for the deleteVersion() method.  | 
            ||
| 817 | *  | 
            ||
| 818 | * @covers \eZ\Publish\Core\Repository\ContentService::deleteVersion  | 
            ||
| 819 | */  | 
            ||
| 820 | public function testDeleteVersionThrowsBadStateExceptionLastVersion()  | 
            ||
| 821 |     { | 
            ||
| 822 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\BadStateException::class);  | 
            ||
| 823 | |||
| 824 | $repository = $this->getRepositoryMock();  | 
            ||
| 825 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 826 | |||
| 827 | $permissionResolver  | 
            ||
| 828 | ->expects($this->once())  | 
            ||
| 829 |             ->method('canUser') | 
            ||
| 830 |             ->with('content', 'versionremove') | 
            ||
| 831 | ->will($this->returnValue(true));  | 
            ||
| 832 | $repository  | 
            ||
| 833 | ->expects($this->never())  | 
            ||
| 834 |             ->method('beginTransaction'); | 
            ||
| 835 | |||
| 836 | $contentService = $this->getPartlyMockedContentService();  | 
            ||
| 837 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandler */  | 
            ||
| 838 | $contentHandler = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 839 | $contentInfo = $this->createMock(APIContentInfo::class);  | 
            ||
| 840 | $versionInfo = $this->createMock(APIVersionInfo::class);  | 
            ||
| 841 | |||
| 842 | $contentInfo  | 
            ||
| 843 | ->expects($this->any())  | 
            ||
| 844 |             ->method('__get') | 
            ||
| 845 |             ->with('id') | 
            ||
| 846 | ->will($this->returnValue(42));  | 
            ||
| 847 | |||
| 848 | $versionInfo  | 
            ||
| 849 | ->expects($this->any())  | 
            ||
| 850 |             ->method('__get') | 
            ||
| 851 | ->will(  | 
            ||
| 852 | $this->returnValueMap(  | 
            ||
| 853 | [  | 
            ||
| 854 | ['versionNo', 123],  | 
            ||
| 855 | ['contentInfo', $contentInfo],  | 
            ||
| 856 | ]  | 
            ||
| 857 | )  | 
            ||
| 858 | );  | 
            ||
| 859 | $versionInfo  | 
            ||
| 860 | ->expects($this->once())  | 
            ||
| 861 |             ->method('isPublished') | 
            ||
| 862 | ->willReturn(false);  | 
            ||
| 863 | |||
| 864 | $contentHandler  | 
            ||
| 865 | ->expects($this->once())  | 
            ||
| 866 |             ->method('listVersions') | 
            ||
| 867 | ->with(42)  | 
            ||
| 868 | ->will($this->returnValue(['version']));  | 
            ||
| 869 | |||
| 870 | /* @var \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo */  | 
            ||
| 871 | $contentService->deleteVersion($versionInfo);  | 
            ||
| 872 | }  | 
            ||
| 873 | |||
| 874 | /**  | 
            ||
| 875 | * Test for the createContent() method.  | 
            ||
| 876 | *  | 
            ||
| 877 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 878 | */  | 
            ||
| 879 | View Code Duplication | public function testCreateContentThrowsInvalidArgumentExceptionMainLanguageCodeNotSet()  | 
            |
| 880 |     { | 
            ||
| 881 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);  | 
            ||
| 882 |         $this->expectExceptionMessage('Argument \'$contentCreateStruct\' is invalid: \'mainLanguageCode\' property must be set'); | 
            ||
| 883 | |||
| 884 | $mockedService = $this->getPartlyMockedContentService();  | 
            ||
| 885 | $mockedService->createContent(new ContentCreateStruct(), []);  | 
            ||
| 886 | }  | 
            ||
| 887 | |||
| 888 | /**  | 
            ||
| 889 | * Test for the createContent() method.  | 
            ||
| 890 | *  | 
            ||
| 891 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 892 | */  | 
            ||
| 893 | View Code Duplication | public function testCreateContentThrowsInvalidArgumentExceptionContentTypeNotSet()  | 
            |
| 894 |     { | 
            ||
| 895 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);  | 
            ||
| 896 |         $this->expectExceptionMessage('Argument \'$contentCreateStruct\' is invalid: \'contentType\' property must be set'); | 
            ||
| 897 | |||
| 898 | $mockedService = $this->getPartlyMockedContentService();  | 
            ||
| 899 | $mockedService->createContent(  | 
            ||
| 900 | new ContentCreateStruct(['mainLanguageCode' => 'eng-US']),  | 
            ||
| 901 | []  | 
            ||
| 902 | );  | 
            ||
| 903 | }  | 
            ||
| 904 | |||
| 905 | /**  | 
            ||
| 906 | * Test for the createContent() method.  | 
            ||
| 907 | *  | 
            ||
| 908 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 909 | */  | 
            ||
| 910 | public function testCreateContentThrowsUnauthorizedException()  | 
            ||
| 911 |     { | 
            ||
| 912 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class);  | 
            ||
| 913 | |||
| 914 | $repositoryMock = $this->getRepositoryMock();  | 
            ||
| 915 | |||
| 916 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 917 | $permissionResolver->expects($this->once())  | 
            ||
| 918 |             ->method('getCurrentUserReference') | 
            ||
| 919 | ->will($this->returnValue(new UserReference(169)));  | 
            ||
| 920 | |||
| 921 | $mockedService = $this->getPartlyMockedContentService();  | 
            ||
| 922 | $contentTypeServiceMock = $this->getContentTypeServiceMock();  | 
            ||
| 923 | $contentType = new ContentType(  | 
            ||
| 924 | [  | 
            ||
| 925 | 'id' => 123,  | 
            ||
| 926 | 'fieldDefinitions' => [],  | 
            ||
| 927 | ]  | 
            ||
| 928 | );  | 
            ||
| 929 | $contentCreateStruct = new ContentCreateStruct(  | 
            ||
| 930 | [  | 
            ||
| 931 | 'ownerId' => 169,  | 
            ||
| 932 | 'alwaysAvailable' => false,  | 
            ||
| 933 | 'mainLanguageCode' => 'eng-US',  | 
            ||
| 934 | 'contentType' => $contentType,  | 
            ||
| 935 | ]  | 
            ||
| 936 | );  | 
            ||
| 937 | |||
| 938 | $contentTypeServiceMock->expects($this->once())  | 
            ||
| 939 |             ->method('loadContentType') | 
            ||
| 940 | ->with($this->equalTo(123))  | 
            ||
| 941 | ->will($this->returnValue($contentType));  | 
            ||
| 942 | |||
| 943 | $repositoryMock->expects($this->once())  | 
            ||
| 944 |             ->method('getContentTypeService') | 
            ||
| 945 | ->will($this->returnValue($contentTypeServiceMock));  | 
            ||
| 946 | |||
| 947 | $permissionResolver->expects($this->once())  | 
            ||
| 948 |             ->method('canUser') | 
            ||
| 949 | ->with(  | 
            ||
| 950 |                 $this->equalTo('content'), | 
            ||
| 951 |                 $this->equalTo('create'), | 
            ||
| 952 | $this->isInstanceOf(get_class($contentCreateStruct)),  | 
            ||
| 953 | $this->equalTo([])  | 
            ||
| 954 | )->will($this->returnValue(false));  | 
            ||
| 955 | |||
| 956 | $mockedService->createContent(  | 
            ||
| 957 | new ContentCreateStruct(  | 
            ||
| 958 | [  | 
            ||
| 959 | 'mainLanguageCode' => 'eng-US',  | 
            ||
| 960 | 'contentType' => $contentType,  | 
            ||
| 961 | ]  | 
            ||
| 962 | ),  | 
            ||
| 963 | []  | 
            ||
| 964 | );  | 
            ||
| 965 | }  | 
            ||
| 966 | |||
| 967 | /**  | 
            ||
| 968 | * Test for the createContent() method.  | 
            ||
| 969 | *  | 
            ||
| 970 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 971 | * @exceptionMessage Argument '$contentCreateStruct' is invalid: Another content with remoteId 'faraday' exists  | 
            ||
| 972 | */  | 
            ||
| 973 | public function testCreateContentThrowsInvalidArgumentExceptionDuplicateRemoteId()  | 
            ||
| 974 |     { | 
            ||
| 975 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class);  | 
            ||
| 976 | |||
| 977 | $repositoryMock = $this->getRepositoryMock();  | 
            ||
| 978 | $permissionResolverMock = $this->getPermissionResolverMock();  | 
            ||
| 979 | $permissionResolverMock  | 
            ||
| 980 | ->expects($this->once())  | 
            ||
| 981 |             ->method('getCurrentUserReference') | 
            ||
| 982 | ->willReturn($this->createMock(UserReference::class));  | 
            ||
| 983 | |||
| 984 | $mockedService = $this->getPartlyMockedContentService(['loadContentByRemoteId']);  | 
            ||
| 985 | $contentTypeServiceMock = $this->getContentTypeServiceMock();  | 
            ||
| 986 | $contentType = new ContentType(  | 
            ||
| 987 | [  | 
            ||
| 988 | 'id' => 123,  | 
            ||
| 989 | 'fieldDefinitions' => [],  | 
            ||
| 990 | ]  | 
            ||
| 991 | );  | 
            ||
| 992 | $contentCreateStruct = new ContentCreateStruct(  | 
            ||
| 993 | [  | 
            ||
| 994 | 'ownerId' => 169,  | 
            ||
| 995 | 'alwaysAvailable' => false,  | 
            ||
| 996 | 'remoteId' => 'faraday',  | 
            ||
| 997 | 'mainLanguageCode' => 'eng-US',  | 
            ||
| 998 | 'contentType' => $contentType,  | 
            ||
| 999 | ]  | 
            ||
| 1000 | );  | 
            ||
| 1001 | |||
| 1002 | $contentTypeServiceMock->expects($this->once())  | 
            ||
| 1003 |             ->method('loadContentType') | 
            ||
| 1004 | ->with($this->equalTo(123))  | 
            ||
| 1005 | ->will($this->returnValue($contentType));  | 
            ||
| 1006 | |||
| 1007 | $repositoryMock->expects($this->once())  | 
            ||
| 1008 |             ->method('getContentTypeService') | 
            ||
| 1009 | ->will($this->returnValue($contentTypeServiceMock));  | 
            ||
| 1010 | |||
| 1011 | $permissionResolverMock->expects($this->once())  | 
            ||
| 1012 |             ->method('canUser') | 
            ||
| 1013 | ->with(  | 
            ||
| 1014 |                 $this->equalTo('content'), | 
            ||
| 1015 |                 $this->equalTo('create'), | 
            ||
| 1016 | $this->isInstanceOf(get_class($contentCreateStruct)),  | 
            ||
| 1017 | $this->equalTo([])  | 
            ||
| 1018 | )->will($this->returnValue(true));  | 
            ||
| 1019 | |||
| 1020 | $mockedService->expects($this->once())  | 
            ||
| 1021 |             ->method('loadContentByRemoteId') | 
            ||
| 1022 | ->with($contentCreateStruct->remoteId)  | 
            ||
| 1023 |             ->will($this->returnValue('Hello...')); | 
            ||
| 1024 | |||
| 1025 | $mockedService->createContent(  | 
            ||
| 1026 | new ContentCreateStruct(  | 
            ||
| 1027 | [  | 
            ||
| 1028 | 'remoteId' => 'faraday',  | 
            ||
| 1029 | 'mainLanguageCode' => 'eng-US',  | 
            ||
| 1030 | 'contentType' => $contentType,  | 
            ||
| 1031 | ]  | 
            ||
| 1032 | ),  | 
            ||
| 1033 | []  | 
            ||
| 1034 | );  | 
            ||
| 1035 | }  | 
            ||
| 1036 | |||
| 1037 | /**  | 
            ||
| 1038 | * @param string $mainLanguageCode  | 
            ||
| 1039 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 1040 | * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions  | 
            ||
| 1041 | *  | 
            ||
| 1042 | * @return array  | 
            ||
| 1043 | */  | 
            ||
| 1044 | protected function mapStructFieldsForCreate($mainLanguageCode, $structFields, $fieldDefinitions)  | 
            ||
| 1045 |     { | 
            ||
| 1046 | $mappedFieldDefinitions = [];  | 
            ||
| 1047 |         foreach ($fieldDefinitions as $fieldDefinition) { | 
            ||
| 1048 | $mappedFieldDefinitions[$fieldDefinition->identifier] = $fieldDefinition;  | 
            ||
| 1049 | }  | 
            ||
| 1050 | |||
| 1051 | $mappedStructFields = [];  | 
            ||
| 1052 |         foreach ($structFields as $structField) { | 
            ||
| 1053 |             if ($structField->languageCode === null) { | 
            ||
| 1054 | $languageCode = $mainLanguageCode;  | 
            ||
| 1055 |             } else { | 
            ||
| 1056 | $languageCode = $structField->languageCode;  | 
            ||
| 1057 | }  | 
            ||
| 1058 | |||
| 1059 | $mappedStructFields[$structField->fieldDefIdentifier][$languageCode] = (string)$structField->value;  | 
            ||
| 1060 | }  | 
            ||
| 1061 | |||
| 1062 | return $mappedStructFields;  | 
            ||
| 1063 | }  | 
            ||
| 1064 | |||
| 1065 | /**  | 
            ||
| 1066 | * Returns full, possibly redundant array of field values, indexed by field definition  | 
            ||
| 1067 | * identifier and language code.  | 
            ||
| 1068 | *  | 
            ||
| 1069 | * @throws \RuntimeException Method is intended to be used only with consistent fixtures  | 
            ||
| 1070 | *  | 
            ||
| 1071 | * @param string $mainLanguageCode  | 
            ||
| 1072 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 1073 | * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions  | 
            ||
| 1074 | * @param array $languageCodes  | 
            ||
| 1075 | *  | 
            ||
| 1076 | * @return array  | 
            ||
| 1077 | */  | 
            ||
| 1078 | protected function determineValuesForCreate(  | 
            ||
| 1079 | $mainLanguageCode,  | 
            ||
| 1080 | array $structFields,  | 
            ||
| 1081 | array $fieldDefinitions,  | 
            ||
| 1082 | array $languageCodes  | 
            ||
| 1083 |     ) { | 
            ||
| 1084 | $mappedStructFields = $this->mapStructFieldsForCreate(  | 
            ||
| 1085 | $mainLanguageCode,  | 
            ||
| 1086 | $structFields,  | 
            ||
| 1087 | $fieldDefinitions  | 
            ||
| 1088 | );  | 
            ||
| 1089 | |||
| 1090 | $values = [];  | 
            ||
| 1091 | |||
| 1092 |         foreach ($fieldDefinitions as $fieldDefinition) { | 
            ||
| 1093 | $identifier = $fieldDefinition->identifier;  | 
            ||
| 1094 |             foreach ($languageCodes as $languageCode) { | 
            ||
| 1095 | View Code Duplication |                 if (!$fieldDefinition->isTranslatable) { | 
            |
| 1096 |                     if (isset($mappedStructFields[$identifier][$mainLanguageCode])) { | 
            ||
| 1097 | $values[$identifier][$languageCode] = $mappedStructFields[$identifier][$mainLanguageCode];  | 
            ||
| 1098 |                     } else { | 
            ||
| 1099 | $values[$identifier][$languageCode] = (string)$fieldDefinition->defaultValue;  | 
            ||
| 1100 | }  | 
            ||
| 1101 | continue;  | 
            ||
| 1102 | }  | 
            ||
| 1103 | |||
| 1104 | View Code Duplication |                 if (isset($mappedStructFields[$identifier][$languageCode])) { | 
            |
| 1105 | $values[$identifier][$languageCode] = $mappedStructFields[$identifier][$languageCode];  | 
            ||
| 1106 | continue;  | 
            ||
| 1107 | }  | 
            ||
| 1108 | |||
| 1109 | $values[$identifier][$languageCode] = (string)$fieldDefinition->defaultValue;  | 
            ||
| 1110 | }  | 
            ||
| 1111 | }  | 
            ||
| 1112 | |||
| 1113 | return $this->stubValues($values);  | 
            ||
| 1114 | }  | 
            ||
| 1115 | |||
| 1116 | /**  | 
            ||
| 1117 | * @param string $mainLanguageCode  | 
            ||
| 1118 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 1119 | *  | 
            ||
| 1120 | * @return string[]  | 
            ||
| 1121 | */  | 
            ||
| 1122 | protected function determineLanguageCodesForCreate($mainLanguageCode, array $structFields)  | 
            ||
| 1123 |     { | 
            ||
| 1124 | $languageCodes = [];  | 
            ||
| 1125 | |||
| 1126 |         foreach ($structFields as $field) { | 
            ||
| 1127 |             if ($field->languageCode === null || isset($languageCodes[$field->languageCode])) { | 
            ||
| 1128 | continue;  | 
            ||
| 1129 | }  | 
            ||
| 1130 | |||
| 1131 | $languageCodes[$field->languageCode] = true;  | 
            ||
| 1132 | }  | 
            ||
| 1133 | |||
| 1134 | $languageCodes[$mainLanguageCode] = true;  | 
            ||
| 1135 | |||
| 1136 | return array_keys($languageCodes);  | 
            ||
| 1137 | }  | 
            ||
| 1138 | |||
| 1139 | /**  | 
            ||
| 1140 | * Asserts that calling createContent() with given API field set causes calling  | 
            ||
| 1141 | * Handler::createContent() with given SPI field set.  | 
            ||
| 1142 | *  | 
            ||
| 1143 | * @param string $mainLanguageCode  | 
            ||
| 1144 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 1145 | * @param \eZ\Publish\SPI\Persistence\Content\Field[] $spiFields  | 
            ||
| 1146 | * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions  | 
            ||
| 1147 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs  | 
            ||
| 1148 | * @param \eZ\Publish\SPI\Persistence\Content\ObjectState\Group[] $objectStateGroups  | 
            ||
| 1149 | * @param bool $execute  | 
            ||
| 1150 | *  | 
            ||
| 1151 | * @return mixed  | 
            ||
| 1152 | */  | 
            ||
| 1153 | protected function assertForTestCreateContentNonRedundantFieldSet(  | 
            ||
| 1154 | $mainLanguageCode,  | 
            ||
| 1155 | array $structFields,  | 
            ||
| 1156 | array $spiFields,  | 
            ||
| 1157 | array $fieldDefinitions,  | 
            ||
| 1158 | array $locationCreateStructs = [],  | 
            ||
| 1159 | $withObjectStates = false,  | 
            ||
| 1160 | $execute = true  | 
            ||
| 1161 |     ) { | 
            ||
| 1162 | $repositoryMock = $this->getRepositoryMock();  | 
            ||
| 1163 | $mockedService = $this->getPartlyMockedContentService();  | 
            ||
| 1164 | /** @var \PHPUnit\Framework\MockObject\MockObject $contentHandlerMock */  | 
            ||
| 1165 | $contentHandlerMock = $this->getPersistenceMock()->contentHandler();  | 
            ||
| 1166 | /** @var \PHPUnit\Framework\MockObject\MockObject $languageHandlerMock */  | 
            ||
| 1167 | $languageHandlerMock = $this->getPersistenceMock()->contentLanguageHandler();  | 
            ||
| 1168 | /** @var \PHPUnit\Framework\MockObject\MockObject $objectStateHandlerMock */  | 
            ||
| 1169 | $objectStateHandlerMock = $this->getPersistenceMock()->objectStateHandler();  | 
            ||
| 1170 | $contentTypeServiceMock = $this->getContentTypeServiceMock();  | 
            ||
| 1171 | $fieldTypeServiceMock = $this->getFieldTypeServiceMock();  | 
            ||
| 1172 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 1173 | $relationProcessorMock = $this->getRelationProcessorMock();  | 
            ||
| 1174 | $nameSchemaServiceMock = $this->getNameSchemaServiceMock();  | 
            ||
| 1175 | $permissionResolverMock = $this->getPermissionResolverMock();  | 
            ||
| 1176 | $fieldTypeMock = $this->createMock(SPIFieldType::class);  | 
            ||
| 1177 | $languageCodes = $this->determineLanguageCodesForCreate($mainLanguageCode, $structFields);  | 
            ||
| 1178 | $contentType = new ContentType(  | 
            ||
| 1179 | [  | 
            ||
| 1180 | 'id' => 123,  | 
            ||
| 1181 | 'fieldDefinitions' => $fieldDefinitions,  | 
            ||
| 1182 | 'nameSchema' => '<nameSchema>',  | 
            ||
| 1183 | ]  | 
            ||
| 1184 | );  | 
            ||
| 1185 | $contentCreateStruct = new ContentCreateStruct(  | 
            ||
| 1186 | [  | 
            ||
| 1187 | 'fields' => $structFields,  | 
            ||
| 1188 | 'mainLanguageCode' => $mainLanguageCode,  | 
            ||
| 1189 | 'contentType' => $contentType,  | 
            ||
| 1190 | 'alwaysAvailable' => false,  | 
            ||
| 1191 | 'ownerId' => 169,  | 
            ||
| 1192 | 'sectionId' => 1,  | 
            ||
| 1193 | ]  | 
            ||
| 1194 | );  | 
            ||
| 1195 | |||
| 1196 | $languageHandlerMock->expects($this->any())  | 
            ||
| 1197 |             ->method('loadByLanguageCode') | 
            ||
| 1198 |             ->with($this->isType('string')) | 
            ||
| 1199 | ->will(  | 
            ||
| 1200 | $this->returnCallback(  | 
            ||
| 1201 |                     function () { | 
            ||
| 1202 | return new Language(['id' => 4242]);  | 
            ||
| 1203 | }  | 
            ||
| 1204 | )  | 
            ||
| 1205 | );  | 
            ||
| 1206 | |||
| 1207 |         $repositoryMock->expects($this->once())->method('beginTransaction'); | 
            ||
| 1208 | |||
| 1209 | $contentTypeServiceMock->expects($this->once())  | 
            ||
| 1210 |             ->method('loadContentType') | 
            ||
| 1211 | ->with($this->equalTo($contentType->id))  | 
            ||
| 1212 | ->will($this->returnValue($contentType));  | 
            ||
| 1213 | |||
| 1214 | $repositoryMock->expects($this->once())  | 
            ||
| 1215 |             ->method('getContentTypeService') | 
            ||
| 1216 | ->will($this->returnValue($contentTypeServiceMock));  | 
            ||
| 1217 | |||
| 1218 | $that = $this;  | 
            ||
| 1219 | $permissionResolverMock->expects($this->once())  | 
            ||
| 1220 |             ->method('canUser') | 
            ||
| 1221 | ->with(  | 
            ||
| 1222 |                 $this->equalTo('content'), | 
            ||
| 1223 |                 $this->equalTo('create'), | 
            ||
| 1224 | $this->isInstanceOf(APIContentCreateStruct::class),  | 
            ||
| 1225 | $this->equalTo($locationCreateStructs)  | 
            ||
| 1226 | )->will(  | 
            ||
| 1227 | $this->returnCallback(  | 
            ||
| 1228 |                     function () use ($that, $contentCreateStruct) { | 
            ||
| 1229 | $that->assertEquals($contentCreateStruct, func_get_arg(2));  | 
            ||
| 1230 | |||
| 1231 | return true;  | 
            ||
| 1232 | }  | 
            ||
| 1233 | )  | 
            ||
| 1234 | );  | 
            ||
| 1235 | |||
| 1236 | $domainMapperMock->expects($this->once())  | 
            ||
| 1237 |             ->method('getUniqueHash') | 
            ||
| 1238 | ->with($this->isInstanceOf(APIContentCreateStruct::class))  | 
            ||
| 1239 | ->will(  | 
            ||
| 1240 | $this->returnCallback(  | 
            ||
| 1241 |                     function ($object) use ($that, $contentCreateStruct) { | 
            ||
| 1242 | $that->assertEquals($contentCreateStruct, $object);  | 
            ||
| 1243 | |||
| 1244 | return 'hash';  | 
            ||
| 1245 | }  | 
            ||
| 1246 | )  | 
            ||
| 1247 | );  | 
            ||
| 1248 | |||
| 1249 | $fieldTypeMock->expects($this->any())  | 
            ||
| 1250 |             ->method('acceptValue') | 
            ||
| 1251 | ->will(  | 
            ||
| 1252 | $this->returnCallback(  | 
            ||
| 1253 |                     function ($valueString) { | 
            ||
| 1254 | return new ValueStub($valueString);  | 
            ||
| 1255 | }  | 
            ||
| 1256 | )  | 
            ||
| 1257 | );  | 
            ||
| 1258 | |||
| 1259 | $fieldTypeMock->expects($this->any())  | 
            ||
| 1260 |             ->method('toPersistenceValue') | 
            ||
| 1261 | ->will(  | 
            ||
| 1262 | $this->returnCallback(  | 
            ||
| 1263 |                     function (ValueStub $value) { | 
            ||
| 1264 | return (string)$value;  | 
            ||
| 1265 | }  | 
            ||
| 1266 | )  | 
            ||
| 1267 | );  | 
            ||
| 1268 | |||
| 1269 | $emptyValue = self::EMPTY_FIELD_VALUE;  | 
            ||
| 1270 | $fieldTypeMock->expects($this->any())  | 
            ||
| 1271 |             ->method('isEmptyValue') | 
            ||
| 1272 | ->will(  | 
            ||
| 1273 | $this->returnCallback(  | 
            ||
| 1274 |                     function (ValueStub $value) use ($emptyValue) { | 
            ||
| 1275 | return $emptyValue === (string)$value;  | 
            ||
| 1276 | }  | 
            ||
| 1277 | )  | 
            ||
| 1278 | );  | 
            ||
| 1279 | |||
| 1280 | $fieldTypeMock->expects($this->any())  | 
            ||
| 1281 |             ->method('validate') | 
            ||
| 1282 | ->will($this->returnValue([]));  | 
            ||
| 1283 | |||
| 1284 | $this->getFieldTypeRegistryMock()->expects($this->any())  | 
            ||
| 1285 |             ->method('getFieldType') | 
            ||
| 1286 | ->will($this->returnValue($fieldTypeMock));  | 
            ||
| 1287 | |||
| 1288 | $relationProcessorMock  | 
            ||
| 1289 | ->expects($this->exactly(count($fieldDefinitions) * count($languageCodes)))  | 
            ||
| 1290 |             ->method('appendFieldRelations') | 
            ||
| 1291 | ->with(  | 
            ||
| 1292 |                 $this->isType('array'), | 
            ||
| 1293 |                 $this->isType('array'), | 
            ||
| 1294 | $this->isInstanceOf(SPIFieldType::class),  | 
            ||
| 1295 | $this->isInstanceOf(Value::class),  | 
            ||
| 1296 | $this->anything()  | 
            ||
| 1297 | );  | 
            ||
| 1298 | |||
| 1299 | $values = $this->determineValuesForCreate(  | 
            ||
| 1300 | $mainLanguageCode,  | 
            ||
| 1301 | $structFields,  | 
            ||
| 1302 | $fieldDefinitions,  | 
            ||
| 1303 | $languageCodes  | 
            ||
| 1304 | );  | 
            ||
| 1305 | $nameSchemaServiceMock->expects($this->once())  | 
            ||
| 1306 |             ->method('resolve') | 
            ||
| 1307 | ->with(  | 
            ||
| 1308 | $this->equalTo($contentType->nameSchema),  | 
            ||
| 1309 | $this->equalTo($contentType),  | 
            ||
| 1310 | $this->equalTo($values),  | 
            ||
| 1311 | $this->equalTo($languageCodes)  | 
            ||
| 1312 | )->will($this->returnValue([]));  | 
            ||
| 1313 | |||
| 1314 | $relationProcessorMock->expects($this->any())  | 
            ||
| 1315 |             ->method('processFieldRelations') | 
            ||
| 1316 | ->with(  | 
            ||
| 1317 |                 $this->isType('array'), | 
            ||
| 1318 | $this->equalTo(42),  | 
            ||
| 1319 |                 $this->isType('int'), | 
            ||
| 1320 | $this->equalTo($contentType),  | 
            ||
| 1321 | $this->equalTo([])  | 
            ||
| 1322 | );  | 
            ||
| 1323 | |||
| 1324 |         if (!$withObjectStates) { | 
            ||
| 1325 | $objectStateHandlerMock->expects($this->once())  | 
            ||
| 1326 |                 ->method('loadAllGroups') | 
            ||
| 1327 | ->will($this->returnValue([]));  | 
            ||
| 1328 | }  | 
            ||
| 1329 | |||
| 1330 |         if ($execute) { | 
            ||
| 1331 | $spiContentCreateStruct = new SPIContentCreateStruct(  | 
            ||
| 1332 | [  | 
            ||
| 1333 | 'name' => [],  | 
            ||
| 1334 | 'typeId' => 123,  | 
            ||
| 1335 | 'sectionId' => 1,  | 
            ||
| 1336 | 'ownerId' => 169,  | 
            ||
| 1337 | 'remoteId' => 'hash',  | 
            ||
| 1338 | 'fields' => $spiFields,  | 
            ||
| 1339 | 'modified' => time(),  | 
            ||
| 1340 | 'initialLanguageId' => 4242,  | 
            ||
| 1341 | ]  | 
            ||
| 1342 | );  | 
            ||
| 1343 | $spiContentCreateStruct2 = clone $spiContentCreateStruct;  | 
            ||
| 1344 | ++$spiContentCreateStruct2->modified;  | 
            ||
| 1345 | |||
| 1346 | $spiContent = new SPIContent(  | 
            ||
| 1347 | [  | 
            ||
| 1348 | 'versionInfo' => new SPIContent\VersionInfo(  | 
            ||
| 1349 | [  | 
            ||
| 1350 | 'contentInfo' => new SPIContent\ContentInfo(['id' => 42]),  | 
            ||
| 1351 | 'versionNo' => 7,  | 
            ||
| 1352 | ]  | 
            ||
| 1353 | ),  | 
            ||
| 1354 | ]  | 
            ||
| 1355 | );  | 
            ||
| 1356 | |||
| 1357 | $contentHandlerMock->expects($this->once())  | 
            ||
| 1358 |                 ->method('create') | 
            ||
| 1359 | ->with($this->logicalOr($spiContentCreateStruct, $spiContentCreateStruct2))  | 
            ||
| 1360 | ->will($this->returnValue($spiContent));  | 
            ||
| 1361 | |||
| 1362 |             $repositoryMock->expects($this->once())->method('commit'); | 
            ||
| 1363 | $domainMapperMock->expects($this->once())  | 
            ||
| 1364 |                 ->method('buildContentDomainObject') | 
            ||
| 1365 | ->with(  | 
            ||
| 1366 | $this->isInstanceOf(SPIContent::class),  | 
            ||
| 1367 | $this->equalTo($contentType)  | 
            ||
| 1368 | );  | 
            ||
| 1369 | |||
| 1370 | $mockedService->createContent($contentCreateStruct, []);  | 
            ||
| 1371 | }  | 
            ||
| 1372 | |||
| 1373 | return $contentCreateStruct;  | 
            ||
| 1374 | }  | 
            ||
| 1375 | |||
| 1376 | public function providerForTestCreateContentNonRedundantFieldSet1()  | 
            ||
| 1377 |     { | 
            ||
| 1378 | $spiFields = [  | 
            ||
| 1379 | new SPIField(  | 
            ||
| 1380 | [  | 
            ||
| 1381 | 'fieldDefinitionId' => 'fieldDefinitionId',  | 
            ||
| 1382 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 1383 | 'value' => 'newValue',  | 
            ||
| 1384 | 'languageCode' => 'eng-US',  | 
            ||
| 1385 | ]  | 
            ||
| 1386 | ),  | 
            ||
| 1387 | ];  | 
            ||
| 1388 | |||
| 1389 | return [  | 
            ||
| 1390 | // 0. Without language set  | 
            ||
| 1391 | [  | 
            ||
| 1392 | 'eng-US',  | 
            ||
| 1393 | [  | 
            ||
| 1394 | new Field(  | 
            ||
| 1395 | [  | 
            ||
| 1396 | 'fieldDefIdentifier' => 'identifier',  | 
            ||
| 1397 | 'value' => 'newValue',  | 
            ||
| 1398 | 'languageCode' => 'eng-US',  | 
            ||
| 1399 | ]  | 
            ||
| 1400 | ),  | 
            ||
| 1401 | ],  | 
            ||
| 1402 | $spiFields,  | 
            ||
| 1403 | ],  | 
            ||
| 1404 | // 1. Without language set  | 
            ||
| 1405 | [  | 
            ||
| 1406 | 'eng-US',  | 
            ||
| 1407 | [  | 
            ||
| 1408 | new Field(  | 
            ||
| 1409 | [  | 
            ||
| 1410 | 'fieldDefIdentifier' => 'identifier',  | 
            ||
| 1411 | 'value' => 'newValue',  | 
            ||
| 1412 | 'languageCode' => null,  | 
            ||
| 1413 | ]  | 
            ||
| 1414 | ),  | 
            ||
| 1415 | ],  | 
            ||
| 1416 | $spiFields,  | 
            ||
| 1417 | ],  | 
            ||
| 1418 | ];  | 
            ||
| 1419 | }  | 
            ||
| 1420 | |||
| 1421 | /**  | 
            ||
| 1422 | * Test for the createContent() method.  | 
            ||
| 1423 | *  | 
            ||
| 1424 | * Testing the simplest use case.  | 
            ||
| 1425 | *  | 
            ||
| 1426 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 1427 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 1428 | * @covers \eZ\Publish\Core\Repository\ContentService::cloneField  | 
            ||
| 1429 | * @covers \eZ\Publish\Core\Repository\ContentService::getDefaultObjectStates  | 
            ||
| 1430 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 1431 | * @dataProvider providerForTestCreateContentNonRedundantFieldSet1  | 
            ||
| 1432 | */  | 
            ||
| 1433 | public function testCreateContentNonRedundantFieldSet1($mainLanguageCode, $structFields, $spiFields)  | 
            ||
| 1434 |     { | 
            ||
| 1435 | $fieldDefinitions = [  | 
            ||
| 1436 | new FieldDefinition(  | 
            ||
| 1437 | [  | 
            ||
| 1438 | 'id' => 'fieldDefinitionId',  | 
            ||
| 1439 | 'fieldTypeIdentifier' => 'fieldTypeIdentifier',  | 
            ||
| 1440 | 'isTranslatable' => false,  | 
            ||
| 1441 | 'identifier' => 'identifier',  | 
            ||
| 1442 | 'isRequired' => false,  | 
            ||
| 1443 | 'defaultValue' => 'defaultValue',  | 
            ||
| 1444 | ]  | 
            ||
| 1445 | ),  | 
            ||
| 1446 | ];  | 
            ||
| 1447 | |||
| 1448 | $this->assertForTestCreateContentNonRedundantFieldSet(  | 
            ||
| 1449 | $mainLanguageCode,  | 
            ||
| 1450 | $structFields,  | 
            ||
| 1451 | $spiFields,  | 
            ||
| 1452 | $fieldDefinitions  | 
            ||
| 1453 | );  | 
            ||
| 1454 | }  | 
            ||
| 1455 | |||
| 1456 | public function providerForTestCreateContentNonRedundantFieldSet2()  | 
            ||
| 1457 |     { | 
            ||
| 1458 | $spiFields = [  | 
            ||
| 1459 | new SPIField(  | 
            ||
| 1460 | [  | 
            ||
| 1461 | 'fieldDefinitionId' => 'fieldDefinitionId1',  | 
            ||
| 1462 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 1463 | 'value' => 'newValue1',  | 
            ||
| 1464 | 'languageCode' => 'eng-US',  | 
            ||
| 1465 | ]  | 
            ||
| 1466 | ),  | 
            ||
| 1467 | new SPIField(  | 
            ||
| 1468 | [  | 
            ||
| 1469 | 'fieldDefinitionId' => 'fieldDefinitionId2',  | 
            ||
| 1470 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 1471 | 'value' => 'newValue2',  | 
            ||
| 1472 | 'languageCode' => 'ger-DE',  | 
            ||
| 1473 | ]  | 
            ||
| 1474 | ),  | 
            ||
| 1475 | ];  | 
            ||
| 1476 | |||
| 1477 | return [  | 
            ||
| 1478 | // 0. With language set  | 
            ||
| 1479 | [  | 
            ||
| 1480 | 'eng-US',  | 
            ||
| 1481 | [  | 
            ||
| 1482 | new Field(  | 
            ||
| 1483 | [  | 
            ||
| 1484 | 'fieldDefIdentifier' => 'identifier1',  | 
            ||
| 1485 | 'value' => 'newValue1',  | 
            ||
| 1486 | 'languageCode' => 'eng-US',  | 
            ||
| 1487 | ]  | 
            ||
| 1488 | ),  | 
            ||
| 1489 | new Field(  | 
            ||
| 1490 | [  | 
            ||
| 1491 | 'fieldDefIdentifier' => 'identifier2',  | 
            ||
| 1492 | 'value' => 'newValue2',  | 
            ||
| 1493 | 'languageCode' => 'ger-DE',  | 
            ||
| 1494 | ]  | 
            ||
| 1495 | ),  | 
            ||
| 1496 | ],  | 
            ||
| 1497 | $spiFields,  | 
            ||
| 1498 | ],  | 
            ||
| 1499 | // 1. Without language set  | 
            ||
| 1500 | [  | 
            ||
| 1501 | 'eng-US',  | 
            ||
| 1502 | [  | 
            ||
| 1503 | new Field(  | 
            ||
| 1504 | [  | 
            ||
| 1505 | 'fieldDefIdentifier' => 'identifier1',  | 
            ||
| 1506 | 'value' => 'newValue1',  | 
            ||
| 1507 | 'languageCode' => null,  | 
            ||
| 1508 | ]  | 
            ||
| 1509 | ),  | 
            ||
| 1510 | new Field(  | 
            ||
| 1511 | [  | 
            ||
| 1512 | 'fieldDefIdentifier' => 'identifier2',  | 
            ||
| 1513 | 'value' => 'newValue2',  | 
            ||
| 1514 | 'languageCode' => 'ger-DE',  | 
            ||
| 1515 | ]  | 
            ||
| 1516 | ),  | 
            ||
| 1517 | ],  | 
            ||
| 1518 | $spiFields,  | 
            ||
| 1519 | ],  | 
            ||
| 1520 | ];  | 
            ||
| 1521 | }  | 
            ||
| 1522 | |||
| 1523 | /**  | 
            ||
| 1524 | * Test for the createContent() method.  | 
            ||
| 1525 | *  | 
            ||
| 1526 | * Testing multiple languages with multiple translatable fields with empty default value.  | 
            ||
| 1527 | *  | 
            ||
| 1528 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 1529 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 1530 | * @covers \eZ\Publish\Core\Repository\ContentService::cloneField  | 
            ||
| 1531 | * @covers \eZ\Publish\Core\Repository\ContentService::getDefaultObjectStates  | 
            ||
| 1532 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 1533 | * @dataProvider providerForTestCreateContentNonRedundantFieldSet2  | 
            ||
| 1534 | */  | 
            ||
| 1535 | public function testCreateContentNonRedundantFieldSet2($mainLanguageCode, $structFields, $spiFields)  | 
            ||
| 1536 |     { | 
            ||
| 1537 | $fieldDefinitions = [  | 
            ||
| 1538 | new FieldDefinition(  | 
            ||
| 1539 | [  | 
            ||
| 1540 | 'id' => 'fieldDefinitionId1',  | 
            ||
| 1541 | 'fieldTypeIdentifier' => 'fieldTypeIdentifier',  | 
            ||
| 1542 | 'isTranslatable' => true,  | 
            ||
| 1543 | 'identifier' => 'identifier1',  | 
            ||
| 1544 | 'isRequired' => false,  | 
            ||
| 1545 | 'defaultValue' => self::EMPTY_FIELD_VALUE,  | 
            ||
| 1546 | ]  | 
            ||
| 1547 | ),  | 
            ||
| 1548 | new FieldDefinition(  | 
            ||
| 1549 | [  | 
            ||
| 1550 | 'id' => 'fieldDefinitionId2',  | 
            ||
| 1551 | 'fieldTypeIdentifier' => 'fieldTypeIdentifier',  | 
            ||
| 1552 | 'isTranslatable' => true,  | 
            ||
| 1553 | 'identifier' => 'identifier2',  | 
            ||
| 1554 | 'isRequired' => false,  | 
            ||
| 1555 | 'defaultValue' => self::EMPTY_FIELD_VALUE,  | 
            ||
| 1556 | ]  | 
            ||
| 1557 | ),  | 
            ||
| 1558 | ];  | 
            ||
| 1559 | |||
| 1560 | $this->assertForTestCreateContentNonRedundantFieldSet(  | 
            ||
| 1561 | $mainLanguageCode,  | 
            ||
| 1562 | $structFields,  | 
            ||
| 1563 | $spiFields,  | 
            ||
| 1564 | $fieldDefinitions  | 
            ||
| 1565 | );  | 
            ||
| 1566 | }  | 
            ||
| 1567 | |||
| 1568 | public function providerForTestCreateContentNonRedundantFieldSetComplex()  | 
            ||
| 1569 |     { | 
            ||
| 1570 | $spiFields0 = [  | 
            ||
| 1571 | new SPIField(  | 
            ||
| 1572 | [  | 
            ||
| 1573 | 'fieldDefinitionId' => 'fieldDefinitionId2',  | 
            ||
| 1574 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 1575 | 'value' => 'defaultValue2',  | 
            ||
| 1576 | 'languageCode' => 'eng-US',  | 
            ||
| 1577 | ]  | 
            ||
| 1578 | ),  | 
            ||
| 1579 | new SPIField(  | 
            ||
| 1580 | [  | 
            ||
| 1581 | 'fieldDefinitionId' => 'fieldDefinitionId4',  | 
            ||
| 1582 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 1583 | 'value' => 'defaultValue4',  | 
            ||
| 1584 | 'languageCode' => 'eng-US',  | 
            ||
| 1585 | ]  | 
            ||
| 1586 | ),  | 
            ||
| 1587 | ];  | 
            ||
| 1588 | $spiFields1 = [  | 
            ||
| 1589 | new SPIField(  | 
            ||
| 1590 | [  | 
            ||
| 1591 | 'fieldDefinitionId' => 'fieldDefinitionId1',  | 
            ||
| 1592 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 1593 | 'value' => 'newValue1',  | 
            ||
| 1594 | 'languageCode' => 'ger-DE',  | 
            ||
| 1595 | ]  | 
            ||
| 1596 | ),  | 
            ||
| 1597 | new SPIField(  | 
            ||
| 1598 | [  | 
            ||
| 1599 | 'fieldDefinitionId' => 'fieldDefinitionId2',  | 
            ||
| 1600 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 1601 | 'value' => 'defaultValue2',  | 
            ||
| 1602 | 'languageCode' => 'ger-DE',  | 
            ||
| 1603 | ]  | 
            ||
| 1604 | ),  | 
            ||
| 1605 | new SPIField(  | 
            ||
| 1606 | [  | 
            ||
| 1607 | 'fieldDefinitionId' => 'fieldDefinitionId2',  | 
            ||
| 1608 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 1609 | 'value' => 'newValue2',  | 
            ||
| 1610 | 'languageCode' => 'eng-US',  | 
            ||
| 1611 | ]  | 
            ||
| 1612 | ),  | 
            ||
| 1613 | new SPIField(  | 
            ||
| 1614 | [  | 
            ||
| 1615 | 'fieldDefinitionId' => 'fieldDefinitionId4',  | 
            ||
| 1616 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 1617 | 'value' => 'newValue4',  | 
            ||
| 1618 | 'languageCode' => 'eng-US',  | 
            ||
| 1619 | ]  | 
            ||
| 1620 | ),  | 
            ||
| 1621 | ];  | 
            ||
| 1622 | |||
| 1623 | return [  | 
            ||
| 1624 | // 0. Creating by default values only  | 
            ||
| 1625 | [  | 
            ||
| 1626 | 'eng-US',  | 
            ||
| 1627 | [],  | 
            ||
| 1628 | $spiFields0,  | 
            ||
| 1629 | ],  | 
            ||
| 1630 | // 1. Multiple languages with language set  | 
            ||
| 1631 | [  | 
            ||
| 1632 | 'eng-US',  | 
            ||
| 1633 | [  | 
            ||
| 1634 | new Field(  | 
            ||
| 1635 | [  | 
            ||
| 1636 | 'fieldDefIdentifier' => 'identifier1',  | 
            ||
| 1637 | 'value' => 'newValue1',  | 
            ||
| 1638 | 'languageCode' => 'ger-DE',  | 
            ||
| 1639 | ]  | 
            ||
| 1640 | ),  | 
            ||
| 1641 | new Field(  | 
            ||
| 1642 | [  | 
            ||
| 1643 | 'fieldDefIdentifier' => 'identifier2',  | 
            ||
| 1644 | 'value' => 'newValue2',  | 
            ||
| 1645 | 'languageCode' => 'eng-US',  | 
            ||
| 1646 | ]  | 
            ||
| 1647 | ),  | 
            ||
| 1648 | new Field(  | 
            ||
| 1649 | [  | 
            ||
| 1650 | 'fieldDefIdentifier' => 'identifier4',  | 
            ||
| 1651 | 'value' => 'newValue4',  | 
            ||
| 1652 | 'languageCode' => 'eng-US',  | 
            ||
| 1653 | ]  | 
            ||
| 1654 | ),  | 
            ||
| 1655 | ],  | 
            ||
| 1656 | $spiFields1,  | 
            ||
| 1657 | ],  | 
            ||
| 1658 | // 2. Multiple languages without language set  | 
            ||
| 1659 | [  | 
            ||
| 1660 | 'eng-US',  | 
            ||
| 1661 | [  | 
            ||
| 1662 | new Field(  | 
            ||
| 1663 | [  | 
            ||
| 1664 | 'fieldDefIdentifier' => 'identifier1',  | 
            ||
| 1665 | 'value' => 'newValue1',  | 
            ||
| 1666 | 'languageCode' => 'ger-DE',  | 
            ||
| 1667 | ]  | 
            ||
| 1668 | ),  | 
            ||
| 1669 | new Field(  | 
            ||
| 1670 | [  | 
            ||
| 1671 | 'fieldDefIdentifier' => 'identifier2',  | 
            ||
| 1672 | 'value' => 'newValue2',  | 
            ||
| 1673 | 'languageCode' => null,  | 
            ||
| 1674 | ]  | 
            ||
| 1675 | ),  | 
            ||
| 1676 | new Field(  | 
            ||
| 1677 | [  | 
            ||
| 1678 | 'fieldDefIdentifier' => 'identifier4',  | 
            ||
| 1679 | 'value' => 'newValue4',  | 
            ||
| 1680 | 'languageCode' => null,  | 
            ||
| 1681 | ]  | 
            ||
| 1682 | ),  | 
            ||
| 1683 | ],  | 
            ||
| 1684 | $spiFields1,  | 
            ||
| 1685 | ],  | 
            ||
| 1686 | ];  | 
            ||
| 1687 | }  | 
            ||
| 1688 | |||
| 1689 | protected function fixturesForTestCreateContentNonRedundantFieldSetComplex()  | 
            ||
| 1690 |     { | 
            ||
| 1691 | return [  | 
            ||
| 1692 | new FieldDefinition(  | 
            ||
| 1693 | [  | 
            ||
| 1694 | 'id' => 'fieldDefinitionId1',  | 
            ||
| 1695 | 'fieldTypeIdentifier' => 'fieldTypeIdentifier',  | 
            ||
| 1696 | 'isTranslatable' => true,  | 
            ||
| 1697 | 'identifier' => 'identifier1',  | 
            ||
| 1698 | 'isRequired' => false,  | 
            ||
| 1699 | 'defaultValue' => self::EMPTY_FIELD_VALUE,  | 
            ||
| 1700 | ]  | 
            ||
| 1701 | ),  | 
            ||
| 1702 | new FieldDefinition(  | 
            ||
| 1703 | [  | 
            ||
| 1704 | 'id' => 'fieldDefinitionId2',  | 
            ||
| 1705 | 'fieldTypeIdentifier' => 'fieldTypeIdentifier',  | 
            ||
| 1706 | 'isTranslatable' => true,  | 
            ||
| 1707 | 'identifier' => 'identifier2',  | 
            ||
| 1708 | 'isRequired' => false,  | 
            ||
| 1709 | 'defaultValue' => 'defaultValue2',  | 
            ||
| 1710 | ]  | 
            ||
| 1711 | ),  | 
            ||
| 1712 | new FieldDefinition(  | 
            ||
| 1713 | [  | 
            ||
| 1714 | 'id' => 'fieldDefinitionId3',  | 
            ||
| 1715 | 'fieldTypeIdentifier' => 'fieldTypeIdentifier',  | 
            ||
| 1716 | 'isTranslatable' => false,  | 
            ||
| 1717 | 'identifier' => 'identifier3',  | 
            ||
| 1718 | 'isRequired' => false,  | 
            ||
| 1719 | 'defaultValue' => self::EMPTY_FIELD_VALUE,  | 
            ||
| 1720 | ]  | 
            ||
| 1721 | ),  | 
            ||
| 1722 | new FieldDefinition(  | 
            ||
| 1723 | [  | 
            ||
| 1724 | 'id' => 'fieldDefinitionId4',  | 
            ||
| 1725 | 'fieldTypeIdentifier' => 'fieldTypeIdentifier',  | 
            ||
| 1726 | 'isTranslatable' => false,  | 
            ||
| 1727 | 'identifier' => 'identifier4',  | 
            ||
| 1728 | 'isRequired' => false,  | 
            ||
| 1729 | 'defaultValue' => 'defaultValue4',  | 
            ||
| 1730 | ]  | 
            ||
| 1731 | ),  | 
            ||
| 1732 | ];  | 
            ||
| 1733 | }  | 
            ||
| 1734 | |||
| 1735 | /**  | 
            ||
| 1736 | * Test for the createContent() method.  | 
            ||
| 1737 | *  | 
            ||
| 1738 | * Testing multiple languages with multiple translatable fields with empty default value.  | 
            ||
| 1739 | *  | 
            ||
| 1740 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 1741 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 1742 | * @covers \eZ\Publish\Core\Repository\ContentService::cloneField  | 
            ||
| 1743 | * @covers \eZ\Publish\Core\Repository\ContentService::getDefaultObjectStates  | 
            ||
| 1744 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 1745 | * @dataProvider providerForTestCreateContentNonRedundantFieldSetComplex  | 
            ||
| 1746 | */  | 
            ||
| 1747 | public function testCreateContentNonRedundantFieldSetComplex($mainLanguageCode, $structFields, $spiFields)  | 
            ||
| 1748 |     { | 
            ||
| 1749 | $fieldDefinitions = $this->fixturesForTestCreateContentNonRedundantFieldSetComplex();  | 
            ||
| 1750 | |||
| 1751 | $this->assertForTestCreateContentNonRedundantFieldSet(  | 
            ||
| 1752 | $mainLanguageCode,  | 
            ||
| 1753 | $structFields,  | 
            ||
| 1754 | $spiFields,  | 
            ||
| 1755 | $fieldDefinitions  | 
            ||
| 1756 | );  | 
            ||
| 1757 | }  | 
            ||
| 1758 | |||
| 1759 | View Code Duplication | public function providerForTestCreateContentWithInvalidLanguage()  | 
            |
| 1760 |     { | 
            ||
| 1761 | return [  | 
            ||
| 1762 | [  | 
            ||
| 1763 | 'eng-GB',  | 
            ||
| 1764 | [  | 
            ||
| 1765 | new Field(  | 
            ||
| 1766 | [  | 
            ||
| 1767 | 'fieldDefIdentifier' => 'identifier',  | 
            ||
| 1768 | 'value' => 'newValue',  | 
            ||
| 1769 | 'languageCode' => 'Klingon',  | 
            ||
| 1770 | ]  | 
            ||
| 1771 | ),  | 
            ||
| 1772 | ],  | 
            ||
| 1773 | ],  | 
            ||
| 1774 | [  | 
            ||
| 1775 | 'Klingon',  | 
            ||
| 1776 | [  | 
            ||
| 1777 | new Field(  | 
            ||
| 1778 | [  | 
            ||
| 1779 | 'fieldDefIdentifier' => 'identifier',  | 
            ||
| 1780 | 'value' => 'newValue',  | 
            ||
| 1781 | 'languageCode' => 'eng-GB',  | 
            ||
| 1782 | ]  | 
            ||
| 1783 | ),  | 
            ||
| 1784 | ],  | 
            ||
| 1785 | ],  | 
            ||
| 1786 | ];  | 
            ||
| 1787 | }  | 
            ||
| 1788 | |||
| 1789 | /**  | 
            ||
| 1790 | * Test for the updateContent() method.  | 
            ||
| 1791 | *  | 
            ||
| 1792 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 1793 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 1794 | * @dataProvider providerForTestCreateContentWithInvalidLanguage  | 
            ||
| 1795 | */  | 
            ||
| 1796 | public function testCreateContentWithInvalidLanguage($mainLanguageCode, $structFields)  | 
            ||
| 1797 |     { | 
            ||
| 1798 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\NotFoundException::class);  | 
            ||
| 1799 |         $this->expectExceptionMessage('Could not find \'Language\' with identifier \'Klingon\''); | 
            ||
| 1800 | |||
| 1801 | $repositoryMock = $this->getRepositoryMock();  | 
            ||
| 1802 | $mockedService = $this->getPartlyMockedContentService();  | 
            ||
| 1803 | /** @var \PHPUnit\Framework\MockObject\MockObject $languageHandlerMock */  | 
            ||
| 1804 | $languageHandlerMock = $this->getPersistenceMock()->contentLanguageHandler();  | 
            ||
| 1805 | $contentTypeServiceMock = $this->getContentTypeServiceMock();  | 
            ||
| 1806 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 1807 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 1808 | |||
| 1809 | $contentType = new ContentType(  | 
            ||
| 1810 | [  | 
            ||
| 1811 | 'id' => 123,  | 
            ||
| 1812 | 'fieldDefinitions' => [],  | 
            ||
| 1813 | ]  | 
            ||
| 1814 | );  | 
            ||
| 1815 | $contentCreateStruct = new ContentCreateStruct(  | 
            ||
| 1816 | [  | 
            ||
| 1817 | 'fields' => $structFields,  | 
            ||
| 1818 | 'mainLanguageCode' => $mainLanguageCode,  | 
            ||
| 1819 | 'contentType' => $contentType,  | 
            ||
| 1820 | 'alwaysAvailable' => false,  | 
            ||
| 1821 | 'ownerId' => 169,  | 
            ||
| 1822 | 'sectionId' => 1,  | 
            ||
| 1823 | ]  | 
            ||
| 1824 | );  | 
            ||
| 1825 | |||
| 1826 | $languageHandlerMock->expects($this->any())  | 
            ||
| 1827 |             ->method('loadByLanguageCode') | 
            ||
| 1828 |             ->with($this->isType('string')) | 
            ||
| 1829 | ->will(  | 
            ||
| 1830 | $this->returnCallback(  | 
            ||
| 1831 | View Code Duplication |                     function ($languageCode) { | 
            |
| 1832 |                         if ($languageCode === 'Klingon') { | 
            ||
| 1833 |                             throw new NotFoundException('Language', 'Klingon'); | 
            ||
| 1834 | }  | 
            ||
| 1835 | |||
| 1836 | return new Language(['id' => 4242]);  | 
            ||
| 1837 | }  | 
            ||
| 1838 | )  | 
            ||
| 1839 | );  | 
            ||
| 1840 | |||
| 1841 | $contentTypeServiceMock->expects($this->once())  | 
            ||
| 1842 |             ->method('loadContentType') | 
            ||
| 1843 | ->with($this->equalTo($contentType->id))  | 
            ||
| 1844 | ->will($this->returnValue($contentType));  | 
            ||
| 1845 | |||
| 1846 | $repositoryMock->expects($this->once())  | 
            ||
| 1847 |             ->method('getContentTypeService') | 
            ||
| 1848 | ->will($this->returnValue($contentTypeServiceMock));  | 
            ||
| 1849 | |||
| 1850 | $that = $this;  | 
            ||
| 1851 | $permissionResolver->expects($this->once())  | 
            ||
| 1852 |             ->method('canUser') | 
            ||
| 1853 | ->with(  | 
            ||
| 1854 |                 $this->equalTo('content'), | 
            ||
| 1855 |                 $this->equalTo('create'), | 
            ||
| 1856 | $this->isInstanceOf(APIContentCreateStruct::class),  | 
            ||
| 1857 | $this->equalTo([])  | 
            ||
| 1858 | )->will(  | 
            ||
| 1859 | $this->returnCallback(  | 
            ||
| 1860 |                     function () use ($that, $contentCreateStruct) { | 
            ||
| 1861 | $that->assertEquals($contentCreateStruct, func_get_arg(2));  | 
            ||
| 1862 | |||
| 1863 | return true;  | 
            ||
| 1864 | }  | 
            ||
| 1865 | )  | 
            ||
| 1866 | );  | 
            ||
| 1867 | |||
| 1868 | $domainMapperMock->expects($this->once())  | 
            ||
| 1869 |             ->method('getUniqueHash') | 
            ||
| 1870 | ->with($this->isInstanceOf(APIContentCreateStruct::class))  | 
            ||
| 1871 | ->will(  | 
            ||
| 1872 | $this->returnCallback(  | 
            ||
| 1873 |                     function ($object) use ($that, $contentCreateStruct) { | 
            ||
| 1874 | $that->assertEquals($contentCreateStruct, $object);  | 
            ||
| 1875 | |||
| 1876 | return 'hash';  | 
            ||
| 1877 | }  | 
            ||
| 1878 | )  | 
            ||
| 1879 | );  | 
            ||
| 1880 | |||
| 1881 | $mockedService->createContent($contentCreateStruct, []);  | 
            ||
| 1882 | }  | 
            ||
| 1883 | |||
| 1884 | protected function assertForCreateContentContentValidationException(  | 
            ||
| 1885 | $mainLanguageCode,  | 
            ||
| 1886 | $structFields,  | 
            ||
| 1887 | $fieldDefinitions = []  | 
            ||
| 1888 |     ) { | 
            ||
| 1889 | $repositoryMock = $this->getRepositoryMock();  | 
            ||
| 1890 | $mockedService = $this->getPartlyMockedContentService(['loadContentByRemoteId']);  | 
            ||
| 1891 | $contentTypeServiceMock = $this->getContentTypeServiceMock();  | 
            ||
| 1892 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 1893 | |||
| 1894 | $contentType = new ContentType(  | 
            ||
| 1895 | [  | 
            ||
| 1896 | 'id' => 123,  | 
            ||
| 1897 | 'fieldDefinitions' => $fieldDefinitions,  | 
            ||
| 1898 | ]  | 
            ||
| 1899 | );  | 
            ||
| 1900 | $contentCreateStruct = new ContentCreateStruct(  | 
            ||
| 1901 | [  | 
            ||
| 1902 | 'ownerId' => 169,  | 
            ||
| 1903 | 'alwaysAvailable' => false,  | 
            ||
| 1904 | 'remoteId' => 'faraday',  | 
            ||
| 1905 | 'mainLanguageCode' => $mainLanguageCode,  | 
            ||
| 1906 | 'fields' => $structFields,  | 
            ||
| 1907 | 'contentType' => $contentType,  | 
            ||
| 1908 | ]  | 
            ||
| 1909 | );  | 
            ||
| 1910 | |||
| 1911 | $contentTypeServiceMock->expects($this->once())  | 
            ||
| 1912 |             ->method('loadContentType') | 
            ||
| 1913 | ->with($this->equalTo(123))  | 
            ||
| 1914 | ->will($this->returnValue($contentType));  | 
            ||
| 1915 | |||
| 1916 | $repositoryMock->expects($this->once())  | 
            ||
| 1917 |             ->method('getContentTypeService') | 
            ||
| 1918 | ->will($this->returnValue($contentTypeServiceMock));  | 
            ||
| 1919 | |||
| 1920 | $permissionResolver->expects($this->once())  | 
            ||
| 1921 |             ->method('canUser') | 
            ||
| 1922 | ->with(  | 
            ||
| 1923 |                 $this->equalTo('content'), | 
            ||
| 1924 |                 $this->equalTo('create'), | 
            ||
| 1925 | $this->isInstanceOf(get_class($contentCreateStruct)),  | 
            ||
| 1926 | $this->equalTo([])  | 
            ||
| 1927 | )->will($this->returnValue(true));  | 
            ||
| 1928 | |||
| 1929 | $mockedService->expects($this->once())  | 
            ||
| 1930 |             ->method('loadContentByRemoteId') | 
            ||
| 1931 | ->with($contentCreateStruct->remoteId)  | 
            ||
| 1932 | ->will(  | 
            ||
| 1933 |                 $this->throwException(new NotFoundException('Content', 'faraday')) | 
            ||
| 1934 | );  | 
            ||
| 1935 | |||
| 1936 | $mockedService->createContent($contentCreateStruct, []);  | 
            ||
| 1937 | }  | 
            ||
| 1938 | |||
| 1939 | View Code Duplication | public function providerForTestCreateContentThrowsContentValidationExceptionFieldDefinition()  | 
            |
| 1940 |     { | 
            ||
| 1941 | return [  | 
            ||
| 1942 | [  | 
            ||
| 1943 | 'eng-GB',  | 
            ||
| 1944 | [  | 
            ||
| 1945 | new Field(  | 
            ||
| 1946 | [  | 
            ||
| 1947 | 'fieldDefIdentifier' => 'identifier',  | 
            ||
| 1948 | 'value' => 'newValue',  | 
            ||
| 1949 | 'languageCode' => 'eng-GB',  | 
            ||
| 1950 | ]  | 
            ||
| 1951 | ),  | 
            ||
| 1952 | ],  | 
            ||
| 1953 | ],  | 
            ||
| 1954 | ];  | 
            ||
| 1955 | }  | 
            ||
| 1956 | |||
| 1957 | /**  | 
            ||
| 1958 | * Test for the createContent() method.  | 
            ||
| 1959 | *  | 
            ||
| 1960 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 1961 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 1962 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 1963 | * @dataProvider providerForTestCreateContentThrowsContentValidationExceptionFieldDefinition  | 
            ||
| 1964 | */  | 
            ||
| 1965 | public function testCreateContentThrowsContentValidationExceptionFieldDefinition($mainLanguageCode, $structFields)  | 
            ||
| 1966 |     { | 
            ||
| 1967 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentValidationException::class);  | 
            ||
| 1968 |         $this->expectExceptionMessage('Field definition \'identifier\' does not exist in given ContentType'); | 
            ||
| 1969 | |||
| 1970 | $this->assertForCreateContentContentValidationException(  | 
            ||
| 1971 | $mainLanguageCode,  | 
            ||
| 1972 | $structFields,  | 
            ||
| 1973 | []  | 
            ||
| 1974 | );  | 
            ||
| 1975 | }  | 
            ||
| 1976 | |||
| 1977 | View Code Duplication | public function providerForTestCreateContentThrowsContentValidationExceptionTranslation()  | 
            |
| 1978 |     { | 
            ||
| 1979 | return [  | 
            ||
| 1980 | [  | 
            ||
| 1981 | 'eng-GB',  | 
            ||
| 1982 | [  | 
            ||
| 1983 | new Field(  | 
            ||
| 1984 | [  | 
            ||
| 1985 | 'fieldDefIdentifier' => 'identifier',  | 
            ||
| 1986 | 'value' => 'newValue',  | 
            ||
| 1987 | 'languageCode' => 'eng-US',  | 
            ||
| 1988 | ]  | 
            ||
| 1989 | ),  | 
            ||
| 1990 | ],  | 
            ||
| 1991 | ],  | 
            ||
| 1992 | ];  | 
            ||
| 1993 | }  | 
            ||
| 1994 | |||
| 1995 | /**  | 
            ||
| 1996 | * Test for the createContent() method.  | 
            ||
| 1997 | *  | 
            ||
| 1998 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 1999 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 2000 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 2001 | * @dataProvider providerForTestCreateContentThrowsContentValidationExceptionTranslation  | 
            ||
| 2002 | */  | 
            ||
| 2003 | View Code Duplication | public function testCreateContentThrowsContentValidationExceptionTranslation($mainLanguageCode, $structFields)  | 
            |
| 2004 |     { | 
            ||
| 2005 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentValidationException::class);  | 
            ||
| 2006 |         $this->expectExceptionMessage('A value is set for non translatable field definition \'identifier\' with language \'eng-US\''); | 
            ||
| 2007 | |||
| 2008 | $fieldDefinitions = [  | 
            ||
| 2009 | new FieldDefinition(  | 
            ||
| 2010 | [  | 
            ||
| 2011 | 'id' => 'fieldDefinitionId1',  | 
            ||
| 2012 | 'fieldTypeIdentifier' => 'fieldTypeIdentifier',  | 
            ||
| 2013 | 'isTranslatable' => false,  | 
            ||
| 2014 | 'identifier' => 'identifier',  | 
            ||
| 2015 | 'isRequired' => false,  | 
            ||
| 2016 | 'defaultValue' => self::EMPTY_FIELD_VALUE,  | 
            ||
| 2017 | ]  | 
            ||
| 2018 | ),  | 
            ||
| 2019 | ];  | 
            ||
| 2020 | |||
| 2021 | $this->assertForCreateContentContentValidationException(  | 
            ||
| 2022 | $mainLanguageCode,  | 
            ||
| 2023 | $structFields,  | 
            ||
| 2024 | $fieldDefinitions  | 
            ||
| 2025 | );  | 
            ||
| 2026 | }  | 
            ||
| 2027 | |||
| 2028 | /**  | 
            ||
| 2029 | * Asserts behaviour necessary for testing ContentFieldValidationException because of required  | 
            ||
| 2030 | * field being empty.  | 
            ||
| 2031 | *  | 
            ||
| 2032 | * @param string $mainLanguageCode  | 
            ||
| 2033 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 2034 | * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions  | 
            ||
| 2035 | *  | 
            ||
| 2036 | * @return mixed  | 
            ||
| 2037 | */  | 
            ||
| 2038 | protected function assertForTestCreateContentRequiredField(  | 
            ||
| 2039 | $mainLanguageCode,  | 
            ||
| 2040 | array $structFields,  | 
            ||
| 2041 | array $fieldDefinitions  | 
            ||
| 2042 |     ) { | 
            ||
| 2043 | $repositoryMock = $this->getRepositoryMock();  | 
            ||
| 2044 | /** @var \PHPUnit\Framework\MockObject\MockObject $languageHandlerMock */  | 
            ||
| 2045 | $languageHandlerMock = $this->getPersistenceMock()->contentLanguageHandler();  | 
            ||
| 2046 | $contentTypeServiceMock = $this->getContentTypeServiceMock();  | 
            ||
| 2047 | $fieldTypeServiceMock = $this->getFieldTypeServiceMock();  | 
            ||
| 2048 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 2049 | $fieldTypeMock = $this->createMock(SPIFieldType::class);  | 
            ||
| 2050 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 2051 | |||
| 2052 | $contentType = new ContentType(  | 
            ||
| 2053 | [  | 
            ||
| 2054 | 'id' => 123,  | 
            ||
| 2055 | 'fieldDefinitions' => $fieldDefinitions,  | 
            ||
| 2056 | 'nameSchema' => '<nameSchema>',  | 
            ||
| 2057 | ]  | 
            ||
| 2058 | );  | 
            ||
| 2059 | $contentCreateStruct = new ContentCreateStruct(  | 
            ||
| 2060 | [  | 
            ||
| 2061 | 'fields' => $structFields,  | 
            ||
| 2062 | 'mainLanguageCode' => $mainLanguageCode,  | 
            ||
| 2063 | 'contentType' => $contentType,  | 
            ||
| 2064 | 'alwaysAvailable' => false,  | 
            ||
| 2065 | 'ownerId' => 169,  | 
            ||
| 2066 | 'sectionId' => 1,  | 
            ||
| 2067 | ]  | 
            ||
| 2068 | );  | 
            ||
| 2069 | |||
| 2070 | $languageHandlerMock->expects($this->any())  | 
            ||
| 2071 |             ->method('loadByLanguageCode') | 
            ||
| 2072 |             ->with($this->isType('string')) | 
            ||
| 2073 | ->will(  | 
            ||
| 2074 | $this->returnCallback(  | 
            ||
| 2075 |                     function () { | 
            ||
| 2076 | return new Language(['id' => 4242]);  | 
            ||
| 2077 | }  | 
            ||
| 2078 | )  | 
            ||
| 2079 | );  | 
            ||
| 2080 | |||
| 2081 | $contentTypeServiceMock->expects($this->once())  | 
            ||
| 2082 |             ->method('loadContentType') | 
            ||
| 2083 | ->with($this->equalTo($contentType->id))  | 
            ||
| 2084 | ->will($this->returnValue($contentType));  | 
            ||
| 2085 | |||
| 2086 | $repositoryMock->expects($this->once())  | 
            ||
| 2087 |             ->method('getContentTypeService') | 
            ||
| 2088 | ->will($this->returnValue($contentTypeServiceMock));  | 
            ||
| 2089 | |||
| 2090 | $that = $this;  | 
            ||
| 2091 | $permissionResolver->expects($this->once())  | 
            ||
| 2092 |             ->method('canUser') | 
            ||
| 2093 | ->with(  | 
            ||
| 2094 |                 $this->equalTo('content'), | 
            ||
| 2095 |                 $this->equalTo('create'), | 
            ||
| 2096 | $this->isInstanceOf(APIContentCreateStruct::class),  | 
            ||
| 2097 | $this->equalTo([])  | 
            ||
| 2098 | )->will(  | 
            ||
| 2099 | $this->returnCallback(  | 
            ||
| 2100 |                     function () use ($that, $contentCreateStruct) { | 
            ||
| 2101 | $that->assertEquals($contentCreateStruct, func_get_arg(2));  | 
            ||
| 2102 | |||
| 2103 | return true;  | 
            ||
| 2104 | }  | 
            ||
| 2105 | )  | 
            ||
| 2106 | );  | 
            ||
| 2107 | |||
| 2108 | $domainMapperMock->expects($this->once())  | 
            ||
| 2109 |             ->method('getUniqueHash') | 
            ||
| 2110 | ->with($this->isInstanceOf(APIContentCreateStruct::class))  | 
            ||
| 2111 | ->will(  | 
            ||
| 2112 | $this->returnCallback(  | 
            ||
| 2113 |                     function ($object) use ($that, $contentCreateStruct) { | 
            ||
| 2114 | $that->assertEquals($contentCreateStruct, $object);  | 
            ||
| 2115 | |||
| 2116 | return 'hash';  | 
            ||
| 2117 | }  | 
            ||
| 2118 | )  | 
            ||
| 2119 | );  | 
            ||
| 2120 | |||
| 2121 | $fieldTypeMock->expects($this->any())  | 
            ||
| 2122 |             ->method('acceptValue') | 
            ||
| 2123 | ->will(  | 
            ||
| 2124 | $this->returnCallback(  | 
            ||
| 2125 |                     function ($valueString) { | 
            ||
| 2126 | return new ValueStub($valueString);  | 
            ||
| 2127 | }  | 
            ||
| 2128 | )  | 
            ||
| 2129 | );  | 
            ||
| 2130 | |||
| 2131 | $emptyValue = self::EMPTY_FIELD_VALUE;  | 
            ||
| 2132 | $fieldTypeMock->expects($this->any())  | 
            ||
| 2133 |             ->method('isEmptyValue') | 
            ||
| 2134 | ->will(  | 
            ||
| 2135 | $this->returnCallback(  | 
            ||
| 2136 |                     function (ValueStub $value) use ($emptyValue) { | 
            ||
| 2137 | return $emptyValue === (string)$value;  | 
            ||
| 2138 | }  | 
            ||
| 2139 | )  | 
            ||
| 2140 | );  | 
            ||
| 2141 | |||
| 2142 | $fieldTypeMock->expects($this->any())  | 
            ||
| 2143 |             ->method('validate') | 
            ||
| 2144 | ->will($this->returnValue([]));  | 
            ||
| 2145 | |||
| 2146 | $this->getFieldTypeRegistryMock()->expects($this->any())  | 
            ||
| 2147 |             ->method('getFieldType') | 
            ||
| 2148 | ->will($this->returnValue($fieldTypeMock));  | 
            ||
| 2149 | |||
| 2150 | return $contentCreateStruct;  | 
            ||
| 2151 | }  | 
            ||
| 2152 | |||
| 2153 | View Code Duplication | public function providerForTestCreateContentThrowsContentValidationExceptionRequiredField()  | 
            |
| 2154 |     { | 
            ||
| 2155 | return [  | 
            ||
| 2156 | [  | 
            ||
| 2157 | 'eng-US',  | 
            ||
| 2158 | [  | 
            ||
| 2159 | new Field(  | 
            ||
| 2160 | [  | 
            ||
| 2161 | 'fieldDefIdentifier' => 'identifier',  | 
            ||
| 2162 | 'value' => self::EMPTY_FIELD_VALUE,  | 
            ||
| 2163 | 'languageCode' => null,  | 
            ||
| 2164 | ]  | 
            ||
| 2165 | ),  | 
            ||
| 2166 | ],  | 
            ||
| 2167 | 'identifier',  | 
            ||
| 2168 | 'eng-US',  | 
            ||
| 2169 | ],  | 
            ||
| 2170 | ];  | 
            ||
| 2171 | }  | 
            ||
| 2172 | |||
| 2173 | /**  | 
            ||
| 2174 | * Test for the createContent() method.  | 
            ||
| 2175 | *  | 
            ||
| 2176 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 2177 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 2178 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 2179 | * @dataProvider providerForTestCreateContentThrowsContentValidationExceptionRequiredField  | 
            ||
| 2180 | */  | 
            ||
| 2181 | public function testCreateContentRequiredField(  | 
            ||
| 2182 | $mainLanguageCode,  | 
            ||
| 2183 | $structFields,  | 
            ||
| 2184 | $identifier,  | 
            ||
| 2185 | $languageCode  | 
            ||
| 2186 |     ) { | 
            ||
| 2187 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException::class);  | 
            ||
| 2188 | |||
| 2189 | $fieldDefinitions = [  | 
            ||
| 2190 | new FieldDefinition(  | 
            ||
| 2191 | [  | 
            ||
| 2192 | 'id' => 'fieldDefinitionId',  | 
            ||
| 2193 | 'fieldTypeIdentifier' => 'fieldTypeIdentifier',  | 
            ||
| 2194 | 'isTranslatable' => true,  | 
            ||
| 2195 | 'identifier' => 'identifier',  | 
            ||
| 2196 | 'isRequired' => true,  | 
            ||
| 2197 | 'defaultValue' => 'defaultValue',  | 
            ||
| 2198 | ]  | 
            ||
| 2199 | ),  | 
            ||
| 2200 | ];  | 
            ||
| 2201 | $contentCreateStruct = $this->assertForTestCreateContentRequiredField(  | 
            ||
| 2202 | $mainLanguageCode,  | 
            ||
| 2203 | $structFields,  | 
            ||
| 2204 | $fieldDefinitions  | 
            ||
| 2205 | );  | 
            ||
| 2206 | |||
| 2207 | $mockedService = $this->getPartlyMockedContentService();  | 
            ||
| 2208 | |||
| 2209 |         try { | 
            ||
| 2210 | $mockedService->createContent($contentCreateStruct, []);  | 
            ||
| 2211 |         } catch (ContentValidationException $e) { | 
            ||
| 2212 | $this->assertEquals(  | 
            ||
| 2213 |                 "Value for required field definition '{$identifier}' with language '{$languageCode}' is empty", | 
            ||
| 2214 | $e->getMessage()  | 
            ||
| 2215 | );  | 
            ||
| 2216 | |||
| 2217 | throw $e;  | 
            ||
| 2218 | }  | 
            ||
| 2219 | }  | 
            ||
| 2220 | |||
| 2221 | /**  | 
            ||
| 2222 | * Asserts behaviour necessary for testing ContentFieldValidationException because of  | 
            ||
| 2223 | * field not being valid.  | 
            ||
| 2224 | *  | 
            ||
| 2225 | * @param string $mainLanguageCode  | 
            ||
| 2226 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 2227 | * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions  | 
            ||
| 2228 | *  | 
            ||
| 2229 | * @return mixed  | 
            ||
| 2230 | */  | 
            ||
| 2231 | protected function assertForTestCreateContentThrowsContentFieldValidationException(  | 
            ||
| 2232 | $mainLanguageCode,  | 
            ||
| 2233 | array $structFields,  | 
            ||
| 2234 | array $fieldDefinitions  | 
            ||
| 2235 |     ) { | 
            ||
| 2236 | $repositoryMock = $this->getRepositoryMock();  | 
            ||
| 2237 | /** @var \PHPUnit\Framework\MockObject\MockObject $languageHandlerMock */  | 
            ||
| 2238 | $languageHandlerMock = $this->getPersistenceMock()->contentLanguageHandler();  | 
            ||
| 2239 | $contentTypeServiceMock = $this->getContentTypeServiceMock();  | 
            ||
| 2240 | $fieldTypeServiceMock = $this->getFieldTypeServiceMock();  | 
            ||
| 2241 | $domainMapperMock = $this->getDomainMapperMock();  | 
            ||
| 2242 | $relationProcessorMock = $this->getRelationProcessorMock();  | 
            ||
| 2243 | $fieldTypeMock = $this->createMock(SPIFieldType::class);  | 
            ||
| 2244 | $languageCodes = $this->determineLanguageCodesForCreate($mainLanguageCode, $structFields);  | 
            ||
| 2245 | $permissionResolver = $this->getPermissionResolverMock();  | 
            ||
| 2246 | |||
| 2247 | $contentType = new ContentType(  | 
            ||
| 2248 | [  | 
            ||
| 2249 | 'id' => 123,  | 
            ||
| 2250 | 'fieldDefinitions' => $fieldDefinitions,  | 
            ||
| 2251 | 'nameSchema' => '<nameSchema>',  | 
            ||
| 2252 | ]  | 
            ||
| 2253 | );  | 
            ||
| 2254 | $contentCreateStruct = new ContentCreateStruct(  | 
            ||
| 2255 | [  | 
            ||
| 2256 | 'fields' => $structFields,  | 
            ||
| 2257 | 'mainLanguageCode' => $mainLanguageCode,  | 
            ||
| 2258 | 'contentType' => $contentType,  | 
            ||
| 2259 | 'alwaysAvailable' => false,  | 
            ||
| 2260 | 'ownerId' => 169,  | 
            ||
| 2261 | 'sectionId' => 1,  | 
            ||
| 2262 | ]  | 
            ||
| 2263 | );  | 
            ||
| 2264 | |||
| 2265 | $languageHandlerMock->expects($this->any())  | 
            ||
| 2266 |             ->method('loadByLanguageCode') | 
            ||
| 2267 |             ->with($this->isType('string')) | 
            ||
| 2268 | ->will(  | 
            ||
| 2269 | $this->returnCallback(  | 
            ||
| 2270 |                     function () { | 
            ||
| 2271 | return new Language(['id' => 4242]);  | 
            ||
| 2272 | }  | 
            ||
| 2273 | )  | 
            ||
| 2274 | );  | 
            ||
| 2275 | |||
| 2276 | $contentTypeServiceMock->expects($this->once())  | 
            ||
| 2277 |             ->method('loadContentType') | 
            ||
| 2278 | ->with($this->equalTo($contentType->id))  | 
            ||
| 2279 | ->will($this->returnValue($contentType));  | 
            ||
| 2280 | |||
| 2281 | $repositoryMock->expects($this->once())  | 
            ||
| 2282 |             ->method('getContentTypeService') | 
            ||
| 2283 | ->will($this->returnValue($contentTypeServiceMock));  | 
            ||
| 2284 | |||
| 2285 | $that = $this;  | 
            ||
| 2286 | $permissionResolver->expects($this->once())  | 
            ||
| 2287 |             ->method('canUser') | 
            ||
| 2288 | ->with(  | 
            ||
| 2289 |                 $this->equalTo('content'), | 
            ||
| 2290 |                 $this->equalTo('create'), | 
            ||
| 2291 | $this->isInstanceOf(APIContentCreateStruct::class),  | 
            ||
| 2292 | $this->equalTo([])  | 
            ||
| 2293 | )->will(  | 
            ||
| 2294 | $this->returnCallback(  | 
            ||
| 2295 |                     function () use ($that, $contentCreateStruct) { | 
            ||
| 2296 | $that->assertEquals($contentCreateStruct, func_get_arg(2));  | 
            ||
| 2297 | |||
| 2298 | return true;  | 
            ||
| 2299 | }  | 
            ||
| 2300 | )  | 
            ||
| 2301 | );  | 
            ||
| 2302 | |||
| 2303 | $domainMapperMock->expects($this->once())  | 
            ||
| 2304 |             ->method('getUniqueHash') | 
            ||
| 2305 | ->with($this->isInstanceOf(APIContentCreateStruct::class))  | 
            ||
| 2306 | ->will(  | 
            ||
| 2307 | $this->returnCallback(  | 
            ||
| 2308 |                     function ($object) use ($that, $contentCreateStruct) { | 
            ||
| 2309 | $that->assertEquals($contentCreateStruct, $object);  | 
            ||
| 2310 | |||
| 2311 | return 'hash';  | 
            ||
| 2312 | }  | 
            ||
| 2313 | )  | 
            ||
| 2314 | );  | 
            ||
| 2315 | |||
| 2316 | $this->getFieldTypeRegistryMock()->expects($this->any())  | 
            ||
| 2317 |             ->method('getFieldType') | 
            ||
| 2318 | ->will($this->returnValue($fieldTypeMock));  | 
            ||
| 2319 | |||
| 2320 | $relationProcessorMock  | 
            ||
| 2321 | ->expects($this->any())  | 
            ||
| 2322 |             ->method('appendFieldRelations') | 
            ||
| 2323 | ->with(  | 
            ||
| 2324 |                 $this->isType('array'), | 
            ||
| 2325 |                 $this->isType('array'), | 
            ||
| 2326 | $this->isInstanceOf(SPIFieldType::class),  | 
            ||
| 2327 | $this->isInstanceOf(Value::class),  | 
            ||
| 2328 | $this->anything()  | 
            ||
| 2329 | );  | 
            ||
| 2330 | |||
| 2331 | $fieldValues = $this->determineValuesForCreate(  | 
            ||
| 2332 | $mainLanguageCode,  | 
            ||
| 2333 | $structFields,  | 
            ||
| 2334 | $fieldDefinitions,  | 
            ||
| 2335 | $languageCodes  | 
            ||
| 2336 | );  | 
            ||
| 2337 | $allFieldErrors = [];  | 
            ||
| 2338 | $validateCount = 0;  | 
            ||
| 2339 | $emptyValue = self::EMPTY_FIELD_VALUE;  | 
            ||
| 2340 |         foreach ($contentType->getFieldDefinitions() as $fieldDefinition) { | 
            ||
| 2341 |             foreach ($fieldValues[$fieldDefinition->identifier] as $languageCode => $value) { | 
            ||
| 2342 | $fieldTypeMock->expects($this->at($validateCount++))  | 
            ||
| 2343 |                     ->method('acceptValue') | 
            ||
| 2344 | ->will(  | 
            ||
| 2345 | $this->returnCallback(  | 
            ||
| 2346 |                             function ($valueString) { | 
            ||
| 2347 | return new ValueStub($valueString);  | 
            ||
| 2348 | }  | 
            ||
| 2349 | )  | 
            ||
| 2350 | );  | 
            ||
| 2351 | |||
| 2352 | $fieldTypeMock->expects($this->at($validateCount++))  | 
            ||
| 2353 |                     ->method('isEmptyValue') | 
            ||
| 2354 | ->will(  | 
            ||
| 2355 | $this->returnCallback(  | 
            ||
| 2356 |                             function (ValueStub $value) use ($emptyValue) { | 
            ||
| 2357 | return $emptyValue === (string)$value;  | 
            ||
| 2358 | }  | 
            ||
| 2359 | )  | 
            ||
| 2360 | );  | 
            ||
| 2361 | |||
| 2362 |                 if (self::EMPTY_FIELD_VALUE === (string)$value) { | 
            ||
| 2363 | continue;  | 
            ||
| 2364 | }  | 
            ||
| 2365 | |||
| 2366 | $fieldTypeMock->expects($this->at($validateCount++))  | 
            ||
| 2367 |                     ->method('validate') | 
            ||
| 2368 | ->with(  | 
            ||
| 2369 | $this->equalTo($fieldDefinition),  | 
            ||
| 2370 | $this->equalTo($value)  | 
            ||
| 2371 | )->will($this->returnArgument(1));  | 
            ||
| 2372 | |||
| 2373 | $allFieldErrors[$fieldDefinition->id][$languageCode] = $value;  | 
            ||
| 2374 | }  | 
            ||
| 2375 | }  | 
            ||
| 2376 | |||
| 2377 | return [$contentCreateStruct, $allFieldErrors];  | 
            ||
| 2378 | }  | 
            ||
| 2379 | |||
| 2380 | public function providerForTestCreateContentThrowsContentFieldValidationException()  | 
            ||
| 2384 | |||
| 2385 | /**  | 
            ||
| 2386 | * Test for the createContent() method.  | 
            ||
| 2387 | *  | 
            ||
| 2388 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 2389 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 2390 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 2391 | * @dataProvider providerForTestCreateContentThrowsContentFieldValidationException  | 
            ||
| 2392 | */  | 
            ||
| 2393 | View Code Duplication | public function testCreateContentThrowsContentFieldValidationException($mainLanguageCode, $structFields)  | 
            |
| 2394 |     { | 
            ||
| 2395 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException::class);  | 
            ||
| 2396 |         $this->expectExceptionMessage('Content fields did not validate'); | 
            ||
| 2397 | |||
| 2398 | $fieldDefinitions = $this->fixturesForTestCreateContentNonRedundantFieldSetComplex();  | 
            ||
| 2399 | list($contentCreateStruct, $allFieldErrors) =  | 
            ||
| 2400 | $this->assertForTestCreateContentThrowsContentFieldValidationException(  | 
            ||
| 2401 | $mainLanguageCode,  | 
            ||
| 2402 | $structFields,  | 
            ||
| 2403 | $fieldDefinitions  | 
            ||
| 2404 | );  | 
            ||
| 2405 | |||
| 2406 | $mockedService = $this->getPartlyMockedContentService();  | 
            ||
| 2407 | |||
| 2408 |         try { | 
            ||
| 2409 | $mockedService->createContent($contentCreateStruct);  | 
            ||
| 2410 |         } catch (ContentFieldValidationException $e) { | 
            ||
| 2411 | $this->assertEquals($allFieldErrors, $e->getFieldErrors());  | 
            ||
| 2412 | throw $e;  | 
            ||
| 2413 | }  | 
            ||
| 2414 | }  | 
            ||
| 2415 | |||
| 2416 | /**  | 
            ||
| 2417 | * Test for the createContent() method.  | 
            ||
| 2418 | *  | 
            ||
| 2419 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 2420 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 2421 | * @covers \eZ\Publish\Core\Repository\ContentService::buildSPILocationCreateStructs  | 
            ||
| 2422 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 2423 | */  | 
            ||
| 2424 | public function testCreateContentWithLocations()  | 
            ||
| 2425 |     { | 
            ||
| 2426 | $spiFields = [  | 
            ||
| 2427 | new SPIField(  | 
            ||
| 2428 | [  | 
            ||
| 2429 | 'fieldDefinitionId' => 'fieldDefinitionId',  | 
            ||
| 2430 | 'type' => 'fieldTypeIdentifier',  | 
            ||
| 2431 | 'value' => 'defaultValue',  | 
            ||
| 2432 | 'languageCode' => 'eng-US',  | 
            ||
| 2551 | |||
| 2552 | /**  | 
            ||
| 2553 | * Test for the createContent() method.  | 
            ||
| 2554 | *  | 
            ||
| 2555 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 2556 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 2557 | * @covers \eZ\Publish\Core\Repository\ContentService::buildSPILocationCreateStructs  | 
            ||
| 2558 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 2559 | */  | 
            ||
| 2560 | public function testCreateContentWithLocationsDuplicateUnderParent()  | 
            ||
| 2683 | |||
| 2684 | /**  | 
            ||
| 2685 | * Test for the createContent() method.  | 
            ||
| 2686 | *  | 
            ||
| 2687 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 2688 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 2689 | * @covers \eZ\Publish\Core\Repository\ContentService::getDefaultObjectStates  | 
            ||
| 2690 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 2691 | */  | 
            ||
| 2692 | public function testCreateContentObjectStates()  | 
            ||
| 2788 | |||
| 2789 | /**  | 
            ||
| 2790 | * Test for the createContent() method.  | 
            ||
| 2791 | *  | 
            ||
| 2792 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForCreate  | 
            ||
| 2793 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForCreate  | 
            ||
| 2794 | * @covers \eZ\Publish\Core\Repository\ContentService::getDefaultObjectStates  | 
            ||
| 2795 | * @covers \eZ\Publish\Core\Repository\ContentService::createContent  | 
            ||
| 2796 | * @dataProvider providerForTestCreateContentThrowsContentValidationExceptionTranslation  | 
            ||
| 2797 | */  | 
            ||
| 2798 | public function testCreateContentWithRollback()  | 
            ||
| 2842 | |||
| 2843 | public function providerForTestUpdateContentThrowsBadStateException()  | 
            ||
| 2850 | |||
| 2851 | /**  | 
            ||
| 2852 | * Test for the updateContent() method.  | 
            ||
| 2853 | *  | 
            ||
| 2854 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 2855 | * @dataProvider providerForTestUpdateContentThrowsBadStateException  | 
            ||
| 2856 | */  | 
            ||
| 2857 | public function testUpdateContentThrowsBadStateException($status)  | 
            ||
| 2889 | |||
| 2890 | /**  | 
            ||
| 2891 | * Test for the updateContent() method.  | 
            ||
| 2892 | *  | 
            ||
| 2893 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 2894 | */  | 
            ||
| 2895 | public function testUpdateContentThrowsUnauthorizedException()  | 
            ||
| 2937 | |||
| 2938 | /**  | 
            ||
| 2939 | * @param string $initialLanguageCode  | 
            ||
| 2940 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 2941 | * @param string[] $existingLanguages  | 
            ||
| 2942 | *  | 
            ||
| 2943 | * @return string[]  | 
            ||
| 2944 | */  | 
            ||
| 2945 | protected function determineLanguageCodesForUpdate($initialLanguageCode, array $structFields, $existingLanguages)  | 
            ||
| 2962 | |||
| 2963 | /**  | 
            ||
| 2964 | * @param string $initialLanguageCode  | 
            ||
| 2965 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 2966 | * @param string $mainLanguageCode  | 
            ||
| 2967 | * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions  | 
            ||
| 2968 | *  | 
            ||
| 2969 | * @return array  | 
            ||
| 2970 | */  | 
            ||
| 2971 | protected function mapStructFieldsForUpdate($initialLanguageCode, $structFields, $mainLanguageCode, $fieldDefinitions)  | 
            ||
| 2997 | |||
| 2998 | /**  | 
            ||
| 2999 | * Returns full, possibly redundant array of field values, indexed by field definition  | 
            ||
| 3000 | * identifier and language code.  | 
            ||
| 3001 | *  | 
            ||
| 3002 | * @param string $initialLanguageCode  | 
            ||
| 3003 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 3004 | * @param \eZ\Publish\Core\Repository\Values\Content\Content $content  | 
            ||
| 3005 | * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions  | 
            ||
| 3006 | * @param array $languageCodes  | 
            ||
| 3007 | *  | 
            ||
| 3008 | * @return array  | 
            ||
| 3009 | */  | 
            ||
| 3010 | protected function determineValuesForUpdate(  | 
            ||
| 3056 | |||
| 3057 | protected function stubValues(array $fieldValues)  | 
            ||
| 3067 | |||
| 3068 | /**  | 
            ||
| 3069 | * Asserts that calling updateContent() with given API field set causes calling  | 
            ||
| 3070 | * Handler::updateContent() with given SPI field set.  | 
            ||
| 3071 | *  | 
            ||
| 3072 | * @param string $initialLanguageCode  | 
            ||
| 3073 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $structFields  | 
            ||
| 3074 | * @param \eZ\Publish\SPI\Persistence\Content\Field[] $spiFields  | 
            ||
| 3075 | * @param \eZ\Publish\API\Repository\Values\Content\Field[] $existingFields  | 
            ||
| 3076 | * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition[] $fieldDefinitions  | 
            ||
| 3077 | * @param bool $execute  | 
            ||
| 3078 | *  | 
            ||
| 3079 | * @return mixed  | 
            ||
| 3080 | */  | 
            ||
| 3081 | protected function assertForTestUpdateContentNonRedundantFieldSet(  | 
            ||
| 3320 | |||
| 3321 | public function providerForTestUpdateContentNonRedundantFieldSet1()  | 
            ||
| 3373 | |||
| 3374 | /**  | 
            ||
| 3375 | * Test for the updateContent() method.  | 
            ||
| 3376 | *  | 
            ||
| 3377 | * Testing the simplest use case.  | 
            ||
| 3378 | *  | 
            ||
| 3379 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 3380 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 3381 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 3382 | * @dataProvider providerForTestUpdateContentNonRedundantFieldSet1  | 
            ||
| 3383 | */  | 
            ||
| 3384 | View Code Duplication | public function testUpdateContentNonRedundantFieldSet1($initialLanguageCode, $structFields, $spiFields)  | 
            |
| 3418 | |||
| 3419 | public function providerForTestUpdateContentNonRedundantFieldSet2()  | 
            ||
| 3586 | |||
| 3587 | /**  | 
            ||
| 3588 | * Test for the updateContent() method.  | 
            ||
| 3589 | *  | 
            ||
| 3590 | * Testing with translatable field.  | 
            ||
| 3591 | *  | 
            ||
| 3592 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 3593 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 3594 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 3595 | * @dataProvider providerForTestUpdateContentNonRedundantFieldSet2  | 
            ||
| 3596 | */  | 
            ||
| 3597 | View Code Duplication | public function testUpdateContentNonRedundantFieldSet2($initialLanguageCode, $structFields, $spiFields)  | 
            |
| 3631 | |||
| 3632 | public function providerForTestUpdateContentNonRedundantFieldSet3()  | 
            ||
| 3848 | |||
| 3849 | /**  | 
            ||
| 3850 | * Test for the updateContent() method.  | 
            ||
| 3851 | *  | 
            ||
| 3852 | * Testing with new language and untranslatable field.  | 
            ||
| 3853 | *  | 
            ||
| 3854 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 3855 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 3856 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 3857 | * @dataProvider providerForTestUpdateContentNonRedundantFieldSet3  | 
            ||
| 3858 | */  | 
            ||
| 3859 | public function testUpdateContentNonRedundantFieldSet3($initialLanguageCode, $structFields, $spiFields)  | 
            ||
| 3911 | |||
| 3912 | public function providerForTestUpdateContentNonRedundantFieldSet4()  | 
            ||
| 4153 | |||
| 4154 | /**  | 
            ||
| 4155 | * Test for the updateContent() method.  | 
            ||
| 4156 | *  | 
            ||
| 4157 | * Testing with empty values.  | 
            ||
| 4158 | *  | 
            ||
| 4159 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 4160 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 4161 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 4162 | * @dataProvider providerForTestUpdateContentNonRedundantFieldSet4  | 
            ||
| 4163 | */  | 
            ||
| 4164 | public function testUpdateContentNonRedundantFieldSet4($initialLanguageCode, $structFields, $spiFields)  | 
            ||
| 4216 | |||
| 4217 | /**  | 
            ||
| 4218 | * @todo add first field empty  | 
            ||
| 4219 | *  | 
            ||
| 4220 | * @return array  | 
            ||
| 4221 | */  | 
            ||
| 4222 | public function providerForTestUpdateContentNonRedundantFieldSetComplex()  | 
            ||
| 4450 | |||
| 4451 | protected function fixturesForTestUpdateContentNonRedundantFieldSetComplex()  | 
            ||
| 4533 | |||
| 4534 | /**  | 
            ||
| 4535 | * Test for the updateContent() method.  | 
            ||
| 4536 | *  | 
            ||
| 4537 | * Testing more complex cases.  | 
            ||
| 4538 | *  | 
            ||
| 4539 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 4540 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 4541 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 4542 | * @dataProvider providerForTestUpdateContentNonRedundantFieldSetComplex  | 
            ||
| 4543 | */  | 
            ||
| 4544 | public function testUpdateContentNonRedundantFieldSetComplex($initialLanguageCode, $structFields, $spiFields)  | 
            ||
| 4556 | |||
| 4557 | View Code Duplication | public function providerForTestUpdateContentWithInvalidLanguage()  | 
            |
| 4586 | |||
| 4587 | /**  | 
            ||
| 4588 | * Test for the updateContent() method.  | 
            ||
| 4589 | *  | 
            ||
| 4590 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 4591 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 4592 | * @dataProvider providerForTestUpdateContentWithInvalidLanguage  | 
            ||
| 4593 | */  | 
            ||
| 4594 | public function testUpdateContentWithInvalidLanguage($initialLanguageCode, $structFields)  | 
            ||
| 4667 | |||
| 4668 | protected function assertForUpdateContentContentValidationException(  | 
            ||
| 4753 | |||
| 4754 | View Code Duplication | public function providerForTestUpdateContentThrowsContentValidationExceptionFieldDefinition()  | 
            |
| 4771 | |||
| 4772 | /**  | 
            ||
| 4773 | * Test for the updateContent() method.  | 
            ||
| 4774 | *  | 
            ||
| 4775 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 4776 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 4777 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 4778 | * @dataProvider providerForTestUpdateContentThrowsContentValidationExceptionFieldDefinition  | 
            ||
| 4779 | */  | 
            ||
| 4780 | public function testUpdateContentThrowsContentValidationExceptionFieldDefinition($initialLanguageCode, $structFields)  | 
            ||
| 4791 | |||
| 4792 | View Code Duplication | public function providerForTestUpdateContentThrowsContentValidationExceptionTranslation()  | 
            |
| 4809 | |||
| 4810 | /**  | 
            ||
| 4811 | * Test for the updateContent() method.  | 
            ||
| 4812 | *  | 
            ||
| 4813 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 4814 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 4815 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 4816 | * @dataProvider providerForTestUpdateContentThrowsContentValidationExceptionTranslation  | 
            ||
| 4817 | */  | 
            ||
| 4818 | View Code Duplication | public function testUpdateContentThrowsContentValidationExceptionTranslation($initialLanguageCode, $structFields)  | 
            |
| 4842 | |||
| 4843 | public function assertForTestUpdateContentRequiredField(  | 
            ||
| 4964 | |||
| 4965 | View Code Duplication | public function providerForTestUpdateContentRequiredField()  | 
            |
| 4984 | |||
| 4985 | /**  | 
            ||
| 4986 | * Test for the updateContent() method.  | 
            ||
| 4987 | *  | 
            ||
| 4988 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 4989 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 4990 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 4991 | * @dataProvider providerForTestUpdateContentRequiredField  | 
            ||
| 4992 | */  | 
            ||
| 4993 | public function testUpdateContentRequiredField(  | 
            ||
| 5042 | |||
| 5043 | public function assertForTestUpdateContentThrowsContentFieldValidationException(  | 
            ||
| 5176 | |||
| 5177 | public function providerForTestUpdateContentThrowsContentFieldValidationException()  | 
            ||
| 5298 | |||
| 5299 | /**  | 
            ||
| 5300 | * Test for the updateContent() method.  | 
            ||
| 5301 | *  | 
            ||
| 5302 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 5303 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 5304 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 5305 | * @dataProvider providerForTestUpdateContentThrowsContentFieldValidationException  | 
            ||
| 5306 | */  | 
            ||
| 5307 | View Code Duplication | public function testUpdateContentThrowsContentFieldValidationException($initialLanguageCode, $structFields, $spiField, $allFieldErrors)  | 
            |
| 5328 | |||
| 5329 | /**  | 
            ||
| 5330 | * Test for the updateContent() method.  | 
            ||
| 5331 | *  | 
            ||
| 5332 | * @covers \eZ\Publish\Core\Repository\ContentService::getLanguageCodesForUpdate  | 
            ||
| 5333 | * @covers \eZ\Publish\Core\Repository\ContentService::mapFieldsForUpdate  | 
            ||
| 5334 | * @covers \eZ\Publish\Core\Repository\ContentService::updateContent  | 
            ||
| 5335 | */  | 
            ||
| 5336 | public function testUpdateContentTransactionRollback()  | 
            ||
| 5393 | |||
| 5394 | /**  | 
            ||
| 5395 | * Test for the copyContent() method.  | 
            ||
| 5396 | *  | 
            ||
| 5397 | * @covers \eZ\Publish\Core\Repository\ContentService::copyContent  | 
            ||
| 5398 | */  | 
            ||
| 5399 | public function testCopyContentThrowsUnauthorizedException()  | 
            ||
| 5442 | |||
| 5443 | /**  | 
            ||
| 5444 | * Test for the copyContent() method.  | 
            ||
| 5445 | *  | 
            ||
| 5446 | * @covers \eZ\Publish\Core\Repository\ContentService::copyContent  | 
            ||
| 5447 | * @covers \eZ\Publish\Core\Repository\ContentService::getDefaultObjectStates  | 
            ||
| 5448 | * @covers \eZ\Publish\Core\Repository\ContentService::internalPublishVersion  | 
            ||
| 5449 | */  | 
            ||
| 5450 | public function testCopyContent()  | 
            ||
| 5574 | |||
| 5575 | /**  | 
            ||
| 5576 | * Test for the copyContent() method.  | 
            ||
| 5577 | *  | 
            ||
| 5578 | * @covers \eZ\Publish\Core\Repository\ContentService::copyContent  | 
            ||
| 5579 | * @covers \eZ\Publish\Core\Repository\ContentService::getDefaultObjectStates  | 
            ||
| 5580 | * @covers \eZ\Publish\Core\Repository\ContentService::internalPublishVersion  | 
            ||
| 5581 | */  | 
            ||
| 5582 | public function testCopyContentWithVersionInfo()  | 
            ||
| 5703 | |||
| 5704 | /**  | 
            ||
| 5705 | * Test for the copyContent() method.  | 
            ||
| 5706 | *  | 
            ||
| 5707 | * @covers \eZ\Publish\Core\Repository\ContentService::copyContent  | 
            ||
| 5708 | * @covers \eZ\Publish\Core\Repository\ContentService::getDefaultObjectStates  | 
            ||
| 5709 | * @covers \eZ\Publish\Core\Repository\ContentService::internalPublishVersion  | 
            ||
| 5710 | */  | 
            ||
| 5711 | public function testCopyContentWithRollback()  | 
            ||
| 5774 | |||
| 5775 | /**  | 
            ||
| 5776 | * Reusable method for setting exceptions on buildContentDomainObject usage.  | 
            ||
| 5777 | *  | 
            ||
| 5778 | * Plain usage as in when content type is loaded directly.  | 
            ||
| 5779 | *  | 
            ||
| 5780 | * @param \eZ\Publish\SPI\Persistence\Content $spiContent  | 
            ||
| 5781 | * @param array $translations  | 
            ||
| 5782 | * @param bool $useAlwaysAvailable  | 
            ||
| 5783 | *  | 
            ||
| 5784 | * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\API\Repository\Values\Content\Content  | 
            ||
| 5785 | */  | 
            ||
| 5786 | private function mockBuildContentDomainObject(SPIContent $spiContent, array $translations = null, bool $useAlwaysAvailable = null)  | 
            ||
| 5816 | |||
| 5817 | protected function mockGetDefaultObjectStates()  | 
            ||
| 5856 | |||
| 5857 | protected function mockSetDefaultObjectStates()  | 
            ||
| 5876 | |||
| 5877 | /**  | 
            ||
| 5878 | * @param int|null $publicationDate  | 
            ||
| 5879 | * @param int|null $modificationDate  | 
            ||
| 5880 | * @param bool $isHidden  | 
            ||
| 5881 | *  | 
            ||
| 5882 | * @return \eZ\Publish\API\Repository\Values\Content\Content  | 
            ||
| 5883 | */  | 
            ||
| 5884 | protected function mockPublishVersion($publicationDate = null, $modificationDate = null, $isHidden = false)  | 
            ||
| 5960 | |||
| 5961 | /**  | 
            ||
| 5962 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content  | 
            ||
| 5963 | */  | 
            ||
| 5964 | protected function mockPublishUrlAliasesForContent(APIContent $content)  | 
            ||
| 6010 | |||
| 6011 | protected $domainMapperMock;  | 
            ||
| 6012 | |||
| 6013 | /**  | 
            ||
| 6014 | * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Repository\Helper\DomainMapper  | 
            ||
| 6015 | */  | 
            ||
| 6016 | protected function getDomainMapperMock()  | 
            ||
| 6024 | |||
| 6025 | protected $relationProcessorMock;  | 
            ||
| 6026 | |||
| 6027 | /**  | 
            ||
| 6028 | * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Repository\Helper\RelationProcessor  | 
            ||
| 6029 | */  | 
            ||
| 6030 | protected function getRelationProcessorMock()  | 
            ||
| 6038 | |||
| 6039 | protected $nameSchemaServiceMock;  | 
            ||
| 6040 | |||
| 6041 | /**  | 
            ||
| 6042 | * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Repository\Helper\NameSchemaService  | 
            ||
| 6043 | */  | 
            ||
| 6044 | protected function getNameSchemaServiceMock()  | 
            ||
| 6052 | |||
| 6053 | protected $contentTypeServiceMock;  | 
            ||
| 6054 | |||
| 6055 | /**  | 
            ||
| 6056 | * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\API\Repository\ContentTypeService  | 
            ||
| 6057 | */  | 
            ||
| 6058 | protected function getContentTypeServiceMock()  | 
            ||
| 6066 | |||
| 6067 | protected $locationServiceMock;  | 
            ||
| 6068 | |||
| 6069 | /**  | 
            ||
| 6070 | * @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\API\Repository\LocationService  | 
            ||
| 6071 | */  | 
            ||
| 6072 | protected function getLocationServiceMock()  | 
            ||
| 6080 | |||
| 6081 | /** @var \eZ\Publish\Core\Repository\ContentService */  | 
            ||
| 6082 | protected $partlyMockedContentService;  | 
            ||
| 6083 | |||
| 6084 | /**  | 
            ||
| 6085 | * Returns the content service to test with $methods mocked.  | 
            ||
| 6086 | *  | 
            ||
| 6087 |      * Injected Repository comes from {@see getRepositoryMock()} and persistence handler from {@see getPersistenceMock()} | 
            ||
| 6088 | *  | 
            ||
| 6089 | * @param string[] $methods  | 
            ||
| 6090 | *  | 
            ||
| 6091 | * @return \eZ\Publish\Core\Repository\ContentService|\PHPUnit\Framework\MockObject\MockObject  | 
            ||
| 6092 | */  | 
            ||
| 6093 | protected function getPartlyMockedContentService(array $methods = null)  | 
            ||
| 6115 | |||
| 6116 | /**  | 
            ||
| 6117 | * @return \eZ\Publish\API\Repository\Repository|\PHPUnit\Framework\MockObject\MockObject  | 
            ||
| 6118 | */  | 
            ||
| 6119 | protected function getRepositoryMock(): Repository  | 
            ||
| 6129 | }  | 
            ||
| 6130 | 
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.