Skip to content

Commit 9f78f32

Browse files
committed
Merge branch 'kirtangajjar-add_more_tests' into develop
2 parents 4b00a9b + 0745ec3 commit 9f78f32

File tree

2 files changed

+148
-32
lines changed

2 files changed

+148
-32
lines changed

features/bootstrap/FeatureContext.php

Lines changed: 104 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,27 @@
77

88
use Behat\Behat\Context\Context;
99
use Behat\Behat\Hook\Scope\AfterFeatureScope;
10-
10+
use Behat\Behat\Hook\Scope\AfterScenarioScope;
1111

1212
use Behat\Gherkin\Node\PyStringNode,
1313
Behat\Gherkin\Node\TableNode;
1414

15+
define( 'EE_SITE_ROOT', getenv('HOME') . '/ee-sites/' );
16+
1517
class FeatureContext implements Context
1618
{
1719
public $command;
1820
public $webroot_path;
21+
public $ee_path;
22+
23+
/**
24+
* Initializes context.
25+
*/
26+
public function __construct()
27+
{
28+
$this->commands = [];
29+
$this->ee_path = getcwd();
30+
}
1931

2032
/**
2133
* @Given ee phar is generated
@@ -55,14 +67,35 @@ public function isInstalled($command)
5567
*/
5668
public function iRun($command)
5769
{
58-
$this->command = EE::launch($command, false, true);
70+
$this->commands[] = EE::launch($command, false, true);
5971
}
72+
73+
/**
74+
* @When I create subsite :subsite in :site
75+
*/
76+
public function iCreateSubsiteInOfType($subsite, $site )
77+
{
78+
$php_container = implode( explode( '.', $subsite ) ) . '_php_1';
79+
80+
EE::launch( "docker exec -it --user='www-data' $php_container sh -c 'wp site create --slug=$site'", false, true );
81+
}
82+
6083
/**
6184
* @Then return value should be 0
6285
*/
63-
public function returnCodeShouldBe0()
86+
public function returnValueShouldBe0()
6487
{
65-
if ( 0 !== $this->command->return_code ) {
88+
if ( 0 !== $this->commands[0]->return_code ) {
89+
throw new Exception("Actual return code is not zero: \n" . $this->command);
90+
}
91+
}
92+
93+
/**
94+
* @Then return value of command :index should be 0
95+
*/
96+
public function returnValueOfCommandShouldBe0($index)
97+
{
98+
if ( 0 !== $this->commands[ $index - 1 ]->return_code ) {
6699
throw new Exception("Actual return code is not zero: \n" . $this->command);
67100
}
68101
}
@@ -80,7 +113,21 @@ public function afterDelayOfSeconds( $time )
80113
*/
81114
public function stdoutShouldReturnExactly($output_stream, PyStringNode $expected_output)
82115
{
83-
$command_output = $output_stream === "STDOUT" ? $this->command->stdout : $this->command->stderr;
116+
$command_output = $output_stream === "STDOUT" ? $this->commands[0]->stdout : $this->commands[0]->stderr;
117+
118+
$command_output = str_replace(["\033[1;31m","\033[0m"],'',$command_output);
119+
120+
if ( $expected_output->getRaw() !== trim($command_output)) {
121+
throw new Exception("Actual output is:\n" . $command_output);
122+
}
123+
}
124+
125+
/**
126+
* @Then /(STDOUT|STDERR) of command :index should return exactly/
127+
*/
128+
public function stdoutOfCommandShouldReturnExactly($output_stream, $index, PyStringNode $expected_output)
129+
{
130+
$command_output = $output_stream === "STDOUT" ? $this->commands[ $index - 1 ]->stdout : $this->commands[ $index - 1 ]->stderr;
84131

85132
$command_output = str_replace(["\033[1;31m","\033[0m"],'',$command_output);
86133

@@ -95,14 +142,50 @@ public function stdoutShouldReturnExactly($output_stream, PyStringNode $expected
95142
*/
96143
public function stdoutShouldReturnSomethingLike($output_stream, PyStringNode $expected_output)
97144
{
98-
$command_output = $output_stream === "STDOUT" ? $this->command->stdout : $this->command->stderr;
145+
$command_output = $output_stream === "STDOUT" ? $this->commands[0]->stdout : $this->commands[0]->stderr;
99146

100147
$expected_out = isset($expected_output->getStrings()[0]) ? $expected_output->getStrings()[0] : '';
101148
if (strpos($command_output, $expected_out) === false) {
102149
throw new Exception("Actual output is:\n" . $command_output);
103150
}
104151
}
105152

153+
154+
/**
155+
* @Then /(STDOUT|STDERR) of command :index should return something like/
156+
*/
157+
public function stdoutOfCommandShouldReturnSomethingLike($output_stream, $index, PyStringNode $expected_output)
158+
{
159+
$command_output = $output_stream === "STDOUT" ? $this->commands[ $index - 1 ]->stdout : $this->commands[ $index - 1 ]->stderr;
160+
161+
$expected_out = isset($expected_output->getStrings()[0]) ? $expected_output->getStrings()[0] : '';
162+
if (strpos($command_output, $expected_out) === false) {
163+
throw new Exception("Actual output is:\n" . $command_output);
164+
}
165+
}
166+
167+
/**
168+
* @Then The site :site should be :type multisite
169+
*/
170+
public function theSiteShouldBeMultisite( $site, $type )
171+
{
172+
$result = EE::launch("cd " . EE_SITE_ROOT . "$site && docker-compose exec --user='www-data' php sh -c 'wp config get SUBDOMAIN_INSTALL'", false, true );
173+
174+
if( $result->stderr ) {
175+
throw new Exception("Found error while executing command: $result->stderr");
176+
}
177+
178+
if($type === 'subdomain' && trim($result->stdout) !== '1') {
179+
throw new Exception("Expecting SUBDOMAIN_INSTALL to be 1. Got: $result->stdout");
180+
}
181+
else if($type === 'subdir' && trim($result->stdout) !== '') {
182+
throw new Exception("Expecting SUBDOMAIN_INSTALL to be empty. Got: $result->stdout");
183+
}
184+
else if($type !== 'subdomain' && $type !== 'subdir') {
185+
throw new Exception("Found unknown site type: $type");
186+
}
187+
}
188+
106189
/**
107190
* @Then The :site db entry should be removed
108191
*/
@@ -120,7 +203,7 @@ public function theDbEntryShouldBeRemoved($site)
120203
*/
121204
public function theWebrootShouldBeRemoved($site)
122205
{
123-
if (file_exists(getenv('HOME') . "/ee-sites/" . $site)) {
206+
if (file_exists(EE_SITE_ROOT . $site)) {
124207
throw new Exception("Webroot has not been removed!");
125208
}
126209
}
@@ -150,7 +233,7 @@ public function followingContainersOfSiteShouldBeRemoved($site, TableNode $table
150233
*/
151234
public function theSiteShouldHaveWebroot($site)
152235
{
153-
if (!file_exists(getenv('HOME') . "/ee-sites/" . $site)) {
236+
if (!file_exists(EE_SITE_ROOT . $site)) {
154237
throw new Exception("Webroot has not been created!");
155238
}
156239
}
@@ -160,7 +243,7 @@ public function theSiteShouldHaveWebroot($site)
160243
*/
161244
public function theSiteShouldHaveWordpress($site)
162245
{
163-
if (!file_exists(getenv('HOME') . "/ee-sites/" . $site . "/app/src/wp-config.php")) {
246+
if (!file_exists(EE_SITE_ROOT . $site . "/app/src/wp-config.php")) {
164247
throw new Exception("WordPress data not found!");
165248
}
166249
}
@@ -244,13 +327,24 @@ public function requestOnWithResolveOptionShouldContainFollowingHeaders($host, $
244327
}
245328
}
246329

330+
/**
331+
* @AfterScenario
332+
*/
333+
public function cleanupScenario(AfterScenarioScope $scope)
334+
{
335+
$this->commands = [];
336+
chdir($this->ee_path);
337+
}
338+
247339
/**
248340
* @AfterFeature
249341
*/
250342
public static function cleanup(AfterFeatureScope $scope)
251343
{
252344
$test_sites = [
253-
'hello.test',
345+
'wp.test',
346+
'wpsubdom.test',
347+
'wpsubdir.test',
254348
'example.test',
255349
'www.example1.test',
256350
'example2.test',

features/site.feature

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,58 @@ Feature: Site Command
2525
usage: ee site
2626
"""
2727

28-
Scenario: Create site successfully
29-
When I run 'sudo bin/ee site create hello.test --wp'
30-
Then The site 'hello.test' should have webroot
31-
And The site 'hello.test' should have WordPress
32-
And Request on 'hello.test' should contain following headers:
33-
| header |
34-
| HTTP/1.1 200 OK |
28+
Scenario: Create wp site successfully
29+
When I run 'sudo bin/ee site create wp.test --wp'
30+
Then The site 'wp.test' should have webroot
31+
And The site 'wp.test' should have WordPress
32+
And Request on 'wp.test' should contain following headers:
33+
| header |
34+
| HTTP/1.1 200 OK |
35+
36+
Scenario: Create wpsubdir site successfully
37+
When I run 'sudo bin/ee site create wpsubdir.test --wpsubdir'
38+
And I create subsite '1' in 'wpsubdir.test'
39+
Then The site 'wpsubdir.test' should have webroot
40+
And The site 'wpsubdir.test' should have WordPress
41+
And The site 'wpsubdir.test' should be 'subdir' multisite
42+
And Request on 'wpsubdir.test' should contain following headers:
43+
| header |
44+
| HTTP/1.1 200 OK |
45+
46+
Scenario: Create wpsubdom site successfully
47+
When I run 'sudo bin/ee site create wpsubdom.test --wpsubdom'
48+
And I create subsite '1' in 'wpsubdom.test'
49+
Then The site 'wpsubdom.test' should have webroot
50+
And The site 'wpsubdom.test' should have WordPress
51+
And The site 'wpsubdom.test' should be 'subdomain' multisite
52+
And Request on 'wpsubdom.test' should contain following headers:
53+
| header |
54+
| HTTP/1.1 200 OK |
3555

3656
Scenario: List the sites
3757
When I run 'sudo bin/ee site list --format=text'
3858
Then STDOUT should return exactly
3959
"""
40-
hello.test
60+
wp.test
61+
wpsubdir.test
62+
wpsubdom.test
4163
"""
4264

4365
Scenario: Delete the sites
44-
When I run 'sudo bin/ee site delete hello.test --yes'
66+
When I run 'sudo bin/ee site delete wp.test --yes'
4567
Then STDOUT should return something like
4668
"""
47-
Site hello.test deleted.
48-
"""
49-
And STDERR should return exactly
50-
"""
69+
Site wp.test deleted.
5170
"""
52-
And The 'hello.test' db entry should be removed
53-
And The 'hello.test' webroot should be removed
54-
And Following containers of site 'hello.test' should be removed:
55-
| container |
56-
| nginx |
57-
| php |
58-
| db |
59-
| redis |
60-
| phpmyadmin |
71+
And STDERR should return exactly
72+
"""
73+
"""
74+
And The 'wp.test' db entry should be removed
75+
And The 'wp.test' webroot should be removed
76+
And Following containers of site 'wp.test' should be removed:
77+
| container |
78+
| nginx |
79+
| php |
80+
| db |
81+
| redis |
82+
| phpmyadmin |

0 commit comments

Comments
 (0)