diff --git a/tests/NodeTypeDiscovery/NodeDefinitionTest.php b/tests/NodeTypeDiscovery/NodeDefinitionTest.php index 6b41e1c2..063c02b2 100644 --- a/tests/NodeTypeDiscovery/NodeDefinitionTest.php +++ b/tests/NodeTypeDiscovery/NodeDefinitionTest.php @@ -74,14 +74,14 @@ public function setUp() $defs = self::$file->getChildNodeDefinitions(); $this->assertInternalType('array', $defs); $this->assertCount(1, $defs); - list($key, $this->content) = each($defs); + $this->content = current($defs); $this->assertInstanceOf(NodeDefinitionInterface::class, $this->content); $this->assertEquals('jcr:content', $this->content->getName()); $defs = self::$folder->getChildNodeDefinitions(); $this->assertInternalType('array', $defs); $this->assertCount(1, $defs); - list($key, $this->hierarchyNodeDef) = each($defs); + $this->hierarchyNodeDef = next($defs); $this->assertInstanceOf(NodeDefinitionInterface::class, $this->hierarchyNodeDef); $this->assertEquals('*', $this->hierarchyNodeDef->getName()); } catch (Exception $e) { diff --git a/tests/NodeTypeDiscovery/NodeTypeTest.php b/tests/NodeTypeDiscovery/NodeTypeTest.php index dc4bd561..c03148a8 100644 --- a/tests/NodeTypeDiscovery/NodeTypeTest.php +++ b/tests/NodeTypeDiscovery/NodeTypeTest.php @@ -157,7 +157,7 @@ public function testGetChildNodeDefinitions() $children = self::$file->getChildNodeDefinitions(); $this->assertInternalType('array', $children); $this->assertCount(1, $children); - list($key, $child) = each($children); + $child = current($children); $this->assertInstanceOf(NodeDefinitionInterface::class, $child); $this->assertEquals('jcr:content', $child->getName()); // the rest is tested in NodeDefinitionTest diff --git a/tests/NodeTypeManagement/NodeTypeBaseCase.php b/tests/NodeTypeManagement/NodeTypeBaseCase.php index 0c8c7c11..927020ff 100644 --- a/tests/NodeTypeManagement/NodeTypeBaseCase.php +++ b/tests/NodeTypeManagement/NodeTypeBaseCase.php @@ -98,7 +98,8 @@ protected function assertTypes($types) $this->assertCount(2, $types, 'Wrong number of nodes registered'); // apitest - list($name, $type) = each($types); + $type = current($types); + $name = key($types); $this->assertEquals('phpcr:apitest', $name); $this->assertInstanceOf(NodeTypeDefinitionInterface::class, $type); /* @var $type NodeTypeDefinitionInterface */ @@ -108,7 +109,8 @@ protected function assertTypes($types) $this->assertTrue($props[0]->isMultiple()); // test - list($name, $type) = each($types); + $type = next($types); + $name = key($types); $this->assertEquals('phpcr:test', $name); $this->assertInstanceOf(NodeTypeDefinitionInterface::class, $type); /* @var $type NodeTypeDefinitionInterface */ @@ -164,8 +166,7 @@ public function testPrimaryItem() $root = $this->session->getRootNode(); if ($root->hasNode('test_node')) { - $node = $root->getNode('test_node'); - $node->remove(); + $root->getNode('test_node')->remove(); $this->session->save(); } diff --git a/tests/NodeTypeManagement/NodeTypeTest.php b/tests/NodeTypeManagement/NodeTypeTest.php index c7b94dcf..670918ec 100644 --- a/tests/NodeTypeManagement/NodeTypeTest.php +++ b/tests/NodeTypeManagement/NodeTypeTest.php @@ -11,6 +11,7 @@ namespace PHPCR\Tests\NodeTypeManagement; +use PHPCR\NodeType\NodeTypeDefinitionInterface; use PHPCR\PropertyType; /** @@ -18,6 +19,45 @@ */ class NodeTypeTest extends NodeTypeBaseCase { + public function testRegisterNodeType() + { + $ns = $this->workspace->getNamespaceRegistry(); + $ns->registerNamespace('phpcr', 'http://www.doctrine-project.org/projects/phpcr_odm'); + + $ntm = $this->workspace->getNodeTypeManager(); + + $apitest = $ntm->createNodeTypeTemplate(); + $apitest->setName('phpcr:apitest'); + $apitest->setMixin(true); + + $class = $ntm->createPropertyDefinitionTemplate(); + $class->setName('phpcr:class'); + $class->setRequiredType(PropertyType::STRING); + $class->setMultiple(true); + $apitest->getPropertyDefinitionTemplates()->append($class); + + $type = $ntm->registerNodeType($apitest, true); + + $this->assertApitestType($type); + + $session = $this->renewSession(); + $ntm = $session->getWorkspace()->getNodeTypeManager(); + + $this->assertTrue($ntm->hasNodeType('phpcr:apitest')); + $this->assertApitestType($ntm->getNodeType('phpcr:apitest')); + } + + private function assertApitestType($type) + { + $this->assertInstanceOf(NodeTypeDefinitionInterface::class, $type); + /* @var $type NodeTypeDefinitionInterface */ + $this->assertEquals('phpcr:apitest', $type->getName()); + $props = $type->getDeclaredPropertyDefinitions(); + $this->assertCount(1, $props, 'Wrong number of properties in phpcr:apitest'); + $this->assertEquals('phpcr:class', $props[0]->getName()); + $this->assertTrue($props[0]->isMultiple()); + } + protected function registerNodeTypes($allowUpdate) { $ns = $this->workspace->getNamespaceRegistry(); diff --git a/tests/PhpcrUtils/CndParserTest.php b/tests/PhpcrUtils/CndParserTest.php index 859a7f30..caf82f40 100644 --- a/tests/PhpcrUtils/CndParserTest.php +++ b/tests/PhpcrUtils/CndParserTest.php @@ -197,7 +197,8 @@ protected function assertExampleCnd($res) // get first node type reset($res['nodeTypes']); /** @var $def NodeTypeDefinitionInterface */ - list($name, $def) = each($res['nodeTypes']); + $def = current($res['nodeTypes']); + $name = key($res['nodeTypes']); $this->assertEquals('ns:NodeType', $name); $this->assertInstanceOf(NodeTypeTemplateInterface::class, $def); diff --git a/tests/Reading/SessionReadMethodsTest.php b/tests/Reading/SessionReadMethodsTest.php index 67107619..b5f9d337 100644 --- a/tests/Reading/SessionReadMethodsTest.php +++ b/tests/Reading/SessionReadMethodsTest.php @@ -305,10 +305,10 @@ public function testGetNodesByIdentifier() ]); $this->assertCount(2, $nodes); - list($key, $node) = each($nodes); + $node = current($nodes); $this->assertInstanceOf(NodeInterface::class, $node); $this->assertEquals('/tests_general_base/idExample', $node->getPath()); - list($key, $node) = each($nodes); + $node = next($nodes); $this->assertInstanceOf(NodeInterface::class, $node); $this->assertEquals('/tests_general_base/idExample/jcr:content/weakreference_target', $node->getPath()); } @@ -322,10 +322,10 @@ public function testGetNodesByIdentifierTraversable() ])); $this->assertCount(2, $nodes); - list($key, $node) = each($nodes); + $node = current($nodes); $this->assertInstanceOf(NodeInterface::class, $node); $this->assertEquals('/tests_general_base/idExample', $node->getPath()); - list($key, $node) = each($nodes); + $node = next($nodes); $this->assertInstanceOf(NodeInterface::class, $node); $this->assertEquals('/tests_general_base/idExample/jcr:content/weakreference_target', $node->getPath()); } diff --git a/tests/SameNameSiblings/DeleteMethodsTest.php b/tests/SameNameSiblings/DeleteMethodsTest.php index 6e11ef77..64d460b6 100644 --- a/tests/SameNameSiblings/DeleteMethodsTest.php +++ b/tests/SameNameSiblings/DeleteMethodsTest.php @@ -140,10 +140,12 @@ public function testDeleteManyNodes() $parent = $this->session->getNode($parentPath); $this->assertCount(count($childrenAtEnd), $parent->getNodes()); + $childValue = -1; foreach ($parent->getNodes() as $node) { - $child = each($childrenAtEnd); - $this->assertEquals($parentPath.'/'.$child['key'], $node->getPath()); - $this->assertEquals($child['value'], $node->getProperty('childNumber')->getValue()); + $childValue = (-1 === $childValue) ? current($childrenAtEnd) : next($childrenAtEnd); + $childKey = key($childrenAtEnd); + $this->assertEquals($parentPath.'/'.$childKey, $node->getPath()); + $this->assertEquals($childValue, $node->getProperty('childNumber')->getValue()); } }