public function testPostTree() { $data1 = ['title' => 'news', 'tags' => ['tag1', 'tag2'], 'url' => '/news', 'article' => 'Test']; $data2 = ['title' => 'test-1', 'tags' => ['tag1', 'tag2'], 'url' => '/news/test', 'article' => 'Test']; $client = $this->createAuthenticatedClient(); $client->request('POST', '/api/nodes?template=default&webspace=sulu_io&language=en', $data1); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $response = json_decode($client->getResponse()->getContent()); $uuid = $response->id; $client->request('POST', '/api/nodes?template=default&parent=' . $uuid . '&webspace=sulu_io&language=en', $data2); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $response = json_decode($client->getResponse()->getContent()); $this->assertEquals('test-1', $response->title); $this->assertEquals('Test', $response->article); $this->assertEquals('/news/test', $response->url); $this->assertEquals(['tag1', 'tag2'], $response->tags); $this->assertEquals($this->getTestUserId(), $response->creator); $this->assertEquals($this->getTestUserId(), $response->changer); $root = $this->session->getRootNode(); $route = $root->getNode('cmf/sulu_io/routes/en/news/test'); /** @var NodeInterface $content */ $content = $route->getPropertyValue('sulu:content'); $this->assertEquals('test-1', $content->getProperty('i18n:en-title')->getString()); $this->assertEquals('Test', $content->getProperty('i18n:en-article')->getString()); $this->assertCount(2, $content->getPropertyValue('i18n:en-tags')); $this->assertEquals($this->getTestUserId(), $content->getPropertyValue('i18n:en-creator')); $this->assertEquals($this->getTestUserId(), $content->getPropertyValue('i18n:en-changer')); // check parent $this->assertEquals($uuid, $content->getParent()->getIdentifier()); }
protected function removeTestNode() { $root = $this->session->getRootNode(); if ($root->hasNode($this->testNodeName)) { $root->getNode($this->testNodeName)->remove(); $this->session->save(); } }
private function handleSession(SessionInterface $session, $fileName) { if ($session->getRootNode()->hasNode('cmf')) { $session->getNode('/cmf')->remove(); $session->save(); } $session->importXML('/', $fileName, ImportUUIDBehaviorInterface::IMPORT_UUID_COLLISION_THROW); $session->save(); }
/** * This method populates the test case properties both at test setUp * and after renewing the session. * * The default schema is to have a root node /test_<something> with one * child node per test with the node name being the test name. */ protected function initProperties() { $this->session = $this->sharedFixture['session']; $this->node = null; $this->rootNode = $this->session->getRootNode(); $children = $this->rootNode->getNodes('tests_*'); $child = $children->current(); if ($child && $child->hasNode($this->getName())) { $this->node = $child->getNode($this->getName()); } }
public function testOverride() { $property = new Property('url', [], 'resource_locator'); $property->setValue('/test'); $node = $this->sessionManager->getContentNode('sulu_io')->addNode('test'); $node->addMixin('sulu:content'); $this->session->save(); $this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en'); $this->assertEquals('/test', $node->getPropertyValue('url')); $this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test')); $property->setValue('/test-2'); $this->resourceLocator->write($node, $property, 1, 'sulu_io', 'en'); $this->assertEquals('/test-2', $node->getPropertyValue('url')); $this->assertTrue($this->session->getRootNode()->hasNode('cmf/sulu_io/routes/en/test-2')); }
/** * Create a path. * * @param string $path * * @return NodeInterface */ public function createPath($path) { $current = $this->session->getRootNode(); $segments = preg_split('#/#', $path, null, PREG_SPLIT_NO_EMPTY); foreach ($segments as $segment) { if ($current->hasNode($segment)) { $current = $current->getNode($segment); } else { $current = $current->addNode($segment); $current->addMixin('mix:referenceable'); $current->setProperty('jcr:uuid', UUIDHelper::generateUUID()); } } return $current; }
/** * Delete all content in the workspace this session is bound to. * * Remember to save the session after calling the purge method. * * Note that if you want to delete a node under your root node, you can just * use the remove method on that node. This method is just here to help you * because the implementation might add nodes like jcr:system to the root * node which you are not allowed to remove. * * @param SessionInterface $session the session to remove all children of * the root node * * @see isSystemItem */ public static function purgeWorkspace(SessionInterface $session) { $root = $session->getRootNode(); /** @var $property PropertyInterface */ foreach ($root->getProperties() as $property) { if (!self::isSystemItem($property)) { $property->remove(); } } /** @var $node NodeInterface */ foreach ($root->getNodes() as $node) { if (!self::isSystemItem($node)) { $node->remove(); } } }
public function testPrimaryItem() { $this->registerNodeTypePrimaryItem(); // Create a node of that type $root = $this->session->getRootNode(); if ($root->hasNode('test_node')) { $node = $root->getNode('test_node'); $node->remove(); $this->session->save(); } $node = $root->addNode('test_node', 'phpcr:primary_item_test'); $node->setProperty('phpcr:content', 'test'); $this->session->save(); // Check the primary item of the new node $primary = $node->getPrimaryItem(); $this->assertInstanceOf('PHPCR\\ItemInterface', $node); $this->assertEquals('phpcr:content', $primary->getName()); }
/** * Creates every node on the path to the given node. Also uses the same UUIDs for these nodes. * * @param NodeInterface $node */ private function createNodesWithUuid(NodeInterface $node) { $path = $node->getPath(); if ($this->liveSession->itemExists($path)) { return; } $currentDefaultNode = $node->getSession()->getRootNode(); $currentLiveNode = $this->liveSession->getRootNode(); $pathSegments = explode('/', ltrim($path, '/')); foreach ($pathSegments as $pathSegment) { $currentDefaultNode = $currentDefaultNode->getNode($pathSegment); if ($currentLiveNode->hasNode($pathSegment)) { $currentLiveNode = $currentLiveNode->getNode($pathSegment); continue; } $currentLiveNode = $currentLiveNode->addNode($pathSegment); $currentLiveNode->setMixins(['mix:referenceable']); $currentLiveNode->setProperty('jcr:uuid', $currentDefaultNode->getIdentifier()); } }
private function migrateHome(SessionInterface $session, $from, $to, $referenceWebspace) { $webspaceManager = $this->container->get('sulu_core.webspace.webspace_manager'); $pathRegistry = $this->container->get('sulu_document_manager.path_segment_registry'); $webspaces = $webspaceManager->getWebspaceCollection(); foreach ($webspaces as $webspace) { $webspacePath = sprintf('/%s/%s', $pathRegistry->getPathSegment('base'), $webspace->getKey()); $homeNodeName = $pathRegistry->getPathSegment('content'); $webspace = $session->getNode($webspacePath); if ($referenceWebspace) { $webspace->addMixin('mix:referenceable'); } else { $webspace->removeMixin('mix:referenceable'); } $homeNode = $webspace->getNode($homeNodeName); $tmpNode = $session->getRootNode()->addNode('/tmp'); $tmpNode->addMixin('mix:referenceable'); $session->save(); $homeNodeReferences = $homeNode->getReferences(); $homeNodeReferenceValues = []; foreach ($homeNodeReferences as $homeNodeReference) { /* @var Property $homeNodeReference */ $homeNodeReferenceValues[$homeNodeReference->getPath()] = $homeNodeReference->getValue(); $homeNodeReference->setValue($tmpNode); } $session->save(); $homeNode->removeMixin($from); $session->save(); $homeNode->addMixin($to); $session->save(); foreach ($homeNodeReferences as $homeNodeReference) { $homeNodeReference->setValue($homeNodeReferenceValues[$homeNodeReference->getPath()], PropertyType::REFERENCE); } $session->save(); $tmpNode->remove(); } }
/** * @see \PHPCR\SessionInterface::getRootNode */ public function getRootNode() { return new Node($this->session->getRootNode()); }
public function down(SessionInterface $session) { $session->getRootNode()->getNode('hello')->remove(); }
/** * {@inheritdoc} */ public function up(SessionInterface $session) { $root = $session->getRootNode(); $this->upgradeNode($root); }