Skip to content

Commit 06a8450

Browse files
committed
Behat tests no failures
1 parent 3bc5538 commit 06a8450

26 files changed

+303
-89
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class FeatureContext extends BehatContext
2727
protected $applicationTester;
2828
protected $filesystem;
2929
protected $workingDir;
30+
protected $currentWorkspaceName = 'default';
3031

3132
/**
3233
* Initializes context.
@@ -45,8 +46,7 @@ public function beforeScenario()
4546
chdir($this->workingDir);
4647
$this->filesystem = new Filesystem();
4748

48-
$session = $this->getSession();
49-
$session->save();
49+
$session = $this->getSession(null, true);
5050

5151
$this->applicationTester = new ApplicationTester($this->application);
5252
$this->applicationTester->run(array(
@@ -69,12 +69,17 @@ public static function cleanTestFolders()
6969
$fs->remove(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'phpcr-shell');
7070
}
7171

72-
private function getSession($workspaceName = 'default')
72+
private function getSession($workspaceName = null, $force = false)
7373
{
74-
static $session = array();
74+
if ($workspaceName === null) {
75+
$workspaceName = $this->currentWorkspaceName;
76+
}
77+
78+
static $sessions = array();
7579

76-
if (isset($session[$workspaceName])) {
77-
return $session[$workspaceName];
80+
if (false === $force && isset($sessions[$workspaceName])) {
81+
$session = $sessions[$workspaceName];
82+
return $session;
7883
}
7984

8085
$params = array(
@@ -85,9 +90,9 @@ private function getSession($workspaceName = 'default')
8590
$repository = $factory->getRepository($params);
8691
$credentials = new SimpleCredentials('admin', 'admin');
8792

88-
$session[$workspaceName] = $repository->login($credentials, $workspaceName);
93+
$sessions[$workspaceName] = $repository->login($credentials, $workspaceName);
8994

90-
return $session[$workspaceName];
95+
return $sessions[$workspaceName];
9196
}
9297

9398
private function getOutput()
@@ -413,7 +418,7 @@ public function theNodeAtShouldNotHaveTheMixin($arg1, $arg2)
413418
*/
414419
public function thereShouldNotExistANodeAt($arg1)
415420
{
416-
$session = $this->getSession();
421+
$session = $this->getSession(null, true);
417422

418423
try {
419424
$session->getNode($arg1);
@@ -532,13 +537,13 @@ public function thereShouldNotExistAWorkspaceCalled($arg1)
532537
}
533538

534539
/**
535-
* @Given /^the "([^"]*)" fixtures are loaded into a workspace "([^"]*)"$/
540+
* @Given /^the "([^"]*)" fixtures are loaded into workspace "([^"]*)"$/
536541
*/
537-
public function theFixturesAreLoadedIntoAWorkspace($arg1, $arg2)
542+
public function theFixturesAreLoadedIntoWorkspace($arg1, $arg2)
538543
{
539-
$this->thereExistsAWorkspace($arg2);
544+
$this->theCurrentWorkspaceIs($arg2);
540545
$fixtureFile = $this->getFixtureFilename($arg1);
541-
$session = $this->getSession($arg2);
546+
$session = $this->getSession();
542547
NodeHelper::purgeWorkspace($session);
543548
$session->save();
544549
$session->importXml('/', $fixtureFile, 0);
@@ -556,7 +561,6 @@ public function theNodeTypeIsLoaded($arg1)
556561
$workspace = $session->getWorkspace();
557562
$nodeTypeManager = $workspace->getNodeTypeManager();
558563
$nodeTypeManager->registerNodeTypesCnd($cnd, true);
559-
$session->save();
560564
}
561565

562566
/**
@@ -614,6 +618,33 @@ public function theCurrentNodeIs($arg1)
614618
$this->executeCommand(sprintf('cd %s', $arg1));
615619
}
616620

621+
/**
622+
* @Given /^the current workspace is "([^"]*)"$/
623+
*/
624+
public function theCurrentWorkspaceIs($arg1)
625+
{
626+
$this->thereExistsAWorkspace($arg1);
627+
$this->currentWorkspaceName = $arg1;
628+
}
629+
630+
/**
631+
* @Given /^the current workspace is empty/
632+
*/
633+
public function theCurrentWorkspaceIsEmpty()
634+
{
635+
$session = $this->getSession();
636+
NodeHelper::purgeWorkspace($session);
637+
$session->save();
638+
}
639+
640+
/**
641+
* @Given /^I refresh the session/
642+
*/
643+
public function iRefreshTheSession()
644+
{
645+
$this->executeCommand('session:refresh');
646+
}
647+
617648
/**
618649
* @Given /^the primary type of "([^"]*)" should be "([^"]*)"$/
619650
*/
@@ -637,6 +668,18 @@ public function theNodeAtShouldHaveThePropertyWithValue($arg1, $arg2, $arg3)
637668
PHPUnit_Framework_Assert::assertEquals($arg3, $propertyType);
638669
}
639670

671+
/**
672+
* @Given /^I set the value of property "([^"]*)" on node "([^"]*)" to "([^"]*)"$/
673+
*/
674+
public function iSetTheValueOfPropertyOnNodeTo($arg1, $arg2, $arg3)
675+
{
676+
$session = $this->getSession();
677+
$node = $session->getNode($arg2);
678+
$property = $node->getProperty($arg1);
679+
$property->setValue($arg3);
680+
$session->save();
681+
}
682+
640683
/**
641684
* @Given /^the node at "([^"]*)" has the mixin "([^"]*)"$/
642685
*/
@@ -655,7 +698,7 @@ public function iCloneNodeFromTo($arg1, $arg2, $arg3)
655698
{
656699
$session = $this->getSession();
657700
$workspace = $session->getWorkspace();
658-
$workspace->cloneFrom($arg2, $arg1, $arg3, false);
701+
$workspace->cloneFrom($arg2, $arg1, $arg3, true);
659702
}
660703

661704
/**

features/fixtures/cms.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sv:node xmlns:crx="http://www.day.com/crx/1.0"
3+
xmlns:lx="http://flux-cms.org/2.0"
4+
xmlns:test="http://liip.to/jackalope"
5+
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
6+
xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
7+
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
8+
xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"
9+
xmlns:fn="http://www.w3.org/2005/xpath-functions"
10+
xmlns:vlt="http://www.day.com/jcr/vault/1.0"
11+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
12+
xmlns:new_prefix="http://a_new_namespace"
13+
xmlns:jcr="http://www.jcp.org/jcr/1.0"
14+
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
15+
xmlns:rep="internal"
16+
sv:name="cms">
17+
18+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
19+
<sv:value>nt:unstructured</sv:value>
20+
</sv:property>
21+
22+
<sv:node sv:name="articles">
23+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
24+
<sv:value>nt:unstructured</sv:value>
25+
</sv:property>
26+
<sv:node sv:name="article1">
27+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
28+
<sv:value>nt:unstructured</sv:value>
29+
</sv:property>
30+
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
31+
<sv:value>mix:referenceable</sv:value>
32+
</sv:property>
33+
<sv:property sv:name="jcr:uuid" sv:type="String">
34+
<sv:value>13543fc6-1abf-4708-bfcc-e49511754b40</sv:value>
35+
</sv:property>
36+
<sv:property sv:name="title" sv:type="String">
37+
<sv:value>Article 1</sv:value>
38+
</sv:property>
39+
</sv:node>
40+
</sv:node>
41+
</sv:node>
42+
43+

features/fixtures/example.cnd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
<ns ='http://namespace.com/ns'>
1+
<ns='http://namespace.com/ns'>
2+
<nt='http://www.jcp.org/jcr/nt/1.0'>
23
[ns:NodeType] > nt:unstructured
4+
orderable query

features/node_workspace_corresponding.feature renamed to features/node_corresponding.feature

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ Feature: Display the path of any corresponding node in a given workspace
55

66
Background:
77
Given that I am logged in as "testuser"
8+
And the current workspace is "default"
89
And the "session_data.xml" fixtures are loaded
9-
And the "session_data.xml" fixtures are loaded into a workspace "test"
10+
And the current workspace is "default_1"
11+
And the "session_data.xml" fixtures are loaded
12+
And the current workspace is "default"
1013

1114
Scenario: Rename a node
1215
Given the current node is "/tests_general_base/idExample"
13-
And I execute the "node:corresponding test" command
16+
And I execute the "node:corresponding default" command
1417
Then the command should not fail
1518
And I should see the following:
1619
"""

features/node_info.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Feature: Show information about node
77
Given that I am logged in as "testuser"
88
And the "session_data.xml" fixtures are loaded
99

10-
Scenario: Rename a node
10+
Scenario: Show node information
1111
Given the current node is "/tests_general_base"
1212
And I execute the "node:info --no-ansi" command
1313
Then the command should not fail

features/node_rename.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Feature: Rename a node
88
And the "session_data.xml" fixtures are loaded
99

1010
Scenario: Rename a node
11-
Given the current node is "/tests_general_base"
11+
Given the current node is "/tests_general_base/idExample"
1212
And I execute the "node:rename foobar" command
13+
And I save the session
1314
Then the command should not fail
1415
And there should exist a node at "/tests_general_base/foobar"

features/node_shared_remove.feature

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ Feature: Remove the current node from any shared set to which it belongs
55

66
Background:
77
Given that I am logged in as "testuser"
8-
And the "session_data.xml" fixtures are loaded
9-
And the node at "/tests_general_base/daniel/leech" has the mixin "mix:shareable"
10-
And I clone node "/tests_general_base/daniel/leech" from "default" to "/tests_general_base/bar"
8+
And the current workspace is "default_1"
9+
And the "cms.xml" fixtures are loaded
10+
And the current workspace is "default"
11+
And I clone node "/cms/articles/article1" from "default_1" to "/foobar"
1112

1213
Scenario: Remove the current node and all of its shared paths
13-
Given the current node is "/tests_general_base/daniel"
14+
Given the current node is "/foobar"
1415
And I execute the "node:shared:remove" command
1516
Then the command should fail
1617
And I should see the following:

features/node_shared_show.feature

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ Feature: Show the current nodes shared set
55

66
Background:
77
Given that I am logged in as "testuser"
8-
And the "session_data.xml" fixtures are loaded
9-
And the node at "/tests_general_base/daniel/leech" has the mixin "mix:shareable"
10-
And I clone node "/tests_general_base/daniel/leech" from "default" to "/tests_general_base/bar"
8+
And the current workspace is "default_1"
9+
And the "cms.xml" fixtures are loaded
10+
And the current workspace is "default"
11+
And I clone node "/cms/articles/article1" from "default_1" to "/foobar"
1112

1213
Scenario: Show the current nodes shared set
13-
Given the current node is "/tests_general_base/daniel/leech"
14+
Given the current node is "/foobar"
1415
And I execute the "node:shared:show" command
1516
Then the command should fail
1617
And I should see the following:

features/node_type_edit.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Feature: Edit a node type
77
Given that I am logged in as "testuser"
88
And the "example.cnd" node type is loaded
99

10-
Scenario Outline: Edit a property
10+
Scenario Outline: Edit a node type
1111
Given the "EDITOR" environment variable is set to "cat"
1212
And I execute the "<command>" command
1313
Then the command should not fail

features/node_update.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Feature: Update the current node from the node to which it corresponds in the given workspace
2+
In order to update the current node from the node to which it corresponds in the given workspace
3+
As a user that is logged into the shell
4+
I need to be able to do that
5+
6+
Background:
7+
Given the current workspace is "default_1"
8+
And the "cms.xml" fixtures are loaded
9+
And I set the value of property "title" on node "/cms/articles/article1" to "this is a test"
10+
And the current workspace is "default"
11+
And I clone node "/cms/articles/article1" from "default_1" to "/foobar"
12+
13+
Scenario: Update a node
14+
Given the current node is "/foobar"
15+
And I execute the "node:update default_1" command
16+
Then the command should not fail
17+
And I save the session
18+
And the node at "/foobar" should have the property "title" with value "this is a test"

0 commit comments

Comments
 (0)