Skip to content

Commit 3765772

Browse files
committed
Merge pull request #16 from phpcr/fixing_tests
Fixing tests
2 parents 96f9b6d + e457c44 commit 3765772

39 files changed

+544
-147
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 71 additions & 16 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,13 +46,13 @@ 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(
5353
'--transport' => 'jackrabbit',
5454
'--no-interaction' => true,
55+
'--unsupported' => true, // test all the commands, even if they are unsupported (we test for the fail)
5556
), array(
5657
'interactive' => true,
5758
));
@@ -69,8 +70,19 @@ public static function cleanTestFolders()
6970
$fs->remove(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'phpcr-shell');
7071
}
7172

72-
private function getSession($workspaceName = 'default')
73+
private function getSession($workspaceName = null, $force = false)
7374
{
75+
if ($workspaceName === null) {
76+
$workspaceName = $this->currentWorkspaceName;
77+
}
78+
79+
static $sessions = array();
80+
81+
if (false === $force && isset($sessions[$workspaceName])) {
82+
$session = $sessions[$workspaceName];
83+
return $session;
84+
}
85+
7486
$params = array(
7587
'jackalope.jackrabbit_uri' => 'http://localhost:8080/server/',
7688
);
@@ -79,9 +91,9 @@ private function getSession($workspaceName = 'default')
7991
$repository = $factory->getRepository($params);
8092
$credentials = new SimpleCredentials('admin', 'admin');
8193

82-
$session = $repository->login($credentials, $workspaceName);
94+
$sessions[$workspaceName] = $repository->login($credentials, $workspaceName);
8395

84-
return $session;
96+
return $sessions[$workspaceName];
8597
}
8698

8799
private function getOutput()
@@ -184,7 +196,7 @@ public function iShouldSeeTheFollowing(PyStringNode $string)
184196
public function theFixturesAreLoaded($arg1)
185197
{
186198
$fixtureFile = $this->getFixtureFilename($arg1);
187-
$session = $this->getSession();
199+
$session = $this->getSession(null, true);
188200
NodeHelper::purgeWorkspace($session);
189201
$session->save();
190202
$session->importXml('/', $fixtureFile, 0);
@@ -407,7 +419,7 @@ public function theNodeAtShouldNotHaveTheMixin($arg1, $arg2)
407419
*/
408420
public function thereShouldNotExistANodeAt($arg1)
409421
{
410-
$session = $this->getSession();
422+
$session = $this->getSession(null, true);
411423

412424
try {
413425
$session->getNode($arg1);
@@ -506,7 +518,11 @@ public function thereExistsAWorkspace($arg1)
506518
{
507519
$session = $this->getSession();
508520
$workspace = $session->getWorkspace();
509-
$workspace->createWorkspace($arg1);
521+
try {
522+
$workspace->createWorkspace($arg1);
523+
} catch (\Exception $e) {
524+
// already exists..
525+
}
510526
}
511527

512528
/**
@@ -522,12 +538,13 @@ public function thereShouldNotExistAWorkspaceCalled($arg1)
522538
}
523539

524540
/**
525-
* @Given /^the "([^"]*)" fixtures are loaded into a workspace "([^"]*)"$/
541+
* @Given /^the "([^"]*)" fixtures are loaded into workspace "([^"]*)"$/
526542
*/
527-
public function theFixturesAreLoadedIntoAWorkspace($arg1, $arg2)
543+
public function theFixturesAreLoadedIntoWorkspace($arg1, $arg2)
528544
{
545+
$this->theCurrentWorkspaceIs($arg2);
529546
$fixtureFile = $this->getFixtureFilename($arg1);
530-
$session = $this->getSession($arg2);
547+
$session = $this->getSession();
531548
NodeHelper::purgeWorkspace($session);
532549
$session->save();
533550
$session->importXml('/', $fixtureFile, 0);
@@ -545,7 +562,6 @@ public function theNodeTypeIsLoaded($arg1)
545562
$workspace = $session->getWorkspace();
546563
$nodeTypeManager = $workspace->getNodeTypeManager();
547564
$nodeTypeManager->registerNodeTypesCnd($cnd, true);
548-
$session->save();
549565
}
550566

551567
/**
@@ -603,6 +619,33 @@ public function theCurrentNodeIs($arg1)
603619
$this->executeCommand(sprintf('cd %s', $arg1));
604620
}
605621

622+
/**
623+
* @Given /^the current workspace is "([^"]*)"$/
624+
*/
625+
public function theCurrentWorkspaceIs($arg1)
626+
{
627+
$this->thereExistsAWorkspace($arg1);
628+
$this->currentWorkspaceName = $arg1;
629+
}
630+
631+
/**
632+
* @Given /^the current workspace is empty/
633+
*/
634+
public function theCurrentWorkspaceIsEmpty()
635+
{
636+
$session = $this->getSession();
637+
NodeHelper::purgeWorkspace($session);
638+
$session->save();
639+
}
640+
641+
/**
642+
* @Given /^I refresh the session/
643+
*/
644+
public function iRefreshTheSession()
645+
{
646+
$this->executeCommand('session:refresh');
647+
}
648+
606649
/**
607650
* @Given /^the primary type of "([^"]*)" should be "([^"]*)"$/
608651
*/
@@ -615,17 +658,29 @@ public function thePrimaryTypeOfShouldBe($arg1, $arg2)
615658
}
616659

617660
/**
618-
* @Given /^the node at "([^"]*)" should have the property "([^"]*)" with type "([^"]*)"$/
661+
* @Given /^the node at "([^"]*)" should have the property "([^"]*)" with value "([^"]*)"$/
619662
*/
620-
public function theNodeAtShouldHaveThePropertyWithType($arg1, $arg2, $arg3)
663+
public function theNodeAtShouldHaveThePropertyWithValue($arg1, $arg2, $arg3)
621664
{
622665
$session = $this->getSession();
623666
$node = $session->getNode($arg1);
624667
$property = $node->getProperty($arg2);
625-
$propertyType = $property->getType();
668+
$propertyType = $property->getValue();
626669
PHPUnit_Framework_Assert::assertEquals($arg3, $propertyType);
627670
}
628671

672+
/**
673+
* @Given /^I set the value of property "([^"]*)" on node "([^"]*)" to "([^"]*)"$/
674+
*/
675+
public function iSetTheValueOfPropertyOnNodeTo($arg1, $arg2, $arg3)
676+
{
677+
$session = $this->getSession();
678+
$node = $session->getNode($arg2);
679+
$property = $node->getProperty($arg1);
680+
$property->setValue($arg3);
681+
$session->save();
682+
}
683+
629684
/**
630685
* @Given /^the node at "([^"]*)" has the mixin "([^"]*)"$/
631686
*/
@@ -644,7 +699,7 @@ public function iCloneNodeFromTo($arg1, $arg2, $arg3)
644699
{
645700
$session = $this->getSession();
646701
$workspace = $session->getWorkspace();
647-
$workspace->cloneFrom($arg2, $arg1, $arg3, false);
702+
$workspace->cloneFrom($arg2, $arg1, $arg3, true);
648703
}
649704

650705
/**

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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ 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
10+
And the current workspace is "default_1"
11+
And the "session_data.xml" fixtures are loaded
12+
And the current workspace is "default"
913

1014
Scenario: Rename a node
11-
Given the current node is "/tests_general_base"
15+
Given the current node is "/tests_general_base/idExample"
1216
And I execute the "node:corresponding default" command
1317
Then the command should not fail
1418
And I should see the following:
1519
"""
16-
/foobar
20+
/tests_general_base/idExample
1721
"""

features/node_create.feature

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ Feature: Create a node
2323
And the primary type of "/testfile" should be "nt:folder"
2424

2525
Scenario: Create a new node at a non-root current node no matching child type
26-
Given the current node is "/tests_general_base"
26+
Given the current node is "/tests_general_base/emptyExample"
2727
And I execute the "node:create testcreate" command
2828
Then the command should fail
2929
And I should see the following:
3030
"""
31-
No matching child node definition found for `testcreate' in type `nt:folder' for node '/tests_general_base'. Please specify the type explicitly
31+
No matching child node definition found for `testcreate'
3232
"""
3333

3434
Scenario: Create a new node at a non-root current node
@@ -37,11 +37,3 @@ Feature: Create a node
3737
And I save the session
3838
Then the command should not fail
3939
And there should exist a node at "/tests_general_base/testcreate"
40-
41-
Scenario: Attempt to create an empty node
42-
Given I execute the "node:create" command
43-
Then the command should fail
44-
And I should see the following:
45-
"""
46-
Name can not be empty
47-
"""

features/node_info.feature

Lines changed: 2 additions & 2 deletions
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
@@ -17,7 +17,7 @@ Feature: Show information about node
1717
| Path | /tests_general_base |
1818
| UUID | N/A |
1919
| Index | 1 |
20-
| Primary node type | nt:folder |
20+
| Primary node type | nt:unstructured |
2121
| Mixin node types | |
2222
| Checked out? | [ERROR] Not implemented by jackalope |
2323
| Locked? | [ERROR] Not implemented by jackalope |

features/node_list.feature

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ Feature: List properites and chidren of current node
1919
| numberPropertyNode/ | nt:file | |
2020
| NumberPropertyNodeToCompare1/ | nt:file | |
2121
| NumberPropertyNodeToCompare2/ | nt:file | |
22-
| jcr:createdBy | STRING | admin |
23-
| jcr:primaryType | NAME | nt:folder |
22+
| jcr:primaryType | NAME | nt:unstructured |
2423

2524
Scenario: List the properties
2625
Given the current node is "/tests_general_base"
2726
And I execute the "node:list --properties --no-ansi" command
2827
Then the command should not fail
2928
And I should see a table containing the following rows:
30-
| jcr:createdBy | STRING | admin |
31-
| jcr:primaryType | NAME | nt:folder |
29+
| jcr:primaryType | NAME | nt:unstructured |
3230

3331
Scenario: List the children nodes
3432
Given the current node is "/tests_general_base"

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_set.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Feature: Set a node property
1111
Scenario Outline: Set a property
1212
Given I execute the "<command>" command
1313
Then the command should not fail
14-
And the node at "/properties" should have the property "<name>" with type "<type>"
14+
And I save the session
15+
And the node at "/properties" should have the property "<name>" with value "<type>"
1516

1617
Examples:
1718
| command | name | type |

features/node_set_primary_type.feature

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ Feature: Set the nodes primary type
99

1010
Scenario: List the properties and children of the current node
1111
Given the current node is "/tests_general_base"
12-
And I execute the "node:type:set-primary nt:unstructured --no-ansi" command
13-
Then the command should not fail
12+
And I execute the "node:set-primary-type nt:unstructured --no-ansi" command
13+
Then the command should fail
14+
And I should see the following:
15+
"""
16+
Not implemented
17+
"""

0 commit comments

Comments
 (0)