-
Notifications
You must be signed in to change notification settings - Fork 21
added tests for version label support. #175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
1cb6563
0306add
16d2648
ff2e765
ba0926a
148b8f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,119 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use leading There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
*/ | ||
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 | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test also depends on testAddLabel to succeed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Is fixed |
||
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')); | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please only one blank line between tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is fixed |
||
/** | ||
* 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. | ||
* | ||
|
@@ -328,6 +443,4 @@ protected function versionExists($history, $versionName) | |
|
||
return false; | ||
} | ||
|
||
// TODO: missing addVersionlabel, getVersionByLabel, getVersionLabels, hasVersionLabel, removeVersionLabel | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add
@depends testAddLabel
? if adding the label does not work, this will fail for sure.