Skip to content

Commit 66de696

Browse files
committed
Merge pull request #96 from fazy/delete-sns-nodes
Tests for deleting same name siblings
2 parents cf50084 + fe22ccf commit 66de696

File tree

3 files changed

+298
-1
lines changed

3 files changed

+298
-1
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sv:node xmlns:crx="http://www.day.com/crx/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions" xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:rep="internal" sv:name="tests_write_manipulation_delete_sns">
3+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
4+
<sv:value>nt:unstructured</sv:value>
5+
</sv:property>
6+
<sv:node sv:name="testRemoveSnsBySession">
7+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
8+
<sv:value>nt:unstructured</sv:value>
9+
</sv:property>
10+
<sv:node sv:name="child">
11+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
12+
<sv:value>nt:unstructured</sv:value>
13+
</sv:property>
14+
</sv:node>
15+
<sv:node sv:name="child">
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="child">
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>
26+
<sv:node sv:name="testRemoveSnsByNode">
27+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
28+
<sv:value>nt:unstructured</sv:value>
29+
</sv:property>
30+
<sv:node sv:name="child">
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="child">
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 sv:name="child">
41+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
42+
<sv:value>nt:unstructured</sv:value>
43+
</sv:property>
44+
</sv:node>
45+
</sv:node>
46+
<sv:node sv:name="testRemoveManyNodes">
47+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
48+
<sv:value>nt:unstructured</sv:value>
49+
</sv:property>
50+
<sv:node sv:name="child">
51+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
52+
<sv:value>nt:unstructured</sv:value>
53+
</sv:property>
54+
<sv:property sv:name="childNumber" sv:type="String">
55+
<sv:value>1</sv:value>
56+
</sv:property>
57+
</sv:node>
58+
<sv:node sv:name="child">
59+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
60+
<sv:value>nt:unstructured</sv:value>
61+
</sv:property>
62+
<sv:property sv:name="childNumber" sv:type="String">
63+
<sv:value>2</sv:value>
64+
</sv:property>
65+
</sv:node>
66+
<sv:node sv:name="child">
67+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
68+
<sv:value>nt:unstructured</sv:value>
69+
</sv:property>
70+
<sv:property sv:name="childNumber" sv:type="String">
71+
<sv:value>3</sv:value>
72+
</sv:property>
73+
</sv:node>
74+
<sv:node sv:name="child">
75+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
76+
<sv:value>nt:unstructured</sv:value>
77+
</sv:property>
78+
<sv:property sv:name="childNumber" sv:type="String">
79+
<sv:value>4</sv:value>
80+
</sv:property>
81+
</sv:node>
82+
<sv:node sv:name="child">
83+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
84+
<sv:value>nt:unstructured</sv:value>
85+
</sv:property>
86+
<sv:property sv:name="childNumber" sv:type="String">
87+
<sv:value>5</sv:value>
88+
</sv:property>
89+
</sv:node>
90+
<sv:node sv:name="child">
91+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
92+
<sv:value>nt:unstructured</sv:value>
93+
</sv:property>
94+
<sv:property sv:name="childNumber" sv:type="String">
95+
<sv:value>6</sv:value>
96+
</sv:property>
97+
</sv:node>
98+
<sv:node sv:name="child">
99+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
100+
<sv:value>nt:unstructured</sv:value>
101+
</sv:property>
102+
<sv:property sv:name="childNumber" sv:type="String">
103+
<sv:value>7</sv:value>
104+
</sv:property>
105+
</sv:node>
106+
<sv:node sv:name="child">
107+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
108+
<sv:value>nt:unstructured</sv:value>
109+
</sv:property>
110+
<sv:property sv:name="childNumber" sv:type="String">
111+
<sv:value>8</sv:value>
112+
</sv:property>
113+
</sv:node>
114+
<sv:node sv:name="child">
115+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
116+
<sv:value>nt:unstructured</sv:value>
117+
</sv:property>
118+
<sv:property sv:name="childNumber" sv:type="String">
119+
<sv:value>9</sv:value>
120+
</sv:property>
121+
</sv:node>
122+
<sv:node sv:name="child">
123+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
124+
<sv:value>nt:unstructured</sv:value>
125+
</sv:property>
126+
<sv:property sv:name="childNumber" sv:type="String">
127+
<sv:value>10</sv:value>
128+
</sv:property>
129+
</sv:node>
130+
<sv:node sv:name="child">
131+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
132+
<sv:value>nt:unstructured</sv:value>
133+
</sv:property>
134+
<sv:property sv:name="childNumber" sv:type="String">
135+
<sv:value>11</sv:value>
136+
</sv:property>
137+
</sv:node>
138+
<sv:node sv:name="child">
139+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
140+
<sv:value>nt:unstructured</sv:value>
141+
</sv:property>
142+
<sv:property sv:name="childNumber" sv:type="String">
143+
<sv:value>12</sv:value>
144+
</sv:property>
145+
</sv:node>
146+
</sv:node>
147+
</sv:node>
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
namespace PHPCR\Tests\SameNameSiblings;
3+
4+
require_once(__DIR__ . '/../../inc/BaseCase.php');
5+
6+
/**
7+
* Test for deleting same name siblings (SNS).
8+
*
9+
* At this point, we are only testing for the ability to delete existing SNS;
10+
* creating or manipulating them is not supported.
11+
*/
12+
class DeleteMethodsTest extends \PHPCR\Test\BaseCase
13+
{
14+
static public function setupBeforeClass($fixtures = '22_SameNameSiblings/delete')
15+
{
16+
parent::setupBeforeClass($fixtures);
17+
}
18+
19+
public function setUp()
20+
{
21+
$this->renewSession(); // get rid of cache from previous tests
22+
parent::setUp();
23+
}
24+
25+
/**
26+
* Call session->removeItem() with multiple items before session->save()
27+
*/
28+
public function testRemoveItemMultiple()
29+
{
30+
$parentPath = '/tests_write_manipulation_delete_sns/testRemoveSnsBySession';
31+
$session = $this->sharedFixture['session'];
32+
$childNames = array('child', 'child[2]', 'child[3]');
33+
34+
$parent = $this->getParentNode($session, $parentPath);
35+
36+
foreach ($childNames as $childName) {
37+
$this->assertTrue($parent->hasNode($childName));
38+
$session->removeItem($parentPath . '/' . $childName);
39+
$this->assertFalse($parent->hasNode($childName), 'Node was not removed');
40+
}
41+
42+
$this->saveAndRenewSession();
43+
44+
foreach ($childNames as $childName) {
45+
$this->assertFalse($this->sharedFixture['session']->nodeExists($parentPath . '/' . $childName));
46+
}
47+
}
48+
49+
/**
50+
* Call node->remove() with multiple items before session->save()
51+
*
52+
* \PHPCR\ItemInterface::remove
53+
*/
54+
public function testRemoveNode()
55+
{
56+
$parentPath = '/tests_write_manipulation_delete_sns/testRemoveSnsByNode';
57+
$session = $this->sharedFixture['session'];
58+
$childNames = array('child', 'child[2]', 'child[3]');
59+
60+
$parent = $this->getParentNode($session, $parentPath);
61+
62+
foreach ($childNames as $childName) {
63+
$this->assertTrue($parent->hasNode($childName));
64+
$child = $parent->getNode($childName);
65+
$this->assertInstanceOf('PHPCR\NodeInterface', $child);
66+
$child->remove();
67+
$this->assertFalse($parent->hasNode($childName), 'Node was not removed');
68+
}
69+
70+
$this->saveAndRenewSession();
71+
72+
foreach ($childNames as $childName) {
73+
$this->assertFalse($this->sharedFixture['session']->nodeExists($parentPath . '/' . $childName));
74+
}
75+
}
76+
77+
/**
78+
* Delete 6 nodes from a set of 12, and check that the correct ones remain
79+
* (using a property to track individual nodes as they get renamed).
80+
*/
81+
public function testDeleteManyNodes()
82+
{
83+
$parentPath = '/tests_write_manipulation_delete_sns/testRemoveManyNodes';
84+
$session = $this->sharedFixture['session'];
85+
$childrenAtStart = array(
86+
'child' => '1',
87+
'child[2]' => '2',
88+
'child[3]' => '3',
89+
'child[4]' => '4',
90+
'child[5]' => '5',
91+
'child[6]' => '6',
92+
'child[7]' => '7',
93+
'child[8]' => '8',
94+
'child[9]' => '9',
95+
'child[10]' => '10',
96+
'child[11]' => '11',
97+
'child[12]' => '12',
98+
);
99+
$childrenToDelete = array(
100+
'child',
101+
'child[2]',
102+
'child[3]',
103+
'child[6]',
104+
'child[10]',
105+
'child[11]',
106+
);
107+
$childrenAtEnd = array(
108+
'child' => '4',
109+
'child[2]' => '5',
110+
'child[3]' => '7',
111+
'child[4]' => '8',
112+
'child[5]' => '9',
113+
'child[6]' => '12',
114+
);
115+
116+
$parent = $this->getParentNode($session, $parentPath);
117+
118+
foreach ($childrenAtStart as $childName => $childNumber) {
119+
$this->assertTrue($parent->hasNode($childName), "Child $childNumber not found.");
120+
}
121+
122+
foreach ($childrenToDelete as $childName) {
123+
$session->removeItem($parentPath . '/' . $childName);
124+
$this->assertFalse($parent->hasNode($childName), 'Node was not removed');
125+
}
126+
127+
$this->saveAndRenewSession();
128+
129+
$parent = $this->sharedFixture['session']->getNode($parentPath);
130+
$this->assertEquals(count($childrenAtEnd), count($parent->getNodes()));
131+
132+
foreach ($parent->getNodes() as $node) {
133+
$child = each($childrenAtEnd);
134+
$this->assertEquals($parentPath . '/' . $child['key'], $node->getPath());
135+
$this->assertEquals($child['value'], $node->getProperty('childNumber')->getValue());
136+
}
137+
}
138+
139+
/**
140+
* @param $session
141+
* @param $parentPath
142+
* @return mixed
143+
*/
144+
private function getParentNode($session, $parentPath)
145+
{
146+
$parent = $session->getNode($parentPath);
147+
$this->assertInstanceOf('PHPCR\NodeInterface', $parent);
148+
return $parent;
149+
}
150+
}

tests/22_SameNameSiblings/TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Create tests...
1+
Create more tests...
22

0 commit comments

Comments
 (0)