|
11 | 11 |
|
12 | 12 | namespace PHPCR\Tests\Versioning;
|
13 | 13 |
|
| 14 | +use Jackalope\Property; |
| 15 | +use PHPCR\PathNotFoundException; |
14 | 16 | use PHPCR\Util\PathHelper;
|
15 | 17 | use PHPCR\Version\VersionHistoryInterface;
|
16 | 18 | use PHPCR\Version\VersionManagerInterface;
|
@@ -310,6 +312,125 @@ public function testDeleteUnexistingVersion()
|
310 | 312 | $history->removeVersion('unexisting');
|
311 | 313 | }
|
312 | 314 |
|
| 315 | + /** |
| 316 | + * Load Version by label |
| 317 | + */ |
| 318 | + public function testGetVersionByLabel() |
| 319 | + { |
| 320 | + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); |
| 321 | + $history->addVersionLabel('1.0','stable',false); |
| 322 | + |
| 323 | + $expectedVersion = $history->getVersion('1.0'); |
| 324 | + $actualVersion = $history->getVersionByLabel('stable'); |
| 325 | + |
| 326 | + $this->assertEquals($expectedVersion->getIdentifier(), $actualVersion->getIdentifier()); |
| 327 | + } |
| 328 | + |
| 329 | + |
| 330 | + /** |
| 331 | + * Try to load Version by unexisting label |
| 332 | + * @expectedException PHPCR\Version\VersionException |
| 333 | + */ |
| 334 | + public function testUnexistingGetVersionByLabel() |
| 335 | + { |
| 336 | + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); |
| 337 | + |
| 338 | + $history->getVersionByLabel('definitlyNotSetLabel'); |
| 339 | + |
| 340 | + } |
| 341 | + |
| 342 | + /** |
| 343 | + * Try to add label to a version |
| 344 | + */ |
| 345 | + public function testAddLabel() |
| 346 | + { |
| 347 | + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); |
| 348 | + $history->addVersionLabel('1.0','stable',false); |
| 349 | + $node = $history->getNode('jcr:versionLabels'); |
| 350 | + try { |
| 351 | + $property = $node->getProperty('stable'); |
| 352 | + |
| 353 | + } catch(PathNotFoundException $e) { |
| 354 | + $this->fail('the path "stable" should be found'); |
| 355 | + } |
| 356 | + } |
| 357 | + |
| 358 | + /** |
| 359 | + * Try to check, if version has label |
| 360 | + */ |
| 361 | + public function testHasVersionLabel() |
| 362 | + { |
| 363 | + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); |
| 364 | + $history->addVersionLabel('1.0','stable',false); |
| 365 | + $history->addVersionLabel('1.0','labelname',false); |
| 366 | + $history->addVersionLabel('1.1','anotherlabelname',false); |
| 367 | + |
| 368 | + $version = $history->getVersion('1.0'); |
| 369 | + |
| 370 | + |
| 371 | + $this->assertFalse($history->hasVersionLabel('unsetlabel')); |
| 372 | + $this->assertFalse($history->hasVersionLabel('unsetlabel',$version)); |
| 373 | + |
| 374 | + $this->assertTrue($history->hasVersionLabel('stable')); |
| 375 | + $this->assertTrue($history->hasVersionLabel('stable',$version)); |
| 376 | + |
| 377 | + $this->assertFalse($history->hasVersionLabel('anotherlabelname',$version)); |
| 378 | + $this->assertFalse($history->hasVersionLabel('unsetlabel',$version)); |
| 379 | + |
| 380 | + } |
| 381 | + |
| 382 | + /** |
| 383 | + * Try to get labels from version history |
| 384 | + */ |
| 385 | + public function testGetVersionLabels() |
| 386 | + { |
| 387 | + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); |
| 388 | + $history->addVersionLabel('1.0','stable',false); |
| 389 | + $history->addVersionLabel('1.0','labelname',false); |
| 390 | + $history->addVersionLabel('1.1','anotherlabelname',false); |
| 391 | + |
| 392 | + $version = $history->getVersion('1.0'); |
| 393 | + |
| 394 | + $labels = $history->getVersionLabels($version); |
| 395 | + $this->assertEquals(2, count($labels)); |
| 396 | + $this->assertTrue(in_array('stable',$labels)); |
| 397 | + $this->assertTrue(in_array('labelname',$labels)); |
| 398 | + |
| 399 | + $labels = $history->getVersionLabels(); |
| 400 | + $this->assertEquals(3, count($labels)); |
| 401 | + $this->assertTrue(in_array('stable',$labels)); |
| 402 | + $this->assertTrue(in_array('labelname',$labels)); |
| 403 | + $this->assertTrue(in_array('anotherlabelname',$labels)); |
| 404 | + } |
| 405 | + |
| 406 | + /** |
| 407 | + * removes label from a version |
| 408 | + */ |
| 409 | + public function testRemoveLabel() |
| 410 | + { |
| 411 | + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); |
| 412 | + $history->addVersionLabel('1.0','toremove',false); |
| 413 | + |
| 414 | + $history->removeVersionLabel('toremove'); |
| 415 | + |
| 416 | + $this->assertFalse($history->hasVersionLabel('toremove')); |
| 417 | + |
| 418 | + |
| 419 | + |
| 420 | + } |
| 421 | + |
| 422 | + |
| 423 | + /** |
| 424 | + * Try to remove unset label from a version. |
| 425 | + * @expectedException \PHPCR\Version\VersionException |
| 426 | + */ |
| 427 | + public function testRemoveUnsetLabel() |
| 428 | + { |
| 429 | + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); |
| 430 | + $history->removeVersionLabel('unsetLabel'); |
| 431 | + } |
| 432 | + |
| 433 | + |
313 | 434 | /**
|
314 | 435 | * Check if a version node with the given name exists in the version history.
|
315 | 436 | *
|
|
0 commit comments