Skip to content

adding tests for Node::getDefinition #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions tests/NodeTypeDiscovery/NodeDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,52 @@

namespace PHPCR\Tests\NodeTypeDiscovery;

use PHPCR\NodeType\NodeDefinitionInterface;
use PHPCR\NodeType\NodeTypeInterface;
use PHPCR\NodeType\NodeTypeManagerInterface;

/**
* Test the NoteDefinition §8.
* Test NodeDefinition behaviour and reading NodeDefinition from NodeTypeDefinition §8.
*
* Requires that NodeTypeManager->getNodeType and NodeTypeDefinition->getChildNodeDefinitions() works correctly
*/
class NodeDefinitionTest extends \PHPCR\Test\BaseCase
{
private static $base;

/**
* @var NodeTypeInterface
*/
private static $file;

/**
* @var NodeTypeInterface
*/
private static $folder;

/**
* @var NodeTypeInterface
*/
private static $hierarchyNodeType;
/** jcr:content of nt:file */

/**
* Node definition of the jcr:content in an nt:file type.
*
* @var NodeDefinitionInterface
*/
private $content;

/**
* Node definition of a hierarchy node.
*
* @var NodeDefinitionInterface
*/
private $hierarchyNodeDef;

public static function setupBeforeClass($fixtures = false)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem in jackalope-doctrine-dbal was that we have no fixtures we load for this test. in jackrabbit, fixtures are not removed in this case so we did not see the mistake. separated the tests now.

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

public function setUp()
{
parent::setUp();
try {
$defs = self::$file->getChildNodeDefinitions();
$this->assertInternalType('array', $defs);
Expand All @@ -55,6 +84,7 @@ public function setUp()
$this->markTestSkipped('getChildNodeDefinitions not working as it should, skipping tests about NodeDefinitionInterface: '.$e->getMessage());
}
}

public function testAllowsSameNameSiblings()
{
$this->assertFalse($this->content->allowsSameNameSiblings());
Expand All @@ -64,10 +94,12 @@ public function testDefaultPrimaryType()
{
$this->assertNull($this->content->getDefaultPrimaryType());
}

public function testDefaultPrimaryTypeName()
{
$this->assertNull($this->content->getDefaultPrimaryTypeName());
}

public function getRequiredPrimaryTypeNames()
{
$names = $this->content->getRequiredPrimaryTypeNames();
Expand Down Expand Up @@ -102,26 +134,31 @@ public function testGetDeclaringNodeType()
$nt = $this->hierarchyNodeDef->getDeclaringNodeType();
$this->assertSame(self::$folder, $nt);
}

public function testName()
{
$this->assertEquals('jcr:content', $this->content->getName());
$this->assertEquals('*', $this->hierarchyNodeDef->getName());
}

public function testGetOnParentVersion()
{
$this->assertEquals(\PHPCR\Version\OnParentVersionAction::COPY, $this->content->getOnParentVersion());
$this->assertEquals(\PHPCR\Version\OnParentVersionAction::VERSION, $this->hierarchyNodeDef->getOnParentVersion());
}

public function testIsAutoCreated()
{
$this->assertFalse($this->content->isAutoCreated());
$this->assertFalse($this->hierarchyNodeDef->isAutoCreated());
}

public function testIsMandatory()
{
$this->assertTrue($this->content->isMandatory());
$this->assertFalse($this->hierarchyNodeDef->isMandatory());
}

public function testIsProtected()
{
$this->assertFalse($this->content->isProtected());
Expand Down
44 changes: 44 additions & 0 deletions tests/NodeTypeDiscovery/NodeNodeDefinitionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the PHPCR API Tests package
*
* Copyright (c) 2015 Liip and others
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPCR\Tests\NodeTypeDiscovery;

use PHPCR\NodeType\NodeDefinitionInterface;
use PHPCR\NodeType\NodeTypeInterface;
use PHPCR\NodeType\NodeTypeManagerInterface;
use PHPCR\Test\BaseCase;

/**
* Test reading NodeDefinition from Nodes §8.
*
* @see NodeInterface::getDefinition
*/
class NodeNodeDefinitionTest extends BaseCase
{
public function testGetNodeDefinitionExact()
{
// an nt:file must have a jcr:content property
$node = $this->rootNode->getNode('tests_general_base/numberPropertyNode/jcr:content');
$nodeDef = $node->getDefinition();
$this->assertInstanceOf('PHPCR\\NodeType\\NodeDefinitionInterface', $nodeDef);
$this->assertEquals('jcr:content', $nodeDef->getName());
$this->assertTrue($nodeDef->isMandatory());
}

public function testGetNodeDefinitionWildcard()
{
// defines a child of nt:folder
$node = $this->rootNode->getNode('tests_general_base/index.txt');
$nodeDef = $node->getDefinition();
$this->assertInstanceOf('PHPCR\\NodeType\\NodeDefinitionInterface', $nodeDef);
$this->assertEquals('*', $nodeDef->getName());
}
}
76 changes: 65 additions & 11 deletions tests/NodeTypeDiscovery/PropertyDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace PHPCR\Tests\NodeTypeDiscovery;

use PHPCR\NodeType\NodeTypeInterface;
use PHPCR\NodeType\NodeTypeManagerInterface;
use PHPCR\NodeType\PropertyDefinitionInterface;
use PHPCR\Query\QOM\QueryObjectModelConstantsInterface;

/**
Expand All @@ -20,26 +23,77 @@
*/
class PropertyDefinitionTest extends \PHPCR\Test\BaseCase
{
/**
* @var NodeTypeInterface
*/
private static $base;

/**
* @var NodeTypeInterface
*/
private static $address;

/**
* @var NodeTypeInterface
*/
private static $mix_created;

/**
* @var NodeTypeInterface
*/
private static $resource;

/** nt:base property */
private $primaryType; // (NAME) mandatory autocreated protected COMPUTE
private $mixinTypes; // (NAME) protected multiple COMPUTE
// properties of nt:base
/**
* (NAME) mandatory autocreated protected COMPUTE
* @var PropertyDefinitionInterface
*/
private $primaryType;

/**
* (NAME) protected multiple COMPUTE
* @var PropertyDefinitionInterface
*/
private $mixinTypes;

/** properties of nt:address */
private $workspace; // (STRING)
private $pathprop; // (PATH)
private $id; // (WEAKREFERENCE)
/** property of mix:created */
private $created; // (DATE) autocreated protected
/** property of nt:resource */
private $data; // (BINARY) mandatory

/**
* (STRING)
* @var PropertyDefinitionInterface
*/
private $workspace;

/**
* (PATH)
* @var PropertyDefinitionInterface
*/
private $pathprop;

/**
* (WEAKREFERENCE)
* @var PropertyDefinitionInterface
*/
private $id;

/**
* (DATE) autocreated protected
* property of mix:created
* @var PropertyDefinitionInterface
*/
private $created; //

/**
* (BINARY) mandatory
* property of nt:resource
* @var PropertyDefinitionInterface
*/
private $data; //

public static function setupBeforeClass($fixtures = false)
{
parent::setupBeforeClass(); // load default fixtures
/** @var NodeTypeManagerInterface $ntm */
$ntm = self::$staticSharedFixture['session']->getWorkspace()->getNodeTypeManager();
self::$base = $ntm->getNodeType('nt:base');
self::$address = $ntm->getNodeType('nt:address');
Expand Down Expand Up @@ -238,7 +292,7 @@ public function testGetPropertyDefinitionExact()
$this->assertEquals('jcr:created', $propDef->getName());
}

public function estGetPropertyDefinitionWildcard()
public function testGetPropertyDefinitionWildcard()
{
$node = $this->rootNode->getNode('tests_general_base/numberPropertyNode/jcr:content');
$valProperty = $node->getProperty('foo');
Expand Down