Skip to content

Commit 6c73df3

Browse files
committed
Node mixin add and remove
1 parent 593c1d5 commit 6c73df3

File tree

6 files changed

+152
-4
lines changed

6 files changed

+152
-4
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,40 @@ public function thereShouldExistANodeAtBefore($arg1, $arg2)
363363
PHPUnit_Framework_Assert::assertEquals($arg2, $beforeNode->getName());
364364
}
365365

366+
/**
367+
* @Given /^the node at "([^"]*)" should have the mixin "([^"]*)"$/
368+
*/
369+
public function theNodeAtShouldHaveTheMixin($arg1, $arg2)
370+
{
371+
$session = $this->getSession();
372+
$node = $session->getNode($arg1);
373+
$mixinNodeTypes = $node->getMixinNodeTypes();
374+
375+
foreach ($mixinNodeTypes as $mixinNodeType) {
376+
if ($mixinNodeType->getName() == $arg2) {
377+
return;
378+
}
379+
}
380+
381+
throw new \Exception('Node "' . $arg1 . '" does not have node type "' . $arg2 . '"');
382+
}
383+
384+
/**
385+
* @Given /^the node at "([^"]*)" should not have the mixin "([^"]*)"$/
386+
*/
387+
public function theNodeAtShouldNotHaveTheMixin($arg1, $arg2)
388+
{
389+
$session = $this->getSession();
390+
$node = $session->getNode($arg1);
391+
$mixinNodeTypes = $node->getMixinNodeTypes();
392+
393+
foreach ($mixinNodeTypes as $mixinNodeType) {
394+
if ($mixinNodeType->getName() == $arg2) {
395+
throw new \Exception('Node "' . $arg1 . '" has the node type "' . $arg2 . '"');
396+
}
397+
}
398+
}
399+
366400
/**
367401
* @Given /^there should not exist a node at "([^"]*)"$/
368402
*/
@@ -586,4 +620,15 @@ public function theNodeAtShouldHaveThePropertyWithType($arg1, $arg2, $arg3)
586620
$propertyType = $property->getType();
587621
PHPUnit_Framework_Assert::assertEquals($arg3, $propertyType);
588622
}
623+
624+
/**
625+
* @Given /^the node at "([^"]*)" has the mixin "([^"]*)"$/
626+
*/
627+
public function theNodeAtHasTheMixin($arg1, $arg2)
628+
{
629+
$session = $this->getSession();
630+
$node = $session->getNode($arg1);
631+
$node->addMixin($arg2);
632+
$session->save();
633+
}
589634
}

features/node_mixin_add.feature

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Feature: Add mixin to the current node
99

1010
Scenario: Add a mixin to the current node
1111
Given the current node is "/tests_general_base"
12-
And I execute the "node:mixin-add mixin:versionable --no-ansi" command
12+
And I execute the "node:mixin:add mix:versionable --no-ansi" command
13+
And I save the session
1314
Then the command should not fail
14-
And the current node should have the mixin "mixin:versionable"
15+
And the node at "/tests_general_base" should have the mixin "mix:versionable"

features/node_mixin_remove.feature

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ Feature: Remove mixin to the current node
66
Background:
77
Given that I am logged in as "testuser"
88
And the "session_data.xml" fixtures are loaded
9+
And the node at "/tests_general_base" has the mixin "mix:versionable"
910

1011
Scenario: Remove a mixin to the current node
1112
Given the current node is "/tests_general_base"
12-
And I execute the "node:mixin-remove mixin:versionable --no-ansi" command
13+
And I execute the "node:mixin:remove mix:versionable --no-ansi" command
14+
And I save the session
1315
Then the command should not fail
14-
And the current node should not have the mixin "mixin:versionable"
16+
And the node at "/tests_general_base" should not have the mixin "mix:versionable"

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
use PHPCR\Shell\Console\Command\NodeDefinitionCommand;
7272
use PHPCR\Shell\Console\Command\NodeSetCommand;
7373
use PHPCR\Shell\Console\Command\NodeRenameCommand;
74+
use PHPCR\Shell\Console\Command\NodeMixinAddCommand;
75+
use PHPCR\Shell\Console\Command\NodeMixinRemoveCommand;
7476
use Jackalope\NotImplementedException;
7577

7678
class ShellApplication extends Application
@@ -153,6 +155,8 @@ public function init()
153155
$this->add(new NodeDefinitionCommand());
154156
$this->add(new NodeSetCommand());
155157
$this->add(new NodeRenameCommand());
158+
$this->add(new NodeMixinAddCommand());
159+
$this->add(new NodeMixinRemoveCommand());
156160

157161
// add shell-specific commands
158162
$this->add(new ChangePathCommand());
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use PHPCR\Util\CND\Writer\CndWriter;
10+
use PHPCR\NodeType\NoSuchNodeTypeException;
11+
use PHPCR\Util\CND\Parser\CndParser;
12+
use PHPCR\NamespaceException;
13+
use Symfony\Component\Console\Input\InputOption;
14+
15+
class NodeMixinAddCommand extends Command
16+
{
17+
protected function configure()
18+
{
19+
$this->setName('node:mixin:add');
20+
$this->setDescription('Add the named mixin to the current node');
21+
$this->addArgument('mixinName', null, InputArgument::REQUIRED, null, 'The name of the mixin node type to be added');
22+
$this->setHelp(<<<HERE
23+
Adds the mixin node type named <info>mixinName</info> to this node.
24+
25+
If this node is already of type <info>mixinName</info> (either due to a previously
26+
added mixin or due to its primary type, through inheritance) then this
27+
method has no effect. Otherwise <info>mixinName</info> is added to this node's
28+
jcr:mixinTypes property.
29+
30+
Semantically, the new node type may take effect immediately, on dispatch
31+
or on persist. The behavior is adopted must be the same as the behavior
32+
adopted for NodeInterface::setPrimaryType() and the behavior that
33+
occurs when a node is first created.
34+
35+
A ConstraintViolationException is thrown either immediately or on save
36+
if a conflict with another assigned mixin or the primary node type
37+
occurs or for an implementation-specific reason. Implementations may
38+
differ on when this validation is done.
39+
40+
In some implementations it may only be possible to add mixin types
41+
before a a node is persisted for the first time. In such cases any
42+
later calls to <info>addMixin</info> will throw a ConstraintViolationException
43+
either immediately, on dispatch or on persist.
44+
HERE
45+
);
46+
}
47+
48+
public function execute(InputInterface $input, OutputInterface $output)
49+
{
50+
$session = $this->getHelper('phpcr')->getSession();
51+
$mixinName = $input->getArgument('mixinName');
52+
$currentNode = $session->getCurrentNode();
53+
$currentNode->addMixin($mixinName);
54+
}
55+
}
56+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use PHPCR\Util\CND\Writer\CndWriter;
10+
use PHPCR\NodeType\NoSuchNodeTypeException;
11+
use PHPCR\Util\CND\Parser\CndParser;
12+
use PHPCR\NamespaceException;
13+
use Symfony\Component\Console\Input\InputOption;
14+
15+
class NodeMixinRemoveCommand extends Command
16+
{
17+
protected function configure()
18+
{
19+
$this->setName('node:mixin:remove');
20+
$this->setDescription('Remove the named mixin to the current node');
21+
$this->addArgument('mixinName', null, InputArgument::REQUIRED, null, 'The name of the mixin node type to be removeed');
22+
$this->setHelp(<<<HERE
23+
Removes the specified mixin node type from this node and removes
24+
mixinName from this node's jcr:mixinTypes property.
25+
26+
Both the semantic change in effective node type and the persistence of
27+
the change to the jcr:mixinTypes property occur on persist.
28+
HERE
29+
);
30+
}
31+
32+
public function execute(InputInterface $input, OutputInterface $output)
33+
{
34+
$session = $this->getHelper('phpcr')->getSession();
35+
$mixinName = $input->getArgument('mixinName');
36+
$currentNode = $session->getCurrentNode();
37+
$currentNode->removeMixin($mixinName);
38+
}
39+
}
40+

0 commit comments

Comments
 (0)