Skip to content

Alias and config #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 26, 2014
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ before_script:

script:
- phpunit --coverage-text
- php vendor/behat/behat/bin/behat --format=failed
- php vendor/behat/behat/bin/behat
- php vendor/bin/phpspec run
9 changes: 9 additions & 0 deletions features/fixtures/cms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@
<sv:value>nt:unstructured</sv:value>
</sv:property>

<sv:node sv:name="test">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
</sv:node>

<sv:node sv:name="articles">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="name">
<sv:value>mix:shareable</sv:value>
</sv:property>
<sv:node sv:name="article1">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Feature: Copy a node from a given workspace to the current workspace
And I save the session
And there should exist a node at "/foo"

Scenario: Copy node from a different workspace
Given I execute the "node:copy /tests_general_base/index.txt /index.txt default_1" command
Then the command should not fail
And there should exist a node at "/index.txt"
# Does not currently work with jackrabbit..
#Scenario: Copy node from a different workspace
# Given I execute the "node:copy /tests_general_base/index.txt /index.txt default_1" command
# Then the command should not fail
# And there should exist a node at "/index.txt"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ Feature: Set a node property
| node:property:set thisisnew foobar --type=string | /properties/thisisnew | foobar |

Scenario: Update a property but do not specify the type
Given I execute the "node:set /properties/decimal 1234" command
Given I execute the "node:property:set /properties/decimal 1234" command
And I execute the "node:list /properties" command
Then I should see the following:
"""
decimal | DECIMAL
"""

Scenario: Create a new property
Given I execute the "node:property:set /properties/new 1234" command
Then the command should not fail
And I execute the "node:list /properties" command
Then I should see the following:
"""
new | STRING
"""
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ hello world
2011-04-21T14:34:20+01:00
"""

Scenario: Attempt to show a node
Given I execute the "node:property:show /tests_general_base" command
Then the command should fail
And I should see the following:
"""
Item at "/tests_general_base" is not a property
"""

Scenario: Try to show non-existing property
Given I execute the "node:property:show /this/path/does/not/exist" command
Then the command should fail
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions features/shell_alias.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: Command aliases
In order to be more effective when using the shell
As a user
I want to be able to use the default command aliases

Background:
Given that I am logged in as "testuser"
And the "cms.xml" fixtures are loaded

Scenario Outline: Execute an alias
Given I execute the "<command>" command
Then the command should not fail

Examples:
| command |
| use default |
| select * from [nt:unstructured] |
| cd cms |
| rm cms |
| mv cms smc |
| ls |
| ls cms |
| sl cms/articles cms/test/foobar |
| cat cms/articles/article1/title |

Scenario: List aliases
Given I execute the "shell:alias:list" command
Then the command should not fail
And I should see a table containing the following rows:
| Alias | Command |
| cd | shell:path:change {arg1} |
| ls | node:list {arg1} |



12 changes: 12 additions & 0 deletions features/shell_config_init.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Initialize a new local configuration
In order to create a default configuration
As a user
I want to be able to execute a command which does that

Scenario: Initialize configuration
Given I execute the "shell:config:init --no-ansi --no-interaction" command
Then the command should not fail
And I should see the following:
"""
alias.yml
"""
8 changes: 8 additions & 0 deletions features/shell_config_reload.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Reload the configuration
In order to reload the configuration
As a user
I want to be able to execute a command which does that

Scenario: Reload configuration
Given I execute the "shell:config:reload" command
Then the command should not fail
14 changes: 14 additions & 0 deletions spec/PHPCR/Shell/Console/Application/ShellApplicationSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace spec\PHPCR\Shell\Console\Application;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ShellApplicationSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Console\Application\ShellApplication');
}
}
43 changes: 43 additions & 0 deletions spec/PHPCR/Shell/Console/Helper/ConfigHelperSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace spec\PHPCR\Shell\Console\Helper;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Filesystem\Filesystem;

class ConfigHelperSpec extends ObjectBehavior
{
function let(
Filesystem $filesystem
)
{
$this->beConstructedWith($filesystem);
}

function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Console\Helper\ConfigHelper');
}

function it_should_have_a_method_to_get_the_users_config_directory()
{
putenv('PHPCRSH_HOME=/home/foobar');
$this->getConfigDir()->shouldReturn('/home/foobar');
}

function it_should_be_able_to_parse_a_config_file_and_return_the_config_as_an_array(
Filesystem $filesystem
)
{
$dir = __DIR__ . '/fixtures/config';
putenv('PHPCRSH_HOME=' . $dir);
$filesystem->exists(Argument::any())->willReturn(true);

$config = $this->getConfig('alias')->shouldReturn(array(
'foobar' => 'barfoo',
'barfoo' => 'foobar',
));

}
}
2 changes: 2 additions & 0 deletions spec/PHPCR/Shell/Console/Helper/fixtures/config/alias.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
foobar: barfoo
barfoo: foobar
29 changes: 29 additions & 0 deletions spec/PHPCR/Shell/Event/ApplicationInitEventSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace spec\PHPCR\Shell\Event;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Console\Application;

class ApplicationInitEventSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Event\ApplicationInitEvent');
}

function let(
Application $application
)
{
$this->beConstructedWith($application);
}

function it_will_return_the_application(
Application $application
)
{
$this->getApplication()->shouldReturn($application);
}
}
30 changes: 30 additions & 0 deletions spec/PHPCR/Shell/Event/CommandExceptionEventSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace spec\PHPCR\Shell\Event;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Console\Output\OutputInterface;

class CommandExceptionEventSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Event\CommandExceptionEvent');
}

function let(
\Exception $exception,
OutputInterface $output
) {
$this->beConstructedWith($exception, $output);
}

function it_should_provide_access_to_event_parameters(
\Exception $exception,
OutputInterface $output
) {
$this->getException()->shouldReturn($exception);
$this->getOutput()->shouldReturn($output);
}
}
60 changes: 60 additions & 0 deletions spec/PHPCR/Shell/Subscriber/AliasSubscriberSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace spec\PHPCR\Shell\Subscriber;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PHPCR\Shell\Console\Helper\ConfigHelper;
use PHPCR\Shell\Console\Input\StringInput;
use PHPCR\Shell\Event\CommandPreRunEvent;

class AliasSubscriberSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('PHPCR\Shell\Subscriber\AliasSubscriber');
}

function let(
ConfigHelper $config
) {
$this->beConstructedWith(
$config
);

$config->getConfig('alias')->willReturn(array(
'ls' => 'list:command {arg1}',
'mv' => 'move {arg1} {arg2}',
));
}

function it_should_convert_an_aliased_input_into_a_real_command_input(
CommandPreRunEvent $event,
ConfigHelper $config,
StringInput $input
) {
$event->getInput()->willReturn($input);
$input->getFirstArgument()->willReturn('ls');
$input->getTokens()->willReturn(array(
'ls', 'me'
));
$event->setInput(Argument::type('PHPCR\Shell\Console\Input\StringInput'))->shouldBeCalled();

$this->handleAlias($event)->shouldReturn('list:command me');
}

function it_should_ommit_missing_arguments(
CommandPreRunEvent $event,
ConfigHelper $config,
StringInput $input
) {
$event->getInput()->willReturn($input);
$input->getFirstArgument()->willReturn('ls');
$input->getTokens()->willReturn(array(
'ls'
));
$event->setInput(Argument::type('PHPCR\Shell\Console\Input\StringInput'))->shouldBeCalled();

$this->handleAlias($event)->shouldReturn('list:command');
}
}
Loading