Skip to content

Commit 92e596d

Browse files
committed
Merge pull request #157 from phpcr/simple-versioning
adding a test for simple versioning
2 parents 62eaeb0 + cb865e4 commit 92e596d

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
namespace PHPCR\Tests\Versioning;
3+
4+
use PHPCR\NodeInterface;
5+
use PHPCR\Test\BaseCase;
6+
use PHPCR\Version\VersionInterface;
7+
use PHPCR\Version\VersionManagerInterface;
8+
9+
require_once(__DIR__ . '/../../inc/BaseCase.php');
10+
11+
/**
12+
* Testing whether simple versioning works
13+
*
14+
* Covering jcr-283 spec $15.1
15+
*/
16+
class SimpleVersionTest extends BaseCase
17+
{
18+
/**
19+
* @var VersionManagerInterface
20+
*/
21+
private $vm;
22+
23+
/**
24+
* @var VersionInterface
25+
*/
26+
private $simpleVersioned;
27+
28+
public static function setupBeforeClass($fixtures = '15_Versioning/base')
29+
{
30+
parent::setupBeforeClass($fixtures);
31+
}
32+
33+
public function setUp()
34+
{
35+
parent::setUp();
36+
37+
$this->vm = $this->session->getWorkspace()->getVersionManager();
38+
39+
$this->simpleVersioned = $this->vm->getBaseVersion('/tests_version_base/simpleVersioned');
40+
41+
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $this->simpleVersioned);
42+
}
43+
44+
public function testGetContainingHistory()
45+
{
46+
$this->assertSame($this->vm->getVersionHistory('/tests_version_base/simpleVersioned'), $this->simpleVersioned->getContainingHistory());
47+
}
48+
49+
public function testGetCreated()
50+
{
51+
$date = $this->simpleVersioned->getCreated();
52+
$diff = time() - $date->getTimestamp();
53+
$this->assertTrue($diff < 60, 'creation date of the version we created in setupBeforeClass should be within the last few seconds');
54+
}
55+
56+
public function testGetFrozenNode()
57+
{
58+
$frozen = $this->simpleVersioned->getFrozenNode();
59+
$this->assertTrue($frozen->hasProperty('foo'));
60+
$this->assertEquals('bar3', $frozen->getPropertyValue('foo'));
61+
62+
$predecessors = $this->simpleVersioned->getPredecessors();
63+
$this->assertInternalType('array', $predecessors);
64+
$firstVersion = reset($predecessors);
65+
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $firstVersion);
66+
$frozen2 = $firstVersion->getFrozenNode();
67+
$this->assertInstanceOf('PHPCR\NodeInterface', $firstVersion);
68+
/** @var $frozen2 NodeInterface */
69+
$this->assertTrue($frozen2->hasProperty('foo'));
70+
$this->assertEquals('bar2', $frozen2->getPropertyValue('foo'));
71+
}
72+
73+
/**
74+
* @expectedException \PHPCR\NodeType\ConstraintViolationException
75+
* @depends testGetFrozenNode
76+
*/
77+
public function testFrozenNode()
78+
{
79+
$frozen = $this->simpleVersioned->getFrozenNode();
80+
$frozen->setProperty('foo', 'should not work');
81+
self::$staticSharedFixture['session']->save();
82+
}
83+
84+
public function testGetLinearPredecessorSuccessor()
85+
{
86+
$pred = $this->simpleVersioned->getLinearPredecessor();
87+
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $pred);
88+
$succ = $pred->getLinearSuccessor();
89+
$this->assertSame($this->simpleVersioned, $succ);
90+
}
91+
92+
public function testGetLinearPredecessorNull()
93+
{
94+
$rootVersion = $this->vm->getVersionHistory('/tests_version_base/simpleVersioned')->getRootVersion();
95+
// base version is at end of chain
96+
$this->assertNull($rootVersion->getLinearPredecessor());
97+
}
98+
99+
public function testGetLinearSuccessorNull()
100+
{
101+
// base version is at end of chain
102+
$this->assertNull($this->simpleVersioned->getLinearSuccessor());
103+
}
104+
105+
public function testGetPredecessors()
106+
{
107+
$versions = $this->simpleVersioned->getPredecessors();
108+
$this->assertCount(1, $versions);
109+
$pred = $versions[0];
110+
$this->assertInstanceOf('PHPCR\Version\VersionInterface', $pred);
111+
$versions = $pred->getSuccessors();
112+
$this->assertCount(1, $versions, 'expected a successor of our predecessor');
113+
$this->assertSame($this->simpleVersioned, $versions[0]);
114+
}
115+
116+
public function testGetSuccessors()
117+
{
118+
$versions = $this->simpleVersioned->getSuccessors();
119+
$this->assertCount(0, $versions);
120+
}
121+
122+
/**
123+
* Check $version->remove() is not possible. This must go through VersionHistory::remove
124+
*
125+
* @expectedException \PHPCR\RepositoryException
126+
*/
127+
public function testNodeRemoveOnVersion()
128+
{
129+
$version = $this->vm->checkpoint('/tests_version_base/simpleVersioned');
130+
$version->remove();
131+
}
132+
}

0 commit comments

Comments
 (0)