| @@ 58-81 (lines=24) @@ | ||
| 55 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 56 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSection |
|
| 57 | */ |
|
| 58 | public function testLoadSectionThrowsUnauthorizedException() |
|
| 59 | { |
|
| 60 | $repository = $this->getRepository(); |
|
| 61 | ||
| 62 | $anonymousUserId = $this->generateId('user', 10); |
|
| 63 | /* BEGIN: Use Case */ |
|
| 64 | // $anonymousUserId is the ID of the "Anonymous" user in a eZ |
|
| 65 | // Publish demo installation. |
|
| 66 | $userService = $repository->getUserService(); |
|
| 67 | $sectionService = $repository->getSectionService(); |
|
| 68 | ||
| 69 | $sectionCreate = $sectionService->newSectionCreateStruct(); |
|
| 70 | $sectionCreate->name = 'Test Section'; |
|
| 71 | $sectionCreate->identifier = 'uniqueKey'; |
|
| 72 | ||
| 73 | $sectionId = $sectionService->createSection($sectionCreate)->id; |
|
| 74 | ||
| 75 | // Set anonymous user |
|
| 76 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 77 | ||
| 78 | // This call will fail with a "UnauthorizedException" |
|
| 79 | $sectionService->loadSection($sectionId); |
|
| 80 | /* END: Use Case */ |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Test for the updateSection() method. |
|
| @@ 90-117 (lines=28) @@ | ||
| 87 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 88 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
|
| 89 | */ |
|
| 90 | public function testUpdateSectionThrowsUnauthorizedException() |
|
| 91 | { |
|
| 92 | $repository = $this->getRepository(); |
|
| 93 | ||
| 94 | $standardSectionId = $this->generateId('section', 1); |
|
| 95 | $anonymousUserId = $this->generateId('user', 10); |
|
| 96 | /* BEGIN: Use Case */ |
|
| 97 | // $anonymousUserId is the ID of the "Anonymous" user in a eZ |
|
| 98 | // Publish demo installation. |
|
| 99 | // $standardSectionId is the ID of the "Standard" section in a eZ |
|
| 100 | // Publish demo installation. |
|
| 101 | ||
| 102 | $userService = $repository->getUserService(); |
|
| 103 | $sectionService = $repository->getSectionService(); |
|
| 104 | ||
| 105 | $section = $sectionService->loadSection($standardSectionId); |
|
| 106 | ||
| 107 | $sectionUpdate = $sectionService->newSectionUpdateStruct(); |
|
| 108 | $sectionUpdate->name = 'New section name'; |
|
| 109 | $sectionUpdate->identifier = 'newUniqueKey'; |
|
| 110 | ||
| 111 | // Set anonymous user |
|
| 112 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 113 | ||
| 114 | // This call will fail with a "UnauthorizedException" |
|
| 115 | $sectionService->updateSection($section, $sectionUpdate); |
|
| 116 | /* END: Use Case */ |
|
| 117 | } |
|
| 118 | ||
| 119 | /** |
|
| 120 | * Test for the loadSections() method. |
|
| @@ 235-258 (lines=24) @@ | ||
| 232 | * @see \eZ\Publish\API\Repository\SectionService::deleteSection() |
|
| 233 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 234 | */ |
|
| 235 | public function testDeleteSectionThrowsUnauthorizedException() |
|
| 236 | { |
|
| 237 | $repository = $this->getRepository(); |
|
| 238 | ||
| 239 | $anonymousUserId = $this->generateId('user', 10); |
|
| 240 | /* BEGIN: Use Case */ |
|
| 241 | // $anonymousUserId is the ID of the "Anonymous" user in a eZ |
|
| 242 | // Publish demo installation. |
|
| 243 | $userService = $repository->getUserService(); |
|
| 244 | $sectionService = $repository->getSectionService(); |
|
| 245 | ||
| 246 | $sectionCreate = $sectionService->newSectionCreateStruct(); |
|
| 247 | $sectionCreate->name = 'Test Section'; |
|
| 248 | $sectionCreate->identifier = 'uniqueKey'; |
|
| 249 | ||
| 250 | $section = $sectionService->createSection($sectionCreate); |
|
| 251 | ||
| 252 | // Set anonymous user |
|
| 253 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 254 | ||
| 255 | // This call will fail with a "UnauthorizedException" |
|
| 256 | $sectionService->deleteSection($section); |
|
| 257 | /* END: Use Case */ |
|
| 258 | } |
|
| 259 | } |
|
| 260 | ||
| @@ 200-227 (lines=28) @@ | ||
| 197 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSection |
|
| 198 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testNewSectionUpdateStruct |
|
| 199 | */ |
|
| 200 | public function testUpdateSection() |
|
| 201 | { |
|
| 202 | $repository = $this->getRepository(); |
|
| 203 | ||
| 204 | $standardSectionId = $this->generateId('section', 1); |
|
| 205 | /* BEGIN: Use Case */ |
|
| 206 | // $standardSectionId contains the ID of the "Standard" section in a eZ |
|
| 207 | // Publish demo installation. |
|
| 208 | ||
| 209 | $sectionService = $repository->getSectionService(); |
|
| 210 | ||
| 211 | $section = $sectionService->loadSection($standardSectionId); |
|
| 212 | ||
| 213 | $sectionUpdate = $sectionService->newSectionUpdateStruct(); |
|
| 214 | $sectionUpdate->name = 'New section name'; |
|
| 215 | $sectionUpdate->identifier = 'newUniqueKey'; |
|
| 216 | ||
| 217 | $updatedSection = $sectionService->updateSection($section, $sectionUpdate); |
|
| 218 | /* END: Use Case */ |
|
| 219 | ||
| 220 | // Verify that service returns an instance of Section |
|
| 221 | $this->assertInstanceOf('\\eZ\\Publish\\API\\Repository\\Values\\Content\\Section', $updatedSection); |
|
| 222 | ||
| 223 | // Verify that the service also persists the changes |
|
| 224 | $updatedSection = $sectionService->loadSection($standardSectionId); |
|
| 225 | ||
| 226 | $this->assertEquals('New section name', $updatedSection->name); |
|
| 227 | } |
|
| 228 | ||
| 229 | /** |
|
| 230 | * Test for the updateSection() method. |
|
| @@ 262-284 (lines=23) @@ | ||
| 259 | * @see \eZ\Publish\API\Repository\SectionService::updateSection() |
|
| 260 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
|
| 261 | */ |
|
| 262 | public function testUpdateSectionWithSectionIdentifierOnNameUpdate() |
|
| 263 | { |
|
| 264 | $repository = $this->getRepository(); |
|
| 265 | ||
| 266 | $standardSectionId = $this->generateId('section', 1); |
|
| 267 | /* BEGIN: Use Case */ |
|
| 268 | // $standardSectionId contains the ID of the "Standard" section in a eZ |
|
| 269 | // Publish demo installation. |
|
| 270 | ||
| 271 | $sectionService = $repository->getSectionService(); |
|
| 272 | ||
| 273 | $section = $sectionService->loadSection($standardSectionId); |
|
| 274 | $sectionUpdate = $sectionService->newSectionUpdateStruct(); |
|
| 275 | $sectionUpdate->name = 'New section name'; |
|
| 276 | ||
| 277 | // section identifier remains the same |
|
| 278 | $sectionUpdate->identifier = $section->identifier; |
|
| 279 | ||
| 280 | $updatedSection = $sectionService->updateSection($section, $sectionUpdate); |
|
| 281 | /* END: Use Case */ |
|
| 282 | ||
| 283 | $this->assertEquals('standard', $updatedSection->identifier); |
|
| 284 | } |
|
| 285 | ||
| 286 | /** |
|
| 287 | * Test for the updateSection() method. |
|
| @@ 321-348 (lines=28) @@ | ||
| 318 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 319 | * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testUpdateSection |
|
| 320 | */ |
|
| 321 | public function testUpdateSectionThrowsInvalidArgumentException() |
|
| 322 | { |
|
| 323 | $repository = $this->getRepository(); |
|
| 324 | ||
| 325 | $standardSectionId = $this->generateId('section', 1); |
|
| 326 | /* BEGIN: Use Case */ |
|
| 327 | // $standardSectionId contains the ID of the "Standard" section in a eZ |
|
| 328 | // Publish demo installation. |
|
| 329 | ||
| 330 | $sectionService = $repository->getSectionService(); |
|
| 331 | ||
| 332 | // Create section with conflict identifier |
|
| 333 | $sectionCreate = $sectionService->newSectionCreateStruct(); |
|
| 334 | $sectionCreate->name = 'Conflict section'; |
|
| 335 | $sectionCreate->identifier = 'conflictKey'; |
|
| 336 | ||
| 337 | $sectionService->createSection($sectionCreate); |
|
| 338 | ||
| 339 | // Load an existing section and update to an existing identifier |
|
| 340 | $section = $sectionService->loadSection($standardSectionId); |
|
| 341 | ||
| 342 | $sectionUpdate = $sectionService->newSectionUpdateStruct(); |
|
| 343 | $sectionUpdate->identifier = 'conflictKey'; |
|
| 344 | ||
| 345 | // This call should fail with an InvalidArgumentException |
|
| 346 | $sectionService->updateSection($section, $sectionUpdate); |
|
| 347 | /* END: Use Case */ |
|
| 348 | } |
|
| 349 | ||
| 350 | /** |
|
| 351 | * Test for the loadSections() method. |
|