Skip to content

Commit 287c2a9

Browse files
committed
Merge pull request #163 from phpcr/node-get-definition
adding tests for Node::getDefinition
2 parents b2f4da0 + f9198eb commit 287c2a9

File tree

3 files changed

+148
-13
lines changed

3 files changed

+148
-13
lines changed

tests/NodeTypeDiscovery/NodeDefinitionTest.php

+39-2
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,52 @@
1111

1212
namespace PHPCR\Tests\NodeTypeDiscovery;
1313

14+
use PHPCR\NodeType\NodeDefinitionInterface;
15+
use PHPCR\NodeType\NodeTypeInterface;
16+
use PHPCR\NodeType\NodeTypeManagerInterface;
17+
1418
/**
15-
* Test the NoteDefinition §8.
19+
* Test NodeDefinition behaviour and reading NodeDefinition from NodeTypeDefinition §8.
1620
*
1721
* Requires that NodeTypeManager->getNodeType and NodeTypeDefinition->getChildNodeDefinitions() works correctly
1822
*/
1923
class NodeDefinitionTest extends \PHPCR\Test\BaseCase
2024
{
2125
private static $base;
26+
27+
/**
28+
* @var NodeTypeInterface
29+
*/
2230
private static $file;
31+
32+
/**
33+
* @var NodeTypeInterface
34+
*/
2335
private static $folder;
36+
37+
/**
38+
* @var NodeTypeInterface
39+
*/
2440
private static $hierarchyNodeType;
25-
/** jcr:content of nt:file */
41+
42+
/**
43+
* Node definition of the jcr:content in an nt:file type.
44+
*
45+
* @var NodeDefinitionInterface
46+
*/
2647
private $content;
48+
49+
/**
50+
* Node definition of a hierarchy node.
51+
*
52+
* @var NodeDefinitionInterface
53+
*/
2754
private $hierarchyNodeDef;
2855

2956
public static function setupBeforeClass($fixtures = false)
3057
{
3158
parent::setupBeforeClass($fixtures);
59+
/** @var NodeTypeManagerInterface $ntm */
3260
$ntm = self::$staticSharedFixture['session']->getWorkspace()->getNodeTypeManager();
3361
self::$file = $ntm->getNodeType('nt:file');
3462
self::$folder = $ntm->getNodeType('nt:folder');
@@ -37,6 +65,7 @@ public static function setupBeforeClass($fixtures = false)
3765

3866
public function setUp()
3967
{
68+
parent::setUp();
4069
try {
4170
$defs = self::$file->getChildNodeDefinitions();
4271
$this->assertInternalType('array', $defs);
@@ -55,6 +84,7 @@ public function setUp()
5584
$this->markTestSkipped('getChildNodeDefinitions not working as it should, skipping tests about NodeDefinitionInterface: '.$e->getMessage());
5685
}
5786
}
87+
5888
public function testAllowsSameNameSiblings()
5989
{
6090
$this->assertFalse($this->content->allowsSameNameSiblings());
@@ -64,10 +94,12 @@ public function testDefaultPrimaryType()
6494
{
6595
$this->assertNull($this->content->getDefaultPrimaryType());
6696
}
97+
6798
public function testDefaultPrimaryTypeName()
6899
{
69100
$this->assertNull($this->content->getDefaultPrimaryTypeName());
70101
}
102+
71103
public function getRequiredPrimaryTypeNames()
72104
{
73105
$names = $this->content->getRequiredPrimaryTypeNames();
@@ -102,26 +134,31 @@ public function testGetDeclaringNodeType()
102134
$nt = $this->hierarchyNodeDef->getDeclaringNodeType();
103135
$this->assertSame(self::$folder, $nt);
104136
}
137+
105138
public function testName()
106139
{
107140
$this->assertEquals('jcr:content', $this->content->getName());
108141
$this->assertEquals('*', $this->hierarchyNodeDef->getName());
109142
}
143+
110144
public function testGetOnParentVersion()
111145
{
112146
$this->assertEquals(\PHPCR\Version\OnParentVersionAction::COPY, $this->content->getOnParentVersion());
113147
$this->assertEquals(\PHPCR\Version\OnParentVersionAction::VERSION, $this->hierarchyNodeDef->getOnParentVersion());
114148
}
149+
115150
public function testIsAutoCreated()
116151
{
117152
$this->assertFalse($this->content->isAutoCreated());
118153
$this->assertFalse($this->hierarchyNodeDef->isAutoCreated());
119154
}
155+
120156
public function testIsMandatory()
121157
{
122158
$this->assertTrue($this->content->isMandatory());
123159
$this->assertFalse($this->hierarchyNodeDef->isMandatory());
124160
}
161+
125162
public function testIsProtected()
126163
{
127164
$this->assertFalse($this->content->isProtected());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHPCR API Tests package
5+
*
6+
* Copyright (c) 2015 Liip and others
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace PHPCR\Tests\NodeTypeDiscovery;
13+
14+
use PHPCR\NodeType\NodeDefinitionInterface;
15+
use PHPCR\NodeType\NodeTypeInterface;
16+
use PHPCR\NodeType\NodeTypeManagerInterface;
17+
use PHPCR\Test\BaseCase;
18+
19+
/**
20+
* Test reading NodeDefinition from Nodes §8.
21+
*
22+
* @see NodeInterface::getDefinition
23+
*/
24+
class NodeNodeDefinitionTest extends BaseCase
25+
{
26+
public function testGetNodeDefinitionExact()
27+
{
28+
// an nt:file must have a jcr:content property
29+
$node = $this->rootNode->getNode('tests_general_base/numberPropertyNode/jcr:content');
30+
$nodeDef = $node->getDefinition();
31+
$this->assertInstanceOf('PHPCR\\NodeType\\NodeDefinitionInterface', $nodeDef);
32+
$this->assertEquals('jcr:content', $nodeDef->getName());
33+
$this->assertTrue($nodeDef->isMandatory());
34+
}
35+
36+
public function testGetNodeDefinitionWildcard()
37+
{
38+
// defines a child of nt:folder
39+
$node = $this->rootNode->getNode('tests_general_base/index.txt');
40+
$nodeDef = $node->getDefinition();
41+
$this->assertInstanceOf('PHPCR\\NodeType\\NodeDefinitionInterface', $nodeDef);
42+
$this->assertEquals('*', $nodeDef->getName());
43+
}
44+
}

tests/NodeTypeDiscovery/PropertyDefinitionTest.php

+65-11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace PHPCR\Tests\NodeTypeDiscovery;
1313

14+
use PHPCR\NodeType\NodeTypeInterface;
15+
use PHPCR\NodeType\NodeTypeManagerInterface;
16+
use PHPCR\NodeType\PropertyDefinitionInterface;
1417
use PHPCR\Query\QOM\QueryObjectModelConstantsInterface;
1518

1619
/**
@@ -20,26 +23,77 @@
2023
*/
2124
class PropertyDefinitionTest extends \PHPCR\Test\BaseCase
2225
{
26+
/**
27+
* @var NodeTypeInterface
28+
*/
2329
private static $base;
30+
31+
/**
32+
* @var NodeTypeInterface
33+
*/
2434
private static $address;
35+
36+
/**
37+
* @var NodeTypeInterface
38+
*/
2539
private static $mix_created;
40+
41+
/**
42+
* @var NodeTypeInterface
43+
*/
2644
private static $resource;
2745

28-
/** nt:base property */
29-
private $primaryType; // (NAME) mandatory autocreated protected COMPUTE
30-
private $mixinTypes; // (NAME) protected multiple COMPUTE
46+
// properties of nt:base
47+
/**
48+
* (NAME) mandatory autocreated protected COMPUTE
49+
* @var PropertyDefinitionInterface
50+
*/
51+
private $primaryType;
52+
53+
/**
54+
* (NAME) protected multiple COMPUTE
55+
* @var PropertyDefinitionInterface
56+
*/
57+
private $mixinTypes;
58+
3159
/** properties of nt:address */
32-
private $workspace; // (STRING)
33-
private $pathprop; // (PATH)
34-
private $id; // (WEAKREFERENCE)
35-
/** property of mix:created */
36-
private $created; // (DATE) autocreated protected
37-
/** property of nt:resource */
38-
private $data; // (BINARY) mandatory
60+
61+
/**
62+
* (STRING)
63+
* @var PropertyDefinitionInterface
64+
*/
65+
private $workspace;
66+
67+
/**
68+
* (PATH)
69+
* @var PropertyDefinitionInterface
70+
*/
71+
private $pathprop;
72+
73+
/**
74+
* (WEAKREFERENCE)
75+
* @var PropertyDefinitionInterface
76+
*/
77+
private $id;
78+
79+
/**
80+
* (DATE) autocreated protected
81+
* property of mix:created
82+
* @var PropertyDefinitionInterface
83+
*/
84+
private $created; //
85+
86+
/**
87+
* (BINARY) mandatory
88+
* property of nt:resource
89+
* @var PropertyDefinitionInterface
90+
*/
91+
private $data; //
3992

4093
public static function setupBeforeClass($fixtures = false)
4194
{
4295
parent::setupBeforeClass(); // load default fixtures
96+
/** @var NodeTypeManagerInterface $ntm */
4397
$ntm = self::$staticSharedFixture['session']->getWorkspace()->getNodeTypeManager();
4498
self::$base = $ntm->getNodeType('nt:base');
4599
self::$address = $ntm->getNodeType('nt:address');
@@ -238,7 +292,7 @@ public function testGetPropertyDefinitionExact()
238292
$this->assertEquals('jcr:created', $propDef->getName());
239293
}
240294

241-
public function estGetPropertyDefinitionWildcard()
295+
public function testGetPropertyDefinitionWildcard()
242296
{
243297
$node = $this->rootNode->getNode('tests_general_base/numberPropertyNode/jcr:content');
244298
$valProperty = $node->getProperty('foo');

0 commit comments

Comments
 (0)