Skip to content

adding a test for simple versioning #157

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
May 14, 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
132 changes: 132 additions & 0 deletions tests/15_Versioning/SimpleVersionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
namespace PHPCR\Tests\Versioning;

use PHPCR\NodeInterface;
use PHPCR\Test\BaseCase;
use PHPCR\Version\VersionInterface;
use PHPCR\Version\VersionManagerInterface;

require_once(__DIR__ . '/../../inc/BaseCase.php');

/**
* Testing whether simple versioning works
*
* Covering jcr-283 spec $15.1
*/
class SimpleVersionTest extends BaseCase
{
/**
* @var VersionManagerInterface
*/
private $vm;

/**
* @var VersionInterface
*/
private $simpleVersioned;

public static function setupBeforeClass($fixtures = '15_Versioning/base')
{
parent::setupBeforeClass($fixtures);
}

public function setUp()
{
parent::setUp();

$this->vm = $this->session->getWorkspace()->getVersionManager();

$this->simpleVersioned = $this->vm->getBaseVersion('/tests_version_base/simpleVersioned');

$this->assertInstanceOf('PHPCR\Version\VersionInterface', $this->simpleVersioned);
}

public function testGetContainingHistory()
{
$this->assertSame($this->vm->getVersionHistory('/tests_version_base/simpleVersioned'), $this->simpleVersioned->getContainingHistory());
}

public function testGetCreated()
{
$date = $this->simpleVersioned->getCreated();
$diff = time() - $date->getTimestamp();
$this->assertTrue($diff < 60, 'creation date of the version we created in setupBeforeClass should be within the last few seconds');
}

public function testGetFrozenNode()
{
$frozen = $this->simpleVersioned->getFrozenNode();
$this->assertTrue($frozen->hasProperty('foo'));
$this->assertEquals('bar3', $frozen->getPropertyValue('foo'));

$predecessors = $this->simpleVersioned->getPredecessors();
$this->assertInternalType('array', $predecessors);
$firstVersion = reset($predecessors);
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $firstVersion);
$frozen2 = $firstVersion->getFrozenNode();
$this->assertInstanceOf('PHPCR\NodeInterface', $firstVersion);
/** @var $frozen2 NodeInterface */
$this->assertTrue($frozen2->hasProperty('foo'));
$this->assertEquals('bar2', $frozen2->getPropertyValue('foo'));
}

/**
* @expectedException \PHPCR\NodeType\ConstraintViolationException
* @depends testGetFrozenNode
*/
public function testFrozenNode()
{
$frozen = $this->simpleVersioned->getFrozenNode();
$frozen->setProperty('foo', 'should not work');
self::$staticSharedFixture['session']->save();
}

public function testGetLinearPredecessorSuccessor()
{
$pred = $this->simpleVersioned->getLinearPredecessor();
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $pred);
$succ = $pred->getLinearSuccessor();
$this->assertSame($this->simpleVersioned, $succ);
}

public function testGetLinearPredecessorNull()
{
$rootVersion = $this->vm->getVersionHistory('/tests_version_base/simpleVersioned')->getRootVersion();
// base version is at end of chain
$this->assertNull($rootVersion->getLinearPredecessor());
}

public function testGetLinearSuccessorNull()
{
// base version is at end of chain
$this->assertNull($this->simpleVersioned->getLinearSuccessor());
}

public function testGetPredecessors()
{
$versions = $this->simpleVersioned->getPredecessors();
$this->assertCount(1, $versions);
$pred = $versions[0];
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $pred);
$versions = $pred->getSuccessors();
$this->assertCount(1, $versions, 'expected a successor of our predecessor');
$this->assertSame($this->simpleVersioned, $versions[0]);
}

public function testGetSuccessors()
{
$versions = $this->simpleVersioned->getSuccessors();
$this->assertCount(0, $versions);
}

/**
* Check $version->remove() is not possible. This must go through VersionHistory::remove
*
* @expectedException \PHPCR\RepositoryException
*/
public function testNodeRemoveOnVersion()
{
$version = $this->vm->checkpoint('/tests_version_base/simpleVersioned');
$version->remove();
}
}