From 1cb6563e5ed66ff0fb07ed8979c0720a6bcfc0dd Mon Sep 17 00:00:00 2001 From: Markus Schmucker Date: Wed, 18 Nov 2015 12:02:44 +0100 Subject: [PATCH 1/6] added tests for version label support. --- tests/Versioning/VersionHistoryTest.php | 121 ++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/tests/Versioning/VersionHistoryTest.php b/tests/Versioning/VersionHistoryTest.php index cf4db720..b48af382 100644 --- a/tests/Versioning/VersionHistoryTest.php +++ b/tests/Versioning/VersionHistoryTest.php @@ -11,6 +11,8 @@ namespace PHPCR\Tests\Versioning; +use Jackalope\Property; +use PHPCR\PathNotFoundException; use PHPCR\Util\PathHelper; use PHPCR\Version\VersionHistoryInterface; use PHPCR\Version\VersionManagerInterface; @@ -310,6 +312,125 @@ public function testDeleteUnexistingVersion() $history->removeVersion('unexisting'); } + /** + * Load Version by label + */ + public function testGetVersionByLabel() + { + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); + $history->addVersionLabel('1.0','stable',false); + + $expectedVersion = $history->getVersion('1.0'); + $actualVersion = $history->getVersionByLabel('stable'); + + $this->assertEquals($expectedVersion->getIdentifier(), $actualVersion->getIdentifier()); + } + + + /** + * Try to load Version by unexisting label + * @expectedException PHPCR\Version\VersionException + */ + public function testUnexistingGetVersionByLabel() + { + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); + + $history->getVersionByLabel('definitlyNotSetLabel'); + + } + + /** + * Try to add label to a version + */ + public function testAddLabel() + { + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); + $history->addVersionLabel('1.0','stable',false); + $node = $history->getNode('jcr:versionLabels'); + try { + $property = $node->getProperty('stable'); + + } catch(PathNotFoundException $e) { + $this->fail('the path "stable" should be found'); + } + } + + /** + * Try to check, if version has label + */ + public function testHasVersionLabel() + { + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); + $history->addVersionLabel('1.0','stable',false); + $history->addVersionLabel('1.0','labelname',false); + $history->addVersionLabel('1.1','anotherlabelname',false); + + $version = $history->getVersion('1.0'); + + + $this->assertFalse($history->hasVersionLabel('unsetlabel')); + $this->assertFalse($history->hasVersionLabel('unsetlabel',$version)); + + $this->assertTrue($history->hasVersionLabel('stable')); + $this->assertTrue($history->hasVersionLabel('stable',$version)); + + $this->assertFalse($history->hasVersionLabel('anotherlabelname',$version)); + $this->assertFalse($history->hasVersionLabel('unsetlabel',$version)); + + } + + /** + * Try to get labels from version history + */ + public function testGetVersionLabels() + { + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); + $history->addVersionLabel('1.0','stable',false); + $history->addVersionLabel('1.0','labelname',false); + $history->addVersionLabel('1.1','anotherlabelname',false); + + $version = $history->getVersion('1.0'); + + $labels = $history->getVersionLabels($version); + $this->assertEquals(2, count($labels)); + $this->assertTrue(in_array('stable',$labels)); + $this->assertTrue(in_array('labelname',$labels)); + + $labels = $history->getVersionLabels(); + $this->assertEquals(3, count($labels)); + $this->assertTrue(in_array('stable',$labels)); + $this->assertTrue(in_array('labelname',$labels)); + $this->assertTrue(in_array('anotherlabelname',$labels)); + } + + /** + * removes label from a version + */ + public function testRemoveLabel() + { + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); + $history->addVersionLabel('1.0','toremove',false); + + $history->removeVersionLabel('toremove'); + + $this->assertFalse($history->hasVersionLabel('toremove')); + + + + } + + + /** + * Try to remove unset label from a version. + * @expectedException \PHPCR\Version\VersionException + */ + public function testRemoveUnsetLabel() + { + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); + $history->removeVersionLabel('unsetLabel'); + } + + /** * Check if a version node with the given name exists in the version history. * From 0306add55eb914a18b01f48bd63c22fbf94d0ac8 Mon Sep 17 00:00:00 2001 From: Markus Schmucker Date: Wed, 18 Nov 2015 12:11:58 +0100 Subject: [PATCH 2/6] fixed StyleCI --- tests/Versioning/VersionHistoryTest.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/Versioning/VersionHistoryTest.php b/tests/Versioning/VersionHistoryTest.php index b48af382..df023d05 100644 --- a/tests/Versioning/VersionHistoryTest.php +++ b/tests/Versioning/VersionHistoryTest.php @@ -318,7 +318,7 @@ public function testDeleteUnexistingVersion() public function testGetVersionByLabel() { $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); - $history->addVersionLabel('1.0','stable',false); + $history->addVersionLabel('1.0', 'stable', false); $expectedVersion = $history->getVersion('1.0'); $actualVersion = $history->getVersionByLabel('stable'); @@ -345,7 +345,7 @@ public function testUnexistingGetVersionByLabel() public function testAddLabel() { $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); - $history->addVersionLabel('1.0','stable',false); + $history->addVersionLabel('1.0', 'stable', false); $node = $history->getNode('jcr:versionLabels'); try { $property = $node->getProperty('stable'); @@ -361,9 +361,9 @@ public function testAddLabel() public function testHasVersionLabel() { $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); - $history->addVersionLabel('1.0','stable',false); - $history->addVersionLabel('1.0','labelname',false); - $history->addVersionLabel('1.1','anotherlabelname',false); + $history->addVersionLabel('1.0', 'stable', false); + $history->addVersionLabel('1.0', 'labelname', false); + $history->addVersionLabel('1.1', 'anotherlabelname', false); $version = $history->getVersion('1.0'); @@ -385,9 +385,9 @@ public function testHasVersionLabel() public function testGetVersionLabels() { $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); - $history->addVersionLabel('1.0','stable',false); - $history->addVersionLabel('1.0','labelname',false); - $history->addVersionLabel('1.1','anotherlabelname',false); + $history->addVersionLabel('1.0', 'stable', false); + $history->addVersionLabel('1.0', 'labelname', false); + $history->addVersionLabel('1.1', 'anotherlabelname', false); $version = $history->getVersion('1.0'); @@ -409,7 +409,7 @@ public function testGetVersionLabels() public function testRemoveLabel() { $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); - $history->addVersionLabel('1.0','toremove',false); + $history->addVersionLabel('1.0', 'toremove', false); $history->removeVersionLabel('toremove'); @@ -450,5 +450,4 @@ protected function versionExists($history, $versionName) return false; } - // TODO: missing addVersionlabel, getVersionByLabel, getVersionLabels, hasVersionLabel, removeVersionLabel } From 16d26484faaedc0c2df47e78f131d474c923fc6d Mon Sep 17 00:00:00 2001 From: Markus Schmucker Date: Wed, 18 Nov 2015 12:21:09 +0100 Subject: [PATCH 3/6] StyleCI --- tests/Versioning/VersionHistoryTest.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/Versioning/VersionHistoryTest.php b/tests/Versioning/VersionHistoryTest.php index df023d05..29764601 100644 --- a/tests/Versioning/VersionHistoryTest.php +++ b/tests/Versioning/VersionHistoryTest.php @@ -336,7 +336,6 @@ public function testUnexistingGetVersionByLabel() $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); $history->getVersionByLabel('definitlyNotSetLabel'); - } /** @@ -350,7 +349,7 @@ public function testAddLabel() try { $property = $node->getProperty('stable'); - } catch(PathNotFoundException $e) { + } catch (PathNotFoundException $e) { $this->fail('the path "stable" should be found'); } } @@ -369,13 +368,13 @@ public function testHasVersionLabel() $this->assertFalse($history->hasVersionLabel('unsetlabel')); - $this->assertFalse($history->hasVersionLabel('unsetlabel',$version)); + $this->assertFalse($history->hasVersionLabel('unsetlabel', $version)); $this->assertTrue($history->hasVersionLabel('stable')); - $this->assertTrue($history->hasVersionLabel('stable',$version)); + $this->assertTrue($history->hasVersionLabel('stable', $version)); - $this->assertFalse($history->hasVersionLabel('anotherlabelname',$version)); - $this->assertFalse($history->hasVersionLabel('unsetlabel',$version)); + $this->assertFalse($history->hasVersionLabel('anotherlabelname', $version)); + $this->assertFalse($history->hasVersionLabel('unsetlabel', $version)); } @@ -393,14 +392,14 @@ public function testGetVersionLabels() $labels = $history->getVersionLabels($version); $this->assertEquals(2, count($labels)); - $this->assertTrue(in_array('stable',$labels)); - $this->assertTrue(in_array('labelname',$labels)); + $this->assertTrue(in_array('stable', $labels)); + $this->assertTrue(in_array('labelname', $labels)); $labels = $history->getVersionLabels(); $this->assertEquals(3, count($labels)); - $this->assertTrue(in_array('stable',$labels)); - $this->assertTrue(in_array('labelname',$labels)); - $this->assertTrue(in_array('anotherlabelname',$labels)); + $this->assertTrue(in_array('stable', $labels)); + $this->assertTrue(in_array('labelname', $labels)); + $this->assertTrue(in_array('anotherlabelname', $labels)); } /** @@ -414,9 +413,6 @@ public function testRemoveLabel() $history->removeVersionLabel('toremove'); $this->assertFalse($history->hasVersionLabel('toremove')); - - - } From ff2e765c6430e4a929e11939142ba7c34c60e6b7 Mon Sep 17 00:00:00 2001 From: Markus Schmucker Date: Wed, 18 Nov 2015 12:23:34 +0100 Subject: [PATCH 4/6] StyleCI --- tests/Versioning/VersionHistoryTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Versioning/VersionHistoryTest.php b/tests/Versioning/VersionHistoryTest.php index 29764601..26aebae1 100644 --- a/tests/Versioning/VersionHistoryTest.php +++ b/tests/Versioning/VersionHistoryTest.php @@ -348,7 +348,6 @@ public function testAddLabel() $node = $history->getNode('jcr:versionLabels'); try { $property = $node->getProperty('stable'); - } catch (PathNotFoundException $e) { $this->fail('the path "stable" should be found'); } @@ -375,7 +374,6 @@ public function testHasVersionLabel() $this->assertFalse($history->hasVersionLabel('anotherlabelname', $version)); $this->assertFalse($history->hasVersionLabel('unsetlabel', $version)); - } /** From ba0926a2b70b4596497bf08a980fa234c33d2fa6 Mon Sep 17 00:00:00 2001 From: Markus Schmucker Date: Wed, 18 Nov 2015 12:25:36 +0100 Subject: [PATCH 5/6] StyleCI --- tests/Versioning/VersionHistoryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Versioning/VersionHistoryTest.php b/tests/Versioning/VersionHistoryTest.php index 26aebae1..c48f06af 100644 --- a/tests/Versioning/VersionHistoryTest.php +++ b/tests/Versioning/VersionHistoryTest.php @@ -443,5 +443,4 @@ protected function versionExists($history, $versionName) return false; } - } From 148b8f65af6d850db4fee267f25c25278cd35ab4 Mon Sep 17 00:00:00 2001 From: Markus Schmucker Date: Fri, 20 Nov 2015 12:04:24 +0100 Subject: [PATCH 6/6] - added some @depends annotations in tests/Versioning/VersionHistoryTest.php - fixed some code formating issues --- tests/Versioning/VersionHistoryTest.php | 46 ++++++++++++++----------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/tests/Versioning/VersionHistoryTest.php b/tests/Versioning/VersionHistoryTest.php index c48f06af..23124515 100644 --- a/tests/Versioning/VersionHistoryTest.php +++ b/tests/Versioning/VersionHistoryTest.php @@ -125,7 +125,6 @@ public function testGetAllLinearVersions() $this->assertCount(1, $lastVersion->getPredecessors()); $this->assertCount(0, $lastVersion->getSuccessors()); } - public function testGetAllVersions() { // TODO: have non linear version history @@ -150,7 +149,6 @@ public function testGetAllVersions() $this->assertCount(1, $lastVersion->getPredecessors()); $this->assertCount(0, $lastVersion->getSuccessors()); } - /** * Check version history (allVersions), add more versions, then check the history updates correctly. */ @@ -312,24 +310,9 @@ public function testDeleteUnexistingVersion() $history->removeVersion('unexisting'); } - /** - * Load Version by label - */ - public function testGetVersionByLabel() - { - $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); - $history->addVersionLabel('1.0', 'stable', false); - - $expectedVersion = $history->getVersion('1.0'); - $actualVersion = $history->getVersionByLabel('stable'); - - $this->assertEquals($expectedVersion->getIdentifier(), $actualVersion->getIdentifier()); - } - - /** * Try to load Version by unexisting label - * @expectedException PHPCR\Version\VersionException + * @expectedException \PHPCR\Version\VersionException */ public function testUnexistingGetVersionByLabel() { @@ -345,6 +328,8 @@ public function testAddLabel() { $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); $history->addVersionLabel('1.0', 'stable', false); + $history->setChildrenDirty(); + $node = $history->getNode('jcr:versionLabels'); try { $property = $node->getProperty('stable'); @@ -353,8 +338,26 @@ public function testAddLabel() } } + /** + * Load Version by label + * + * @depends testAddLabel + */ + public function testGetVersionByLabel() + { + $history = $this->vm->getVersionHistory('/tests_version_base/versioned'); + $history->addVersionLabel('1.0', 'stable', false); + + $expectedVersion = $history->getVersion('1.0'); + $actualVersion = $history->getVersionByLabel('stable'); + + $this->assertEquals($expectedVersion->getIdentifier(), $actualVersion->getIdentifier()); + } + /** * Try to check, if version has label + * + * @depends testAddLabel */ public function testHasVersionLabel() { @@ -365,7 +368,6 @@ public function testHasVersionLabel() $version = $history->getVersion('1.0'); - $this->assertFalse($history->hasVersionLabel('unsetlabel')); $this->assertFalse($history->hasVersionLabel('unsetlabel', $version)); @@ -378,6 +380,8 @@ public function testHasVersionLabel() /** * Try to get labels from version history + * + * @depends testAddLabel */ public function testGetVersionLabels() { @@ -402,6 +406,8 @@ public function testGetVersionLabels() /** * removes label from a version + * + * @depends testAddLabel */ public function testRemoveLabel() { @@ -413,7 +419,6 @@ public function testRemoveLabel() $this->assertFalse($history->hasVersionLabel('toremove')); } - /** * Try to remove unset label from a version. * @expectedException \PHPCR\Version\VersionException @@ -424,7 +429,6 @@ public function testRemoveUnsetLabel() $history->removeVersionLabel('unsetLabel'); } - /** * Check if a version node with the given name exists in the version history. *