Skip to content

Commit 7494a2a

Browse files
committed
Merge pull request #151 from phpcr/revert-146-mixreferenceable
Revert "Multivalue reference tests"
2 parents 979dae7 + 22f8c57 commit 7494a2a

File tree

2 files changed

+24
-188
lines changed

2 files changed

+24
-188
lines changed

fixtures/10_Writing/mixinreferenceable.xml

Lines changed: 0 additions & 106 deletions
This file was deleted.

tests/10_Writing/MixinReferenceableTest.php

Lines changed: 24 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
namespace PHPCR\Tests\Writing;
33

4-
use PHPCR\PropertyType;
5-
64
require_once(__DIR__ . '/../../inc/BaseCase.php');
75

86
/**
@@ -12,11 +10,6 @@
1210
*/
1311
class MixinReferenceableTest extends \PHPCR\Test\BaseCase
1412
{
15-
public static function setupBeforeClass($fixtures = '10_Writing/mixinreferenceable')
16-
{
17-
parent::setupBeforeClass($fixtures);
18-
}
19-
2013
public function setUp()
2114
{
2215
$this->renewSession(); // discard changes
@@ -29,11 +22,11 @@ public function setUp()
2922
public function testReferenceOnNonReferenceableNode()
3023
{
3124
// Load a non-referenceable node
32-
$nonReferenceableNode = $this->node->getNode('non-referenceable');
25+
$referenced_node = $this->session->getNode('/tests_general_base/emptyExample');
3326

3427
// Try to reference it
35-
$sourceNode = $this->node->getNode('node');
36-
$sourceNode->setProperty('reference', $nonReferenceableNode, \PHPCR\PropertyType::WEAKREFERENCE);
28+
$source_node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
29+
$source_node->setProperty('reference', $referenced_node, \PHPCR\PropertyType::WEAKREFERENCE);
3730
$this->session->save();
3831
}
3932

@@ -43,24 +36,24 @@ public function testReferenceOnNonReferenceableNode()
4336
public function testReferenceOnNewlyReferenceableNode()
4437
{
4538
// Load a non-referenceable node and make it referenceable
46-
$referencedNode = $this->node->getNode('node');
47-
$referencedNode->addMixin('mix:referenceable');
39+
$referenced_node = $this->session->getNode('/tests_general_base/emptyExample');
40+
$referenced_node->addMixin('mix:referenceable');
4841

4942
// Re-read the node to be sure it has a UUID
5043
$this->saveAndRenewSession();
51-
$referencedNode = $this->node->getNode('node');
44+
$referenced_node = $this->session->getNode('/tests_general_base/emptyExample');
5245

5346
// Reference it from another node
54-
$sourceNode = $this->node->getNode('other-node');
55-
$sourceNode->setProperty('reference', $referencedNode, \PHPCR\PropertyType::WEAKREFERENCE);
47+
$source_node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
48+
$source_node->setProperty('reference', $referenced_node, \PHPCR\PropertyType::WEAKREFERENCE);
5649

5750
$this->session->save();
5851

59-
$this->assertInstanceOf('PHPCR\NodeInterface', $sourceNode->getPropertyValue('reference'));
52+
$this->assertInstanceOf('PHPCR\NodeInterface', $source_node->getPropertyValue('reference'));
6053

6154
// referrers only required to work once save happened
62-
$this->assertCount(0, $referencedNode->getReferences());
63-
$this->assertCount(1, $referencedNode->getWeakReferences());
55+
$this->assertCount(0, $referenced_node->getReferences());
56+
$this->assertCount(1, $referenced_node->getWeakReferences());
6457
}
6558

6659
/**
@@ -69,91 +62,40 @@ public function testReferenceOnNewlyReferenceableNode()
6962
public function testReferenceOnReferenceableNode()
7063
{
7164
// Load a referenceable node
72-
$referencedNode = $this->node->getNode('referenceable');
65+
$referenced_node = $this->session->getNode('/tests_general_base/idExample');
7366

7467
// Reference it from another node
75-
$sourceNode = $this->node->getNode('node');
76-
$sourceNode->setProperty('oreference', $referencedNode, \PHPCR\PropertyType::WEAKREFERENCE);
68+
$source_node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
69+
$source_node->setProperty('oreference', $referenced_node, \PHPCR\PropertyType::WEAKREFERENCE);
7770
$this->session->save();
7871

79-
$this->assertInstanceOf('PHPCR\NodeInterface', $sourceNode->getPropertyValue('oreference'));
72+
$this->assertInstanceOf('PHPCR\NodeInterface', $source_node->getPropertyValue('oreference'));
8073
}
8174

8275
/**
8376
* Test that we can update a reference
8477
*/
8578
public function testUpdateReference()
8679
{
87-
$referenced1 = $this->node->getNode('node');
80+
$referenced1 = $this->session->getNode('/tests_general_base/emptyExample');
8881
$referenced1->addMixin('mix:referenceable');
8982
$this->session->save();
9083

9184
// Load a referenceable node
92-
$referenced2 = $this->node->getNode('referenceable');
85+
$referenced2 = $this->session->getNode('/tests_general_base/idExample');
9386

9487
// Reference it from another node
95-
$sourceNode = $this->node->getNode('other-node');
88+
$source_node = $this->session->getNode('/tests_general_base/index.txt/jcr:content');
9689

97-
$sourceNode->setProperty('reference', $referenced1, \PHPCR\PropertyType::WEAKREFERENCE);
90+
$source_node->setProperty('reference', $referenced1, \PHPCR\PropertyType::WEAKREFERENCE);
9891
$this->session->save();
99-
$sourceNode->setProperty('reference', $referenced2, \PHPCR\PropertyType::WEAKREFERENCE);
92+
$source_node->setProperty('reference', $referenced2, \PHPCR\PropertyType::WEAKREFERENCE);
10093
$this->session->save();
101-
$this->assertSame($referenced2, $sourceNode->getPropertyValue('reference'));
102-
103-
$this->renewSession();
104-
$referenced2 = $this->node->getNode('referenceable');
105-
$this->assertSame($referenced2, $this->node->getNode('other-node')->getProperty('reference')->getValue());
106-
}
107-
108-
public function testMultiValueReference()
109-
{
110-
$this->doTestMultiValueReference(
111-
array('one', 'two', 'three'),
112-
array('one', 'two', 'one', 'one', 'two', 'three'),
113-
PropertyType::REFERENCE
114-
);
115-
}
116-
117-
public function testMultiValueWeakReference()
118-
{
119-
$this->doTestMultiValueReference(
120-
array('one', 'two', 'three'),
121-
array('one', 'two', 'one', 'one', 'two', 'three'),
122-
PropertyType::WEAKREFERENCE
123-
);
124-
}
94+
$this->assertSame($referenced2, $source_node->getPropertyValue('reference'));
12595

126-
private function doTestMultiValueReference($nodeNames, $nodeCollectionNames, $referenceType)
127-
{
128-
$baseNode = $this->node;
129-
$nodes = array();
130-
foreach ($nodeNames as $nodeName) {
131-
$node = $baseNode->addNode($nodeName);
132-
$node->addMixin('mix:referenceable');
133-
$nodes[$nodeName] = $node;
134-
}
135-
136-
$this->session->save();
137-
138-
$referrer = $baseNode->addNode('referrer');
139-
140-
$nodeCollection = array();
141-
142-
foreach ($nodeCollectionNames as $nodeCollectionName) {
143-
$nodeCollection[] = $nodes[$nodeCollectionName];
144-
}
145-
$referrer->setProperty('references', $nodeCollection, $referenceType);
146-
147-
$this->session->save();
148-
149-
$this->renewSession();
150-
$referrer = $this->node->getNode('referrer');
151-
$values = $referrer->getProperty('references');
152-
153-
foreach ($values as $referencedNode) {
154-
$name = array_shift($nodeCollectionNames);
155-
$this->assertSame($name, $referencedNode->getName());
156-
}
96+
$session = $this->renewSession();
97+
$referenced2 = $session->getNode('/tests_general_base/idExample');
98+
$this->assertSame($referenced2, $session->getProperty('/tests_general_base/index.txt/jcr:content/reference')->getValue());
15799
}
158100

159101
public function testSetUuidNewReferenceable()

0 commit comments

Comments
 (0)