Skip to content
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
24 changes: 19 additions & 5 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,30 @@ public function thereShouldExistANodeAt($arg1)
public function thereShouldExistANodeAtBefore($arg1, $arg2)
{
$session = $this->getSession();

try {
$node = $session->getNode($arg1);
$node = $session->getNode($arg2);
} catch (PathNotFoundException $e) {
throw new \Exception('Node does at path ' . $arg1 . ' does not exist.');
}
$parent = $session->getNode(PathHelper::getParentPath($arg1));
$index = $node->getIndex();

$parent = $session->getNode(PathHelper::getParentPath($arg2));
$parentChildren = array_values((array) $parent->getNodes());
$beforeNode = $parentChildren[$index];
PHPUnit_Framework_Assert::assertEquals($arg2, $beforeNode->getName());
$targetNode = null;

foreach ($parentChildren as $i => $parentChild) {
if ($parentChild->getPath() == $arg1) {
$targetNode = $parentChild;
$afterNode = $parentChildren[$i + 1];
break;
}
}

if (null === $targetNode) {
throw new \Exception('Could not find child node ' . $arg1);
}

PHPUnit_Framework_Assert::assertEquals($arg2, $afterNode->getPath());
}

/**
Expand Down
7 changes: 4 additions & 3 deletions features/node_reorder_before.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Feature: Reorder a node
And the "session_data.xml" fixtures are loaded

Scenario: Reorder a node
Given the cnp is "/tests_general_base"
And I execute the "node:order-before unversionable" command
Given the current node is "/tests_general_base"
And I execute the "node:order-before emptyExample idExample" command
Then the command should not fail
And there should exist a node at "/tests_general_base/simpleVersioned" before "/tests_general_base/unversionable"
And I save the session
And there should exist a node at "/tests_general_base/emptyExample" before "/tests_general_base/idExample"
2 changes: 2 additions & 0 deletions src/PHPCR/Shell/Console/Application/ShellApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
use PHPCR\Shell\Console\Command\NodeRenameCommand;
use PHPCR\Shell\Console\Command\NodeMixinAddCommand;
use PHPCR\Shell\Console\Command\NodeMixinRemoveCommand;
use PHPCR\Shell\Console\Command\NodeOrderBeforeCommand;
use PHPCR\Shell\Console\Command\NodeInfoCommand;
use PHPCR\Shell\Console\Command\NodeLifecycleFollowCommand;
use PHPCR\Shell\Console\Command\NodeLifecycleListCommand;
Expand Down Expand Up @@ -205,6 +206,7 @@ public function init()
$this->add(new NodeRenameCommand());
$this->add(new NodeMixinAddCommand());
$this->add(new NodeMixinRemoveCommand());
$this->add(new NodeOrderBeforeCommand());
$this->add(new NodeInfoCommand());
$this->add(new NodeLifecycleFollowCommand());
$this->add(new NodeLifecycleListCommand());
Expand Down
51 changes: 51 additions & 0 deletions src/PHPCR/Shell/Console/Command/NodeOrderBeforeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace PHPCR\Shell\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use PHPCR\Util\CND\Writer\CndWriter;
use PHPCR\NodeType\NoSuchNodeTypeException;
use PHPCR\Util\CND\Parser\CndParser;
use PHPCR\NamespaceException;

class NodeOrderBeforeCommand extends Command
{
protected function configure()
{
$this->setName('node:order-before');
$this->setDescription('');
$this->addArgument('srcChildRelPath', null, InputArgument::REQUIRED, 'The relative path to the child node to be moved in the ordering');
$this->addArgument('destChildRelPath', null, InputArgument::REQUIRED, 'The relative path to the child before which the node srcChildRelPath will be placed');
$this->setHelp(<<<HERE
If this node supports child node ordering, this method inserts the child
node at <info>srcChildRelPath</info> into the child node list at the position
immediately before <info>destChildRelPath</info>

To place the node <info>srcChildRelPath</info> at the end of the list, a
destChildRelPath of null is used.

Note that (apart from the case where <info>destChildRelPath</info> is null) both of
these arguments must be relative paths of depth one, in other words they
are the names of the child nodes, possibly suffixed with an index.

If <info>srcChildRelPath</info> and <info>destChildRelPath</info> are the same, then no change is
made.

This is session-write method, meaning that a change made by this method
is dispatched on save.
HERE
);
}

public function execute(InputInterface $input, OutputInterface $output)
{
$session = $this->getHelper('phpcr')->getSession();
$srcChildRelPath = $input->getArgument('srcChildRelPath');
$destChildRelPath = $input->getArgument('destChildRelPath');
$node = $session->getCurrentNode();
$node->orderBefore($srcChildRelPath, $destChildRelPath);
}
}