|
| 1 | +<?php |
| 2 | +namespace PHPCR\Tests\Writing; |
| 3 | + |
| 4 | +require_once(__DIR__ . '/../../inc/BaseCase.php'); |
| 5 | + |
| 6 | +/** |
| 7 | + * Testing that mix:referenceable nodes references work correctly |
| 8 | + * |
| 9 | + * Covering jcr-2.8.3 spec $10.10.3 |
| 10 | + */ |
| 11 | +class MixinCreatedTest extends \PHPCR\Test\BaseCase |
| 12 | +{ |
| 13 | + public function setUp() |
| 14 | + { |
| 15 | + $this->renewSession(); // discard changes |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * Test that a node with newly set mix:referenceable type can be referenced |
| 20 | + */ |
| 21 | + public function testCreationNode() |
| 22 | + { |
| 23 | + $path = '/tests_general_base/idExample/jcr:content'; |
| 24 | + /** @var $node \PHPCR\NodeInterface */ |
| 25 | + $node = $this->sharedFixture['session']->getNode($path); |
| 26 | + $child = $node->addNode('test'); |
| 27 | + $path .= '/test'; |
| 28 | + $this->assertEquals($path, $child->getPath()); |
| 29 | + $child->addMixin('mix:created'); |
| 30 | + |
| 31 | + $this->sharedFixture['session']->save(); |
| 32 | + |
| 33 | + $this->assertTrue($child->isNodeType('mix:created')); |
| 34 | + $this->assertTrue($child->hasProperty('jcr:created')); |
| 35 | + $date = $child->getPropertyValue('jcr:created'); |
| 36 | + $this->assertInstanceOf('DateTime', $date); |
| 37 | + /** @var $date \DateTime */ |
| 38 | + $diff = time() - $date->getTimestamp(); |
| 39 | + $this->assertTrue($diff < 60*10, "jcr:created should be current date as fixture was just imported: ".$date->format('c')); |
| 40 | + |
| 41 | + // Re-read the node to be sure things got properly saved |
| 42 | + $this->renewSession(); |
| 43 | + $child = $this->sharedFixture['session']->getNode($path); |
| 44 | + |
| 45 | + $this->assertTrue($child->isNodeType('mix:created')); |
| 46 | + $this->assertTrue($child->hasProperty('jcr:created')); |
| 47 | + $date = $child->getPropertyValue('jcr:created'); |
| 48 | + $this->assertInstanceOf('DateTime', $date); |
| 49 | + $diff = time() - $date->getTimestamp(); |
| 50 | + $this->assertTrue($diff < 60*10, "jcr:created should be current date as fixture was just imported: ".$date->format('c')); |
| 51 | + } |
| 52 | +} |
0 commit comments