Skip to content

Commit d9088ed

Browse files
committed
move observation test nodes into a /test path instead of directly root
1 parent d7cf233 commit d9088ed

File tree

2 files changed

+84
-25
lines changed

2 files changed

+84
-25
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sv:node
3+
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
4+
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
5+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
6+
xmlns:jcr="http://www.jcp.org/jcr/1.0"
7+
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
8+
sv:name="tests_observation_manager">
9+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
10+
<sv:value>nt:unstructured</sv:value>
11+
</sv:property>
12+
<sv:property sv:name="jcr:created" sv:type="Date">
13+
<sv:value>2013-04-27T13:00:54.082+02:00</sv:value>
14+
</sv:property>
15+
<sv:node sv:name="testGetUnfilteredEventJournal">
16+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
17+
<sv:value>nt:unstructured</sv:value>
18+
</sv:property>
19+
</sv:node>
20+
<sv:node sv:name="testFilteredEventJournal">
21+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
22+
<sv:value>nt:unstructured</sv:value>
23+
</sv:property>
24+
</sv:node>
25+
<sv:node sv:name="testFilteredEventJournalUuid">
26+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
27+
<sv:value>nt:unstructured</sv:value>
28+
</sv:property>
29+
</sv:node>
30+
<sv:node sv:name="testFilteredEventJournalNodeType">
31+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
32+
<sv:value>nt:unstructured</sv:value>
33+
</sv:property>
34+
</sv:node>
35+
<sv:node sv:name="testUserData">
36+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
37+
<sv:value>nt:unstructured</sv:value>
38+
</sv:property>
39+
</sv:node>
40+
</sv:node>

tests/12_Observation/ObservationManagerTest.php

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,21 @@ class ObservationManagerTest extends \PHPCR\Test\BaseCase
2424
// TODO: write some tests for journal filtering with combined filters.
2525
// All the tests here will only tests filtering on a single criterion.
2626

27-
public function testGetUnfilteredEventJournal()
27+
static public function setupBeforeClass($fixtures = '12_Observation/manager')
2828
{
29+
parent::setupBeforeClass($fixtures);
2930
sleep(1); // To avoid having the same date as the journal entries generated by the fixtures loading
31+
}
3032

33+
public function setUp()
34+
{
35+
parent::setUp();
36+
//all tests in this suite rely on the trick to have the node populated from the fixtures
37+
$this->assertInstanceOf('PHPCR\NodeInterface', $this->node, "Something went wrong with fixture loading");
38+
}
39+
40+
public function testGetUnfilteredEventJournal()
41+
{
3142
$curTime = time() * 1000;
3243

3344
$producerSession = self::$loader->getSession();
@@ -69,12 +80,12 @@ public function testFilteredEventJournalUuid()
6980
$session = self::$loader->getSession();
7081
$om = $session->getWorkspace()->getObservationManager();
7182

72-
// Make the root node have a UUID
73-
$root = $session->getRootNode();
74-
$root->addMixin('mix:referenceable');
83+
// Make the root node has a UUID
84+
$parent = $session->getNode($this->node->getPath());
85+
$parent->addMixin('mix:referenceable');
7586
$session->save();
7687

77-
$root->setProperty('ref', $root, \PHPCR\PropertyType::WEAKREFERENCE);
88+
$parent->setProperty('ref', $parent, \PHPCR\PropertyType::WEAKREFERENCE);
7889
$session->save();
7990

8091
$uuid = $session->getRootNode()->getIdentifier();
@@ -89,7 +100,7 @@ public function testFilteredEventJournalUuid()
89100
$journal = $om->getEventJournal($filter);
90101
$journal->skipTo($curTime);
91102
$this->assertTrue($journal->valid());
92-
$this->assertEquals('/ref', $journal->current()->getPath());
103+
$this->assertEquals($this->node->getPath() . '/ref', $journal->current()->getPath());
93104
$this->assertEquals(EventInterface::PROPERTY_ADDED, $journal->current()->getType());
94105

95106
$journal->next();
@@ -100,15 +111,12 @@ public function testFilteredEventJournalUuid()
100111
public function testFilteredEventJournalNodeType()
101112
{
102113
$session = self::$loader->getSession();
103-
$root = $session->getRootNode();
104-
$node = $root->addNode('/tests_observation');
105-
$session->save();
106-
sleep(1); // To avoid having the same date as the journal entries generated by the fixtures loading or other tests
107114

108115
$curTime = time() * 1000;
109116
$om = $session->getWorkspace()->getObservationManager();
110117

111-
$node->addNode('unstructured');
118+
$parent = $session->getNode($this->node->getPath());
119+
$parent->addNode('unstructured');
112120
$session->save();
113121

114122
// At this point the journal contains 3 events: PROP_ADDED (for setting the node type of the new node)
@@ -121,7 +129,7 @@ public function testFilteredEventJournalNodeType()
121129

122130
// At this point the journal should only contain the NODE_ADDED event
123131
$this->assertTrue($journal->valid());
124-
$this->assertEquals('/tests_observation/unstructured', $journal->current()->getPath());
132+
$this->assertEquals($this->node->getPath() . '/unstructured', $journal->current()->getPath());
125133
$this->assertEquals(EventInterface::NODE_ADDED, $journal->current()->getType());
126134

127135
$journal->next();
@@ -268,8 +276,8 @@ protected function assertFilterOnNodeTypeNoMatch(ObservationManagerInterface $ob
268276
*/
269277
protected function produceEvents(SessionInterface $session)
270278
{
271-
$root = $session->getRootNode();
272-
$node = $root->addNode('child'); // Will cause a PROPERTY_ADDED + a NODE_ADDED events
279+
$parent = $session->getNode($this->node->getPath());
280+
$node = $parent->addNode('child'); // Will cause a PROPERTY_ADDED + a NODE_ADDED events
273281
$session->save(); // Will cause a PERSIST event
274282

275283
$prop = $node->setProperty('prop', 'value'); // Will case a PROPERTY_ADDED event
@@ -281,7 +289,8 @@ protected function produceEvents(SessionInterface $session)
281289
$prop->remove(); // Will cause a PROPERTY_REMOVED event
282290
$session->save(); // Will cause a PERSIST event
283291

284-
$session->move('/child', '/moved'); // Will cause a NODE_REMOVED + NODE_ADDED + NODE_MOVED events
292+
// Will cause a NODE_REMOVED + NODE_ADDED + NODE_MOVED events
293+
$session->move($node->getPath(), $this->node->getPath() . '/moved');
285294
$session->save(); // Will cause a PERSIST event
286295

287296
$node->remove(); // Will cause a NODE_REMOVED event
@@ -342,6 +351,8 @@ protected function expectEventsInAnyOrder(EventJournalInterface $journal, $event
342351
}
343352

344353
$this->assertEmpty($expectedEvents, 'Some expected events did not occur');
354+
355+
return $occuredEvents;
345356
}
346357

347358
/**
@@ -366,27 +377,27 @@ protected function expectEvents(EventJournalInterface $journal, $startDate)
366377
// The order is implementation specific (Jackrabbit will trigger the prop added before the node added event)
367378
$this->expectEventsInAnyOrder($journal,
368379
array(
369-
array(EventInterface::NODE_ADDED, '/child'),
370-
array(EventInterface::PROPERTY_ADDED, '/child/jcr%3aprimaryType'),
380+
array(EventInterface::NODE_ADDED, $this->node->getPath() . '/child'),
381+
array(EventInterface::PROPERTY_ADDED, $this->node->getPath() . '/child/jcr%3aprimaryType'),
371382
)
372383
);
373384

374385
$this->assertEvent(EventInterface::PERSIST, '', $journal->current());
375386

376387
$journal->next();
377-
$this->assertEvent(EventInterface::PROPERTY_ADDED, '/child/prop', $journal->current());
388+
$this->assertEvent(EventInterface::PROPERTY_ADDED, $this->node->getPath() . '/child/prop', $journal->current());
378389

379390
$journal->next();
380391
$this->assertEvent(EventInterface::PERSIST, '', $journal->current());
381392

382393
$journal->next();
383-
$this->assertEvent(EventInterface::PROPERTY_CHANGED, '/child/prop', $journal->current());
394+
$this->assertEvent(EventInterface::PROPERTY_CHANGED, $this->node->getPath() . '/child/prop', $journal->current());
384395

385396
$journal->next();
386397
$this->assertEvent(EventInterface::PERSIST, '', $journal->current());
387398

388399
$journal->next();
389-
$this->assertEvent(EventInterface::PROPERTY_REMOVED, '/child/prop', $journal->current());
400+
$this->assertEvent(EventInterface::PROPERTY_REMOVED, $this->node->getPath() . '/child/prop', $journal->current());
390401

391402
$journal->next();
392403
$this->assertEvent(EventInterface::PERSIST, '', $journal->current());
@@ -395,18 +406,26 @@ protected function expectEvents(EventJournalInterface $journal, $startDate)
395406

396407
// Same problem as before. Moving a node will cause a NODE_REMOVED + NODE_ADDED + NODE_MOVED
397408
// The order of the events is implementation specific.
398-
$this->expectEventsInAnyOrder($journal,
409+
$events = $this->expectEventsInAnyOrder($journal,
399410
array(
400-
array(EventInterface::NODE_REMOVED, '/child'),
401-
array(EventInterface::NODE_ADDED, '/moved'),
402-
array(EventInterface::NODE_MOVED, '/moved'),
411+
array(EventInterface::NODE_REMOVED, $this->node->getPath() . '/child'),
412+
array(EventInterface::NODE_ADDED, $this->node->getPath() . '/moved'),
413+
array(EventInterface::NODE_MOVED, $this->node->getPath() . '/moved'),
403414
)
404415
);
416+
foreach($events as $event) {
417+
if (EventInterface::NODE_MOVED === $event->getType()) {
418+
$type = $event->getPrimaryNodeType();
419+
$this->assertInstanceOf('PHPCR\NodeType\NodeTypeInterface', $type);
420+
$this->assertEquals('nt:unstructured', $type->getName());
421+
}
422+
}
423+
405424

406425
$this->assertEvent(EventInterface::PERSIST, '', $journal->current());
407426

408427
$journal->next();
409-
$this->assertEvent(EventInterface::NODE_REMOVED, '/moved', $journal->current());
428+
$this->assertEvent(EventInterface::NODE_REMOVED, $this->node->getPath() . '/moved', $journal->current());
410429

411430
$journal->next();
412431
$this->assertEvent(EventInterface::PERSIST, '', $journal->current());

0 commit comments

Comments
 (0)