From 33ca88f9b90862966eb5e6f93c37261f9028e11d Mon Sep 17 00:00:00 2001 From: Daniel Rotter Date: Thu, 11 Jun 2015 15:21:25 +0200 Subject: [PATCH] added test cases for version restore --- tests/Versioning/VersionManagerTest.php | 138 ++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/tests/Versioning/VersionManagerTest.php b/tests/Versioning/VersionManagerTest.php index e2ab3048..026b8646 100644 --- a/tests/Versioning/VersionManagerTest.php +++ b/tests/Versioning/VersionManagerTest.php @@ -11,6 +11,8 @@ namespace PHPCR\Tests\Versioning; +use PHPCR\Version\VersionManagerInterface; + /** * Testing version manager functions. * @@ -18,6 +20,11 @@ */ class VersionManagerTest extends \PHPCR\Test\BaseCase { + /** + * @var VersionManagerInterface + */ + private $vm; + public static function setupBeforeClass($fixtures = '15_Versioning/base') { parent::setupBeforeClass($fixtures); @@ -282,6 +289,137 @@ public function testRestorePendingChanges() $this->vm->restore(true, $version); } + public function testRestoreWithDeletedProperties() + { + $nodePath = '/tests_version_base/versioned'; + $version = $this->vm->checkpoint($nodePath); + $this->vm->checkout($nodePath); + + $node = $this->session->getNode($nodePath); + $node->getProperty('foo')->remove(); + + $this->session->save(); + + $this->assertFalse($node->hasProperty('foo')); + + $this->vm->restore(true, $version); + $node = $this->session->getNode($nodePath); + + $this->assertTrue($node->hasProperty('foo')); + } + + public function testRestoreWithNewProperties() + { + $nodePath = '/tests_version_base/versioned'; + $version = $this->vm->checkpoint($nodePath); + $this->vm->checkout($nodePath); + + $node = $this->session->getNode($nodePath); + $node->setProperty('bar', 'value'); + + $this->session->save(); + + $this->assertTrue($node->hasProperty('bar')); + + $this->vm->restore(true, $version); + $node = $this->session->getNode($nodePath); + + $this->assertFalse($node->hasProperty('bar')); + } + + public function testRestoreIsCheckedIn() + { + $nodePath = '/tests_version_base/versioned'; + $version = $this->vm->checkpoint($nodePath); + + $this->vm->checkout($nodePath); + $this->assertTrue($this->vm->isCheckedOut($nodePath)); + + $this->vm->restore(true, $version); + $this->assertFalse($this->vm->isCheckedOut($nodePath)); + } + + public function testRestoreBaseProperties() + { + // TODO also check for primary node type once it can be changed + + $nodePath = '/tests_version_base/versioned'; + $version = $this->vm->checkpoint($nodePath); + $this->vm->checkout($nodePath); + + $node = $this->session->getNode($nodePath); + $node->addMixin('mix:created'); + + $this->session->save(); + + $node = $this->session->getNode($nodePath); + $this->assertContains('mix:created', $node->getPropertyValue('jcr:mixinTypes')); + $this->assertTrue($node->hasProperty('jcr:created')); + + $this->vm->restore(true, $version); + + $node = $this->session->getNode($nodePath); + $this->assertEquals(array('mix:versionable'), $node->getPropertyValue('jcr:mixinTypes')); + $this->assertFalse($node->hasProperty('jcr:created')); + } + + public function testRestoreWithChildren() + { + $nodePath = '/tests_version_base/versioned'; + $this->vm->checkout($nodePath); + $node = $this->session->getNode($nodePath); + $childNode1 = $node->addNode('childNode1'); + $childNode1->setProperty('foo', 'child1'); + $childNode2 = $node->addNode('childNode2'); + $childNode2->setProperty('foo', 'child2'); + $childNode3 = $childNode1->addNode('childNode3'); + + $this->session->save(); + $version = $this->vm->checkin($nodePath); + + $this->assertCount(2, $node->getNodes()); + $this->assertEquals('child1', $node->getNode('childNode1')->getPropertyValue('foo')); + $this->assertEquals('child2', $node->getNode('childNode2')->getPropertyValue('foo')); + + $this->assertCount(1, $node->getNode('childNode1')->getNodes()); + + $this->vm->checkout($nodePath); + + $childNode1->remove(); + $childNode2->setProperty('foo', 'child1'); + + $this->session->save(); + + $this->assertCount(1, $node->getNodes()); + $this->assertEquals('child1', $node->getNode('childNode2')->getPropertyValue('foo')); + + $this->vm->restore(true, $version); + $node = $this->session->getNode($nodePath); + + $this->assertCount(2, $node->getNodes()); + $this->assertEquals('child1', $node->getNode('childNode1')->getPropertyValue('foo')); + $this->assertEquals('child2', $node->getNode('childNode2')->getPropertyValue('foo')); + $this->assertCount(1, $node->getNode('childNode1')->getNodes()); + } + + public function testRestoreWithNewChildren() + { + $nodePath = '/tests_version_base/versioned'; + $version = $this->vm->checkin($nodePath); + $this->vm->checkout($nodePath); + $node = $this->session->getNode($nodePath); + $node->addNode('newChildNode'); + $this->session->save(); + + $node = $this->session->getNode($nodePath); + $this->assertTrue($node->hasNode('newChildNode')); + + $this->vm->restore(true, $version); + $node = $this->session->getNode($nodePath); + + $this->assertFalse($node->hasNode('newChildNode')); + } + // TODO: test restore with removeExisting false and having an id clash // TODO: testRestoreByVersionArray, testRestoreVersionToPath, testRestoreVersionToExistingPath (expect exception)