Skip to content

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

Merged
merged 6 commits into from
Nov 22, 2015
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 115 additions & 2 deletions tests/Versioning/VersionHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -310,6 +312,119 @@ public function testDeleteUnexistingVersion()
$history->removeVersion('unexisting');
}

/**
* Load Version by label
*/
Copy link
Member

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.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use leading \ to not confuse IDEs that think this could be a relative path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test also depends on testAddLabel to succeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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'));
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please only one blank line between tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
*
Expand All @@ -328,6 +443,4 @@ protected function versionExists($history, $versionName)

return false;
}

// TODO: missing addVersionlabel, getVersionByLabel, getVersionLabels, hasVersionLabel, removeVersionLabel
}