public function setUp() { $this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\QuerySql2TestObj'; $this->dm = $this->createDocumentManager(); $this->node = $this->resetFunctionalNode($this->dm); $versionNode = $this->node->addNode('node1', 'nt:unstructured'); $versionNode->setProperty('username', 'dbu'); $versionNode->setProperty('numbers', array(3, 1, 2)); $versionNode->setProperty('phpcr:class', $this->type); $versionNode = $this->node->addNode('node2', 'nt:unstructured'); $versionNode->setProperty('username', 'johannes'); $versionNode->setProperty('numbers', array(3, 1, 2)); $versionNode->setProperty('phpcr:class', $this->type); $versionNode = $this->node->addNode('node3', 'nt:unstructured'); $versionNode->setProperty('username', 'lsmith'); $versionNode->setProperty('numbers', array(3, 1, 2)); $versionNode->setProperty('phpcr:class', $this->type); $versionNode = $this->node->addNode('node4', 'nt:unstructured'); $versionNode->setProperty('username', 'uwe'); $versionNode->setProperty('numbers', array(3, 1, 2)); $versionNode->setProperty('phpcr:class', $this->type); $versionNode = $this->node->addNode('node5', 'nt:unstructured'); $versionNode->setProperty('numbers', array(3, 1, 2)); $this->dm->getPhpcrSession()->save(); $this->dm = $this->createDocumentManager(); }
public function testSaveTranslation() { // First save some translations $data = array(); $data['topic'] = 'Some interesting subject'; $data['text'] = 'Lorem ipsum...'; $node = $this->getTestNode(); $strategy = new ChildTranslationStrategy($this->dm); $strategy->saveTranslation($data, $node, $this->metadata, 'en'); // Save translation in another language $data['topic'] = 'Un sujet intéressant'; $strategy->saveTranslation($data, $node, $this->metadata, 'fr'); $this->dm->getPhpcrSession()->save(); // Then test we have what we expect in the content repository $node_en = $this->session->getNode($this->nodeNameForLocale('en')); $node_fr = $this->session->getNode($this->nodeNameForLocale('fr')); $this->assertTrue($node_en->hasProperty('topic')); $this->assertTrue($node_fr->hasProperty('topic')); $this->assertTrue($node_en->hasProperty('text')); $this->assertTrue($node_fr->hasProperty('text')); $this->assertFalse($node_fr->hasProperty('author')); $this->assertFalse($node_en->hasProperty('author')); $this->assertEquals('Some interesting subject', $node_en->getPropertyValue('topic')); $this->assertEquals('Un sujet intéressant', $node_fr->getPropertyValue('topic')); $this->assertEquals('Lorem ipsum...', $node_en->getPropertyValue('text')); $this->assertEquals('Lorem ipsum...', $node_fr->getPropertyValue('text')); }
public function setUp() { $this->dm = $this->createDocumentManager(); $this->node = $this->resetFunctionalNode($this->dm); $session = $this->dm->getPhpcrSession(); if (!$session instanceof \Jackalope\Session) { $this->markTestSkipped('Not a Jackalope session'); } $cnd = <<<CND <test='http://test.fr'> [test:protected_property_test] > nt:hierarchyNode - reference (REFERENCE) - changeme (STRING) CND; $cnd2 = <<<CND <test='http://test.fr'> [test:protected_property_test2] > nt:hierarchyNode - reference (REFERENCE) - reference2 (REFERENCE) CND; $ntm = $session->getWorkspace()->getNodeTypeManager(); try { $ntm->registerNodeTypesCnd($cnd, true); $ntm->registerNodeTypesCnd($cnd2, true); } catch (\PHPCR\UnsupportedRepositoryOperationException $e) { $this->markTestSkipped('CND parsing not supported'); } }
public function setUp() { $this->dm = $this->createDocumentManager(array(__DIR__)); $repository = $this->dm->getPhpcrSession()->getRepository(); if (!$repository->getDescriptor('node.type.management.orderable.child.nodes.supported')) { $this->markTestSkipped('PHPCR repository doesn\'t support orderable child nodes'); } $this->node = $this->resetFunctionalNode($this->dm); $parent = $this->dm->find(null, $this->node->getPath()); $node1 = new Generic(); $node1->setParentDocument($parent); $node1->setNodename('source'); $this->dm->persist($node1); $this->childrenNames = array('first', 'second', 'third', 'fourth'); foreach ($this->childrenNames as $childName) { $child = new Generic(); $child->setNodename($childName); $child->setParentDocument($node1); $this->dm->persist($child); } $node2 = new Generic(); $node2->setNodename('target'); $node2->setParentDocument($parent); $this->dm->persist($node2); $this->dm->flush(); $this->dm->clear(); }
public function setUp() { $this->type = 'Doctrine\\Tests\\Models\\CMS\\CmsUser'; $this->dm = $this->createDocumentManager(array(__DIR__)); $this->node = $this->resetFunctionalNode($this->dm); $user = $this->node->addNode('lsmith'); $user->setProperty('username', 'lsmith'); $user->setProperty('numbers', array(3, 1, 2)); $user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING); $this->dm->getPhpcrSession()->save(); }
public function setUp() { $this->type = 'Doctrine\\Tests\\Models\\CMS\\CmsUser'; $this->dm = $this->createDocumentManager(); $session = $this->dm->getPhpcrSession(); $root = $session->getNode('/'); if ($root->hasNode('functional')) { $root->getNode('functional')->remove(); $session->save(); } $this->node = $root->addNode('functional'); $session->save(); }
public function setUp() { $this->type = 'Doctrine\\Tests\\ODM\\PHPCR\\Functional\\TypeUser'; $this->dm = $this->createDocumentManager(array(__DIR__)); $this->node = $this->resetFunctionalNode($this->dm); $user = $this->node->addNode('user'); $user->setProperty('username', 'lsmith'); $user->setProperty('note', 'test'); $user->setProperty('numbers', array(3, 1, 2)); $user->setProperty('parameters', array('bar', 'dong')); $user->setProperty('parameterKey', array('foo', 'ding')); $user->setProperty('phpcr:class', $this->type, PropertyType::STRING); $this->dm->getPhpcrSession()->save(); }
public function setUp() { $this->type = 'Doctrine\\Tests\\Models\\Translation\\Article'; $this->dm = $this->createDocumentManager(); $this->dm->setLocaleChooserStrategy(new LocaleChooser(array('en' => array('fr'), 'fr' => array('en')), 'en')); $this->node = $this->resetFunctionalNode($this->dm); $user = $this->node->addNode('thename'); $user->setProperty('phpcr:class', $this->type, \PHPCR\PropertyType::STRING); $user->setProperty('phpcr_locale:fr-topic', 'french', \PHPCR\PropertyType::STRING); $user->setProperty('phpcr_locale:fr-text', 'french text', \PHPCR\PropertyType::STRING); $user->setProperty('phpcr_locale:frnullfields', array('nullable'), \PHPCR\PropertyType::STRING); $user->setProperty('phpcr_locale:en-topic', 'english', \PHPCR\PropertyType::STRING); $user->setProperty('phpcr_locale:en-text', 'english text', \PHPCR\PropertyType::STRING); $user->setProperty('phpcr_locale:ennullfields', array('nullable'), \PHPCR\PropertyType::STRING); $this->dm->getPhpcrSession()->save(); }
/** * Constructor * * @param SessionInterface $session * @param DocumentManager $dm */ public function __construct(SessionInterface $session = null, DocumentManager $dm = null) { if (!$session && $dm) { $session = $dm->getPhpcrSession(); } parent::__construct($session); $this->dm = $dm; }
/** * Copy file into another file (only inside one volume) * * @param string $source source file path * @param string $targetDir target dir path * @param string $name file name * @return bool * @author Dmitry (dio) Levashov **/ protected function _copy($source, $targetDir, $name) { if ($this->dm->find(null, $targetPath = $this->_joinPath($targetDir, $name))) { return false; } $this->dm->getPhpcrSession()->getWorkspace()->copy($source, $targetPath); return true; }
public function setUp() { $this->type = 'Doctrine\\Tests\\Models\\CMS\\CmsUser'; $this->dm = $this->createDocumentManager(array(__DIR__)); $this->node = $this->resetFunctionalNode($this->dm); $user = $this->node->addNode('lsmith'); $user->setProperty('username', 'lsmith'); $user->setProperty('numbers', array(3, 1, 2)); $user->setProperty('phpcr:class', $this->type, PropertyType::STRING); $this->dm->getPhpcrSession()->save(); // remove node for root tests $session = $this->dm->getPhpcrSession(); $root = $session->getNode('/'); if ($root->hasNode('dbu')) { $root->getNode('dbu')->remove(); $session->save(); } }
/** * Check that persisting a node with the versionable type will add the correct mixin to the node */ public function testAnnotationOnPersist() { $repository = $this->dm->getPhpcrSession()->getRepository(); if (!$repository->getDescriptor('option.versioning.supported')) { $this->markTestSkipped('PHPCR repository doesn\'t support versioning'); } $node = $this->createTestDocument('versionable-article-test', 'Doctrine\\Tests\\Models\\Versioning\\VersionableArticle'); $this->assertTrue($node->isNodeType('mix:simpleVersionable')); $this->assertFalse($node->isNodeType('mix:versionable')); // mix:versionable derives from mix:simpleVersionable, so a full versionable node will be both types $node = $this->createTestDocument('versionable-article-test', 'Doctrine\\Tests\\Models\\Versioning\\FullVersionableArticle'); $this->assertTrue($node->isNodeType('mix:versionable')); $this->assertTrue($node->isNodeType('mix:simpleVersionable')); $node = $this->createTestDocument('versionable-article-test', 'Doctrine\\Tests\\Models\\Versioning\\NonVersionableArticle'); $this->assertFalse($node->isNodeType('mix:simpleVersionable')); $this->assertFalse($node->isNodeType('mix:versionable')); $node = $this->createTestDocument('versionable-article-test', 'Doctrine\\Tests\\Models\\Versioning\\ExtendedVersionableArticle'); $this->assertTrue($node->isNodeType('mix:simpleVersionable')); $this->assertTrue($node->isNodeType('mix:versionable')); }
public function testChangeset() { $user = $this->node->getNode('user'); // the property is not nullable, but this should only be checked on saving, not on loading $user->getProperty('username')->remove(); $this->dm->getPhpcrSession()->save(); $userDoc = $this->dm->find(null, $user->getPath()); $this->assertInstanceOf($this->type, $userDoc); $this->assertNull($userDoc->username); // nothing should happen, we did not alter any value $this->dm->flush(); }
/** * No translation whatsoever is available. All translated fields have to be * null as we do not validate on loading. */ public function testFindNullableFieldNone() { $node = $this->node->addNode('find'); $node->setProperty('phpcr:class', 'Doctrine\\Tests\\Models\\Translation\\Article'); $this->dm->getPhpcrSession()->save(); $this->dm->clear(); /** @var $doc Article */ $doc = $this->dm->find(null, $this->node->getPath() . '/find'); $this->assertEquals('en', $doc->locale); $this->assertNull($doc->topic); $this->assertNull($doc->text); }
public function resetFunctionalNode(DocumentManager $dm) { $session = $dm->getPhpcrSession(); $root = $session->getNode('/'); if ($root->hasNode('functional')) { $root->getNode('functional')->remove(); $session->save(); } $node = $root->addNode('functional'); $session->save(); $dm->clear(); return $node; }
function testParentOfReference() { $doc = $this->dm->find($this->type, '/functional/thename'); $doc->node->addMixin('mix:referenceable'); $this->dm->getPhpcrSession()->save(); $referrer = new NameDocWithRef(); $referrer->id = '/functional/referrer'; $referrer->ref = $doc; $this->dm->persist($referrer); $this->dm->flush(); $this->dm->clear(); $referrer = $this->dm->find(null, '/functional/referrer'); $this->assertInstanceOf('\\Doctrine\\ODM\\PHPCR\\Document\\Generic', $referrer->ref->parent); }
/** * Get the state of this document * * STATE_NEW: the document is not persisted, but a valid mapped document * STATE_MANAGED: the document is tracked and will be updated on flush * STATE_REMOVED: the document is scheduled for removal * STATE_DETACHED: there is a corresponding Node in storage, but this document is not bound to it * * @param object $document the document to get the state of * * @return int one of the STATE_* constants of this class */ public function getDocumentState($document) { $oid = spl_object_hash($document); if (!isset($this->documentState[$oid])) { // this will only use the metadata if id is mapped $id = $this->determineDocumentId($document); if (!$id) { return self::STATE_NEW; } if ($this->getDocumentById($id)) { return self::STATE_DETACHED; } return $this->dm->getPhpcrSession()->nodeExists($id) ? self::STATE_DETACHED : self::STATE_NEW; } return $this->documentState[$oid]; }
public function testQueryBuilder() { $strategy = new AttributeTranslationStrategy($this->dm); $this->dm->setTranslationStrategy('attribute', $strategy); $this->dm->setLocaleChooserStrategy(new LocaleChooser(array('en' => array('fr'), 'fr' => array('en')), 'en')); // First save some translations $data = array(); $data['topic'] = 'Some interesting subject'; $data['text'] = 'Lorem ipsum...'; $data['settings'] = array('is-active' => 'true', 'url' => 'great-article-in-english.html'); $node = $this->getTestNode(); $node->setProperty('author', 'John Doe'); $node->setProperty('phpcr:class', 'Doctrine\\Tests\\Models\\Translation\\Article'); $strategy->saveTranslation($data, $node, $this->metadata, 'en'); // Save translation in another language $data['topic'] = 'Un sujet intéressant'; $data['settings'] = array('is-active' => 'true', 'url' => 'super-article-en-francais.html'); $strategy->saveTranslation($data, $node, $this->metadata, 'fr'); $this->dm->getPhpcrSession()->save(); $qb = $this->dm->createQueryBuilder(); $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\Article', 'a'); $qb->where()->eq()->field('a.topic')->literal('Not Exist')->end(); $res = $qb->getQuery()->execute(); $this->assertCount(0, $res); $qb = $this->dm->createQueryBuilder(); $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\Article', 'a'); $qb->where()->eq()->field('a.topic')->literal('Un sujet intéressant')->end(); $res = $qb->getQuery()->execute(); $this->assertCount(0, $res); $qb = $this->dm->createQueryBuilder(); $qb->setLocale(false); $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\Article', 'a'); $qb->where()->eq()->field('a.topic')->literal('Un sujet intéressant')->end(); $res = $qb->getQuery()->execute(); $this->assertCount(0, $res); $qb = $this->dm->createQueryBuilder(); $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\Article', 'a'); $qb->where()->eq()->field('a.topic')->literal('Some interesting subject')->end(); $res = $qb->getQuery()->execute(); $this->assertCount(1, $res); $qb = $this->dm->createQueryBuilder(); $qb->setLocale('fr'); $qb->from()->document('Doctrine\\Tests\\Models\\Translation\\Article', 'a'); $qb->where()->eq()->field('a.topic')->literal('Un sujet intéressant')->end(); $res = $qb->getQuery()->execute(); $this->assertCount(1, $res); }
public function testRemoveVersion() { $doc = $this->dm->find($this->typeVersion, '/functional/versionTestObj'); $this->dm->checkpoint($doc); $linearVersionHistory = $this->dm->getAllLinearVersions($doc); $lastVersion = end($linearVersionHistory); $lastVersionName = $lastVersion['name']; // Create a new version so that we are not trying to remove the last version $this->dm->checkpoint($doc); // Remove the version $version = $this->dm->findVersionByName($this->typeVersion, '/functional/versionTestObj', $lastVersionName); $removedVersionPath = $version->id; $this->dm->removeVersion($version); // Check it's not in the history anymore $this->assertFalse($this->dm->getPhpcrSession()->nodeExists(PathHelper::getParentPath($removedVersionPath))); return $lastVersionName; }
/** * @param object $document * @return int */ private function getDocumentState($document) { $oid = spl_object_hash($document); if (!isset($this->documentState[$oid])) { $class = $this->dm->getClassMetadata(get_class($document)); $id = $class->getIdentifierValue($document); if (!$id) { return self::STATE_NEW; } if ($class->idGenerator === ClassMetadata::GENERATOR_TYPE_ASSIGNED || $class->idGenerator === ClassMetadata::GENERATOR_TYPE_PARENT) { if ($this->getDocumentById($id)) { return self::STATE_DETACHED; } return $this->dm->getPhpcrSession()->nodeExists($id) ? self::STATE_DETACHED : self::STATE_NEW; } return self::STATE_DETACHED; } return $this->documentState[$oid]; }
public function testMoveByAssignmentWithProxy() { $user = $this->node->getNode('dbu')->addNode('assistant'); $user->setProperty('username', 'foo'); $user->setProperty('status', 'created'); $user->setProperty('phpcr:class', $this->type, PropertyType::STRING); $this->dm->getPhpcrSession()->save(); $this->dm->clear(); $user = $this->dm->find($this->type, '/functional/dbu'); $this->assertNotNull($user, 'User must exist'); $team = $this->dm->find($this->type, '/functional/team'); $this->assertNotNull($team, 'Team must exist'); $user->parent = $team; $this->assertFalse($user->child->__isInitialized()); $this->dm->flush(); $this->assertFalse($user->child->__isInitialized()); $this->assertEquals('/functional/team/dbu/assistant', $user->child->getId()); $this->assertEquals('foo', $user->child->getUsername()); }
/** * Use the parent field together with an auto generated name to generate the id * * {@inheritDoc} */ public function generate($document, ClassMetadata $class, DocumentManager $dm, $parent = null) { if (null === $parent) { $parent = $class->parentMapping ? $class->getFieldValue($document, $class->parentMapping) : null; } $id = $class->getFieldValue($document, $class->identifier); if (empty($id) && null === $parent) { throw IdException::noIdNoParent($document, $class->parentMapping); } if (empty($parent)) { return $id; } try { $parentNode = $dm->getNodeForDocument($parent); $existingNames = (array) $parentNode->getNodeNames(); } catch (RepositoryException $e) { // this typically happens while cascading persisting documents $existingNames = array(); } $name = NodeHelper::generateAutoNodeName($existingNames, $dm->getPhpcrSession()->getWorkspace()->getNamespaceRegistry()->getNamespaces(), '', ''); return $this->buildName($document, $class, $dm, $parent, $name); }
public function testReorderChildrenLast() { if (!$this->dm->getPhpcrSession()->getRepository()->getDescriptor(RepositoryInterface::NODE_TYPE_MANAGEMENT_ORDERABLE_CHILD_NODES_SUPPORTED)) { $this->markTestSkipped('Reordering of children not supported'); } $this->createChildren(); $parent = $this->dm->find($this->type, '/functional/parent'); $this->assertCount(4, $parent->allChildren); /** @var $childrenCollection \Doctrine\ODM\PHPCR\ChildrenCollection */ $childrenCollection = $parent->allChildren; $children = $childrenCollection->toArray(); $childrenCollection->clear(); $expectedOrder = array('Child A', 'Child D', 'Child C', 'Child B'); foreach ($expectedOrder as $name) { $childrenCollection->set($name, $children[$name]); } $this->assertEquals($expectedOrder, $parent->allChildren->getKeys()); $this->dm->flush(); $this->dm->clear(); $parent = $this->dm->find($this->type, '/functional/parent'); $this->assertCount(4, $parent->allChildren); $this->assertEquals($expectedOrder, $parent->allChildren->getKeys()); }
public function testRepeatedFlush() { $user1 = new CmsUser(); $user1->username = '******'; $user2 = new CmsTeamUser(); $user2->username = '******'; $user2->parent = $user1; $user3 = new CmsTeamUser(); $user3->username = '******'; $user3->parent = $user2; $group = new CmsGroup(); $group->id = '/functional/group'; $group->setName('foo'); $group->addUser($user1); $group->addUser($user2); $group->addUser($user3); $this->dm->persist($group); $this->assertCount(3, $group->getUsers()); $this->dm->flush(); $user4 = new CmsTeamUser(); $user4->username = '******'; $user4->parent = $user1; $group->addUser($user4); $this->assertCount(4, $group->getUsers()); $this->dm->flush(); $this->dm->getPhpcrSession()->removeItem($user2->id); $this->dm->getPhpcrSession()->save(); $this->dm->flush(); $this->assertInstanceOf('\\PHPCR\\NodeInterface', $user1->node); $this->assertCount(4, $group->getUsers()); $this->dm->clear(); $group = $this->dm->find(null, '/functional/group'); $group->getUsers()->first(); $this->assertCount(2, $group->getUsers()); $this->assertInstanceOf('\\PHPCR\\NodeInterface', $group->getUsers()->first()->node); }
/** * @inheritDoc */ public function purge() { $session = $this->dm->getPhpcrSession(); NodeHelper::deleteAllNodes($session); $session->save(); }
public function setUp() { $this->dm = $this->createDocumentManager(); $this->session = $this->dm->getPhpcrSession(); $this->node = $this->resetFunctionalNode($this->dm); }
public function setUp() { $this->dm = $this->createDocumentManager(array(__DIR__)); $this->node = $this->resetFunctionalNode($this->dm); $this->dm->getPhpcrSession()->save(); }
public function setup() { $this->dm = $this->createDocumentManager(); $this->workspace = $this->dm->getPhpcrSession()->getWorkspace(); }
public function setUp() { $this->dm = $this->createDocumentManager(); $this->node = $this->resetFunctionalNode($this->dm); $session = $this->dm->getPhpcrSession(); // comment // post // user NodeHelper::createPath($session, '/functional/user'); NodeHelper::createPath($session, '/functional/post'); $user = new BlogUser(); $user->id = '/functional/user/dtl'; $user->name = 'daniel'; $user->username = '******'; $user->status = 'query_builder'; $this->dm->persist($user); $user = new BlogUser(); $user->id = '/functional/user/js'; $user->username = '******'; $user->name = 'johnsmith'; $user->status = 'query_builder'; $this->dm->persist($user); $user = new BlogUser(); $user->id = '/functional/user/js2'; $user->name = 'johnsmith'; $user->username = '******'; $user->status = 'another_johnsmith'; $this->dm->persist($user); $post = new Post(); $post->id = '/functional/post/post_1'; $post->title = 'Post 2'; $post->username = '******'; $this->dm->persist($post); $comment1 = new Comment(); $comment1->id = '/functional/post/post_1/comment_1'; $comment1->title = 'Comment 1'; $this->dm->persist($comment1); $comment2 = new Comment(); $comment2->id = '/functional/post/post_1/comment_2'; $comment2->title = 'Comment 1'; $this->dm->persist($comment2); $reply1 = new Comment(); $reply1->id = '/functional/post/post_1/comment_1/reply_1'; $reply1->title = 'Reply to Comment 1'; $this->dm->persist($reply1); $post = new Post(); $post->id = '/functional/post/post_2'; $post->title = 'Post 2'; $post->username = '******'; $this->dm->persist($post); $comment3 = new Comment(); $comment3->id = '/functional/post/post_2/comment_3'; $comment3->title = 'Comment 3'; $this->dm->persist($comment3); $post3 = new Post(); $post3->id = '/functional/post/post_3'; $post3->title = 'Post 3'; $post3->username = '******'; $this->dm->persist($post3); $this->dm->flush(); }
/** * @inheritDoc */ public function purge() { $session = $this->dm->getPhpcrSession(); NodeHelper::purgeWorkspace($session); $session->save(); }