Skip to content

Commit 92b5028

Browse files
committed
Merge pull request #175 from markussr/master
added tests for version label support.
2 parents 47c9eaf + 148b8f6 commit 92b5028

File tree

1 file changed

+121
-4
lines changed

1 file changed

+121
-4
lines changed

tests/Versioning/VersionHistoryTest.php

+121-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace PHPCR\Tests\Versioning;
1313

14+
use Jackalope\Property;
15+
use PHPCR\PathNotFoundException;
1416
use PHPCR\Util\PathHelper;
1517
use PHPCR\Version\VersionHistoryInterface;
1618
use PHPCR\Version\VersionManagerInterface;
@@ -123,7 +125,6 @@ public function testGetAllLinearVersions()
123125
$this->assertCount(1, $lastVersion->getPredecessors());
124126
$this->assertCount(0, $lastVersion->getSuccessors());
125127
}
126-
127128
public function testGetAllVersions()
128129
{
129130
// TODO: have non linear version history
@@ -148,7 +149,6 @@ public function testGetAllVersions()
148149
$this->assertCount(1, $lastVersion->getPredecessors());
149150
$this->assertCount(0, $lastVersion->getSuccessors());
150151
}
151-
152152
/**
153153
* Check version history (allVersions), add more versions, then check the history updates correctly.
154154
*/
@@ -310,6 +310,125 @@ public function testDeleteUnexistingVersion()
310310
$history->removeVersion('unexisting');
311311
}
312312

313+
/**
314+
* Try to load Version by unexisting label
315+
* @expectedException \PHPCR\Version\VersionException
316+
*/
317+
public function testUnexistingGetVersionByLabel()
318+
{
319+
$history = $this->vm->getVersionHistory('/tests_version_base/versioned');
320+
321+
$history->getVersionByLabel('definitlyNotSetLabel');
322+
}
323+
324+
/**
325+
* Try to add label to a version
326+
*/
327+
public function testAddLabel()
328+
{
329+
$history = $this->vm->getVersionHistory('/tests_version_base/versioned');
330+
$history->addVersionLabel('1.0', 'stable', false);
331+
$history->setChildrenDirty();
332+
333+
$node = $history->getNode('jcr:versionLabels');
334+
try {
335+
$property = $node->getProperty('stable');
336+
} catch (PathNotFoundException $e) {
337+
$this->fail('the path "stable" should be found');
338+
}
339+
}
340+
341+
/**
342+
* Load Version by label
343+
*
344+
* @depends testAddLabel
345+
*/
346+
public function testGetVersionByLabel()
347+
{
348+
$history = $this->vm->getVersionHistory('/tests_version_base/versioned');
349+
$history->addVersionLabel('1.0', 'stable', false);
350+
351+
$expectedVersion = $history->getVersion('1.0');
352+
$actualVersion = $history->getVersionByLabel('stable');
353+
354+
$this->assertEquals($expectedVersion->getIdentifier(), $actualVersion->getIdentifier());
355+
}
356+
357+
/**
358+
* Try to check, if version has label
359+
*
360+
* @depends testAddLabel
361+
*/
362+
public function testHasVersionLabel()
363+
{
364+
$history = $this->vm->getVersionHistory('/tests_version_base/versioned');
365+
$history->addVersionLabel('1.0', 'stable', false);
366+
$history->addVersionLabel('1.0', 'labelname', false);
367+
$history->addVersionLabel('1.1', 'anotherlabelname', false);
368+
369+
$version = $history->getVersion('1.0');
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+
* Try to get labels from version history
383+
*
384+
* @depends testAddLabel
385+
*/
386+
public function testGetVersionLabels()
387+
{
388+
$history = $this->vm->getVersionHistory('/tests_version_base/versioned');
389+
$history->addVersionLabel('1.0', 'stable', false);
390+
$history->addVersionLabel('1.0', 'labelname', false);
391+
$history->addVersionLabel('1.1', 'anotherlabelname', false);
392+
393+
$version = $history->getVersion('1.0');
394+
395+
$labels = $history->getVersionLabels($version);
396+
$this->assertEquals(2, count($labels));
397+
$this->assertTrue(in_array('stable', $labels));
398+
$this->assertTrue(in_array('labelname', $labels));
399+
400+
$labels = $history->getVersionLabels();
401+
$this->assertEquals(3, count($labels));
402+
$this->assertTrue(in_array('stable', $labels));
403+
$this->assertTrue(in_array('labelname', $labels));
404+
$this->assertTrue(in_array('anotherlabelname', $labels));
405+
}
406+
407+
/**
408+
* removes label from a version
409+
*
410+
* @depends testAddLabel
411+
*/
412+
public function testRemoveLabel()
413+
{
414+
$history = $this->vm->getVersionHistory('/tests_version_base/versioned');
415+
$history->addVersionLabel('1.0', 'toremove', false);
416+
417+
$history->removeVersionLabel('toremove');
418+
419+
$this->assertFalse($history->hasVersionLabel('toremove'));
420+
}
421+
422+
/**
423+
* Try to remove unset label from a version.
424+
* @expectedException \PHPCR\Version\VersionException
425+
*/
426+
public function testRemoveUnsetLabel()
427+
{
428+
$history = $this->vm->getVersionHistory('/tests_version_base/versioned');
429+
$history->removeVersionLabel('unsetLabel');
430+
}
431+
313432
/**
314433
* Check if a version node with the given name exists in the version history.
315434
*
@@ -328,6 +447,4 @@ protected function versionExists($history, $versionName)
328447

329448
return false;
330449
}
331-
332-
// TODO: missing addVersionlabel, getVersionByLabel, getVersionLabels, hasVersionLabel, removeVersionLabel
333450
}

0 commit comments

Comments
 (0)