Skip to content
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

[WIP] child version cascade tests (fails) #85

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion fixtures/15_Versioning/base.xml
Expand Up @@ -18,14 +18,25 @@
</sv:node>
<sv:node sv:name="versioned">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
<sv:value>phpcr:versionCascade</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:versionable</sv:value>
</sv:property>
<sv:property sv:name="foo" sv:type="String">
<sv:value>something</sv:value>
</sv:property>
<sv:node sv:name="version_child">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>phpcr:versionCascade</sv:value>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The child can probably can be nt:unstructured rather than phpcr:versionCascade...

</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:versionable</sv:value>
</sv:property>
<sv:property sv:name="foo_c" sv:type="String">
<sv:value>something_c</sv:value>
</sv:property>
</sv:node>
</sv:node>
<sv:node sv:name="simpleVersioned">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
Expand Down
10 changes: 10 additions & 0 deletions inc/BaseCase.php
Expand Up @@ -87,6 +87,16 @@ public static function setupBeforeClass($fixtures = 'general/base')

self::$staticSharedFixture['ie'] = self::$loader->getFixtureLoader();
if ($fixtures) {
$ntm = self::$loader->getSession()->getWorkspace()->getNodeTypeManager();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope it doesn't cause a problem getting the session here? (see comment on L102)

if (! $ntm->hasNodeType('phpcr:versionCascade')) {
$cnd = <<<END_CND
[phpcr:versionCascade] > nt:unstructured
- copy
+ * copy
END_CND;
$ntm->registerNodeTypesCnd($cnd, false);
}

self::$staticSharedFixture['ie']->import($fixtures);
}

Expand Down
78 changes: 78 additions & 0 deletions tests/15_Versioning/VersionTest.php
Expand Up @@ -14,6 +14,8 @@ class VersionTest extends \PHPCR\Test\BaseCase
private $vm;
/** a versioned node */
private $version;
/** a versioned child node */
private $childVersion;

static public function setupBeforeClass($fixtures = '15_Versioning/base')
{
Expand All @@ -23,15 +25,24 @@ static public function setupBeforeClass($fixtures = '15_Versioning/base')
$vm = self::$staticSharedFixture['session']->getWorkspace()->getVersionManager();

$node = self::$staticSharedFixture['session']->getNode('/tests_version_base/versioned');
$childNode = self::$staticSharedFixture['session']->getNode('/tests_version_base/versioned/version_child');
self::$staticSharedFixture['session']->save();

$vm->checkpoint('/tests_version_base/versioned');
$node->setProperty('foo', 'bar');
$childNode->setProperty('foo_c', 'bar_c');
self::$staticSharedFixture['session']->save();

$vm->checkpoint('/tests_version_base/versioned');
$node->setProperty('foo', 'bar2');
$childNode->setProperty('foo_c', 'bar2_c');
self::$staticSharedFixture['session']->save();

$vm->checkpoint('/tests_version_base/versioned');
$node->setProperty('foo', 'bar3');
$childNode->setProperty('foo_c', 'bar3_c');
self::$staticSharedFixture['session']->save();

$vm->checkin('/tests_version_base/versioned');
self::$staticSharedFixture['session'] = self::$loader->getSession(); //reset the session
}
Expand All @@ -43,6 +54,7 @@ public function setUp()
$this->vm = $this->sharedFixture['session']->getWorkspace()->getVersionManager();

$this->version = $this->vm->getBaseVersion('/tests_version_base/versioned');
$this->childVersion = $this->vm->getBaseVersion('/tests_version_base/versioned/version_child');

$this->assertInstanceOf('PHPCR\Version\VersionInterface', $this->version);
}
Expand All @@ -52,6 +64,11 @@ public function testGetContainingHistory()
$this->assertSame($this->vm->getVersionHistory('/tests_version_base/versioned'), $this->version->getContainingHistory());
}

public function testGetContainingChildHistory()
{
$this->assertSame($this->vm->getVersionHistory('/tests_version_base/versioned/version_child'), $this->childVersion->getContainingHistory());
}

public function testGetCreated()
{
$date = $this->version->getCreated();
Expand All @@ -71,6 +88,18 @@ public function testGetFrozenNode()
$this->assertEquals('bar2', $frozen2->getPropertyValue('foo'));
}

public function testGetFrozenChildNode()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the asserts here will currently fail

{
$frozen = $this->childVersion->getFrozenNode();
$this->assertTrue($frozen->hasProperty('foo_c'));
$this->assertEquals('bar3_c', $frozen->getPropertyValue('foo_c'));

$predecessors = $this->childVersion->getPredecessors();
$frozen2 = reset($predecessors)->getFrozenNode();
$this->assertTrue($frozen2->hasProperty('foo_c'));
$this->assertEquals('bar2_c', $frozen2->getPropertyValue('foo_c'));
}

/**
* @expectedException PHPCR\NodeType\ConstraintViolationException
* @depends testGetFrozenNode
Expand All @@ -82,6 +111,17 @@ public function testFrozenNode()
self::$staticSharedFixture['session']->save();
}

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

public function testGetLinearPredecessorSuccessor()
{
$pred = $this->version->getLinearPredecessor();
Expand All @@ -90,19 +130,40 @@ public function testGetLinearPredecessorSuccessor()
$this->assertSame($this->version, $succ);
}

public function testGetChildLinearPredecessorSuccessor()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently fails

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

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

public function testGetChildLinearPredecessorNull()
{
$rootVersion = $this->vm->getVersionHistory('/tests_version_base/versioned/version_child')->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->version->getLinearSuccessor());
}

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

public function testGetPredecessors()
{
$versions = $this->version->getPredecessors();
Expand All @@ -114,12 +175,29 @@ public function testGetPredecessors()
$this->assertSame($this->version, $versions[0]);
}

public function testGetChildPredecessors()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently fails

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

public function testGetSuccessors()
{
$versions = $this->version->getSuccessors();
$this->assertEquals(0, count($versions));
}

public function testGetChildSuccessors()
{
$versions = $this->childVersion->getSuccessors();
$this->assertEquals(0, count($versions));
}

/**
* Check $version->remove() is not possible. This must go through VersionHistory::remove
*
Expand Down