Skip to content

Commit 33ca88f

Browse files
danrotdbu
authored andcommitted
added test cases for version restore
1 parent cc66a3d commit 33ca88f

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

tests/Versioning/VersionManagerTest.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111

1212
namespace PHPCR\Tests\Versioning;
1313

14+
use PHPCR\Version\VersionManagerInterface;
15+
1416
/**
1517
* Testing version manager functions.
1618
*
1719
* Covering jcr-2.8.3 spec $15.1
1820
*/
1921
class VersionManagerTest extends \PHPCR\Test\BaseCase
2022
{
23+
/**
24+
* @var VersionManagerInterface
25+
*/
26+
private $vm;
27+
2128
public static function setupBeforeClass($fixtures = '15_Versioning/base')
2229
{
2330
parent::setupBeforeClass($fixtures);
@@ -282,6 +289,137 @@ public function testRestorePendingChanges()
282289
$this->vm->restore(true, $version);
283290
}
284291

292+
public function testRestoreWithDeletedProperties()
293+
{
294+
$nodePath = '/tests_version_base/versioned';
295+
$version = $this->vm->checkpoint($nodePath);
296+
$this->vm->checkout($nodePath);
297+
298+
$node = $this->session->getNode($nodePath);
299+
$node->getProperty('foo')->remove();
300+
301+
$this->session->save();
302+
303+
$this->assertFalse($node->hasProperty('foo'));
304+
305+
$this->vm->restore(true, $version);
306+
$node = $this->session->getNode($nodePath);
307+
308+
$this->assertTrue($node->hasProperty('foo'));
309+
}
310+
311+
public function testRestoreWithNewProperties()
312+
{
313+
$nodePath = '/tests_version_base/versioned';
314+
$version = $this->vm->checkpoint($nodePath);
315+
$this->vm->checkout($nodePath);
316+
317+
$node = $this->session->getNode($nodePath);
318+
$node->setProperty('bar', 'value');
319+
320+
$this->session->save();
321+
322+
$this->assertTrue($node->hasProperty('bar'));
323+
324+
$this->vm->restore(true, $version);
325+
$node = $this->session->getNode($nodePath);
326+
327+
$this->assertFalse($node->hasProperty('bar'));
328+
}
329+
330+
public function testRestoreIsCheckedIn()
331+
{
332+
$nodePath = '/tests_version_base/versioned';
333+
$version = $this->vm->checkpoint($nodePath);
334+
335+
$this->vm->checkout($nodePath);
336+
$this->assertTrue($this->vm->isCheckedOut($nodePath));
337+
338+
$this->vm->restore(true, $version);
339+
$this->assertFalse($this->vm->isCheckedOut($nodePath));
340+
}
341+
342+
public function testRestoreBaseProperties()
343+
{
344+
// TODO also check for primary node type once it can be changed
345+
346+
$nodePath = '/tests_version_base/versioned';
347+
$version = $this->vm->checkpoint($nodePath);
348+
$this->vm->checkout($nodePath);
349+
350+
$node = $this->session->getNode($nodePath);
351+
$node->addMixin('mix:created');
352+
353+
$this->session->save();
354+
355+
$node = $this->session->getNode($nodePath);
356+
$this->assertContains('mix:created', $node->getPropertyValue('jcr:mixinTypes'));
357+
$this->assertTrue($node->hasProperty('jcr:created'));
358+
359+
$this->vm->restore(true, $version);
360+
361+
$node = $this->session->getNode($nodePath);
362+
$this->assertEquals(array('mix:versionable'), $node->getPropertyValue('jcr:mixinTypes'));
363+
$this->assertFalse($node->hasProperty('jcr:created'));
364+
}
365+
366+
public function testRestoreWithChildren()
367+
{
368+
$nodePath = '/tests_version_base/versioned';
369+
$this->vm->checkout($nodePath);
370+
$node = $this->session->getNode($nodePath);
371+
$childNode1 = $node->addNode('childNode1');
372+
$childNode1->setProperty('foo', 'child1');
373+
$childNode2 = $node->addNode('childNode2');
374+
$childNode2->setProperty('foo', 'child2');
375+
$childNode3 = $childNode1->addNode('childNode3');
376+
377+
$this->session->save();
378+
$version = $this->vm->checkin($nodePath);
379+
380+
$this->assertCount(2, $node->getNodes());
381+
$this->assertEquals('child1', $node->getNode('childNode1')->getPropertyValue('foo'));
382+
$this->assertEquals('child2', $node->getNode('childNode2')->getPropertyValue('foo'));
383+
384+
$this->assertCount(1, $node->getNode('childNode1')->getNodes());
385+
386+
$this->vm->checkout($nodePath);
387+
388+
$childNode1->remove();
389+
$childNode2->setProperty('foo', 'child1');
390+
391+
$this->session->save();
392+
393+
$this->assertCount(1, $node->getNodes());
394+
$this->assertEquals('child1', $node->getNode('childNode2')->getPropertyValue('foo'));
395+
396+
$this->vm->restore(true, $version);
397+
$node = $this->session->getNode($nodePath);
398+
399+
$this->assertCount(2, $node->getNodes());
400+
$this->assertEquals('child1', $node->getNode('childNode1')->getPropertyValue('foo'));
401+
$this->assertEquals('child2', $node->getNode('childNode2')->getPropertyValue('foo'));
402+
$this->assertCount(1, $node->getNode('childNode1')->getNodes());
403+
}
404+
405+
public function testRestoreWithNewChildren()
406+
{
407+
$nodePath = '/tests_version_base/versioned';
408+
$version = $this->vm->checkin($nodePath);
409+
$this->vm->checkout($nodePath);
410+
$node = $this->session->getNode($nodePath);
411+
$node->addNode('newChildNode');
412+
$this->session->save();
413+
414+
$node = $this->session->getNode($nodePath);
415+
$this->assertTrue($node->hasNode('newChildNode'));
416+
417+
$this->vm->restore(true, $version);
418+
$node = $this->session->getNode($nodePath);
419+
420+
$this->assertFalse($node->hasNode('newChildNode'));
421+
}
422+
285423
// TODO: test restore with removeExisting false and having an id clash
286424

287425
// TODO: testRestoreByVersionArray, testRestoreVersionToPath, testRestoreVersionToExistingPath (expect exception)

0 commit comments

Comments
 (0)