Skip to content

Added some tests for version restore functionality #166

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 1 commit into from
Oct 9, 2015
Merged
Changes from all 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
138 changes: 138 additions & 0 deletions tests/Versioning/VersionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@

namespace PHPCR\Tests\Versioning;

use PHPCR\Version\VersionManagerInterface;

/**
* Testing version manager functions.
*
* Covering jcr-2.8.3 spec $15.1
*/
class VersionManagerTest extends \PHPCR\Test\BaseCase
{
/**
* @var VersionManagerInterface
*/
private $vm;

public static function setupBeforeClass($fixtures = '15_Versioning/base')
{
parent::setupBeforeClass($fixtures);
Expand Down Expand Up @@ -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)
Expand Down