Completed
Push — master ( d39d36...4c476a )
by Phil
21:59
created

TextEditorContext::afterTextEditorSuite()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 * ownCloud
4
 *
5
 * @author Phillip Davis <[email protected]>
6
 * @copyright 2017 Phillip Davis [email protected]
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
use Behat\Behat\Context\Context;
24
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
25
use Behat\Gherkin\Node\PyStringNode;
26
use Behat\MinkExtension\Context\RawMinkContext;
27
use Behat\Testwork\Hook\Scope\AfterSuiteScope;
28
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
29
use Page\TextEditorPage;
30
use TestHelpers\SetupHelper;
31
32
require_once 'bootstrap.php';
33
34
/**
35
 * Text Editor context.
36
 */
37
class TextEditorContext extends RawMinkContext implements Context {
38
	private $textEditorPage;
39
	private $featureContext;
40
	private $filesContext;
41
42
	/**
43
	 * @var boolean
44
	 */
45
	private static $appHadToBeEnabled = false;
46
47
	/**
48
	 * TextEditorContext constructor.
49
	 *
50
	 * @param TextEditorPage $textEditorPage
51
	 */
52
	public function __construct(TextEditorPage $textEditorPage) {
53
		$this->textEditorPage = $textEditorPage;
54
	}
55
56
	/**
57
	 * @When /^I create a text file with the name ((?:'[^']*')|(?:"[^"]*"))( without changing the default file extension|)$/
58
	 *
59
	 * @param string $name
60
	 * @param string $useDefaultFileExtension
61
	 * @return void
62
	 */
63
	public function createATextFileWithTheName(
64
		$name,
65
		$useDefaultFileExtension = ''
66
	) {
67
		// The capturing group of the regex always includes the quotes at each
68
		// end of the captured string, so trim them.
69
		$name = trim($name, $name[0]);
70
		$this->textEditorPage->createTextFile(
71
			$this->getSession(),
72
			$name,
73
			strlen($useDefaultFileExtension) ? true : false
74
		);
75
		$this->textEditorPage->waitTillEditorIsLoaded();
76
	}
77
78
79
	/**
80
	 * @Then near the new text file box a tooltip with the text :toolTipText should be displayed
81
	 * @param string $toolTipText
82
	 * @return void
83
	 */
84
	public function nearTheNewTextFileBoxATooltipShouldBeDisplayed($toolTipText) {
85
		PHPUnit_Framework_Assert::assertEquals(
86
			$toolTipText,
87
			$this->textEditorPage->getTooltipOfNewTextFileBox()
88
		);
89
	}
90
91
	/**
92
	 * @When I input :text in the text area
93
	 * @param string $text
94
	 * @return void
95
	 */
96
	public function iInputTextInTheTextArea($text) {
97
		$this->textEditorPage->typeIntoTextFile(
98
			$this->getSession(),
99
			$text
100
		);
101
	}
102
103
	/**
104
	 * @When I input the following text in the text area:
105
	 * @param PyStringNode $multiLineText
106
	 * @return void
107
	 */
108
	public function iInputTheFollowingInTheTextArea(PyStringNode $multiLineText) {
109
		$this->textEditorPage->typeIntoTextFile(
110
			$this->getSession(),
111
			$multiLineText->getRaw()
112
		);
113
	}
114
115
	/**
116
	 * @Then there is/are :number line(s) of text
117
	 * @param int $number
118
	 * @return void
119
	 */
120
	public function thereAreLinesOfText($number) {
121
		PHPUnit_Framework_Assert::assertEquals(
122
			$number,
123
			count($this->textEditorPage->textFileContent())
124
		);
125
	}
126
127
	/**
128
	 * @Then line :number of the text is :text
129
	 * @param int $number
130
	 * @param string $text
131
	 * @return void
132
	 */
133
	public function lineOfTheTextIs($number, $text) {
134
		$lineIndex = $number - 1;
135
		$textFileContent = $this->textEditorPage->textFileContent();
136
		PHPUnit_Framework_Assert::assertEquals(
137
			$text,
138
			$textFileContent[$lineIndex]
139
		);
140
	}
141
	/**
142
	 * @When I close the text editor
143
	 * @return void
144
	 */
145
	public function iCloseTheTextEditor() {
146
		$this->textEditorPage->closeTheTextEditor($this->getSession());
147
	}
148
149
	/**
150
	 * This will run once at the start of a whole suite
151
	 * of features with scenarios.
152
	 *
153
	 * @param BeforeSuiteScope $scope
154
	 * @return void
155
	 * @BeforeSuite
156
	 */
157
	public static function beforeTextEditorSuite(BeforeSuiteScope $scope) {
158
		SetupHelper::setOcPath($scope);
159
		self::$appHadToBeEnabled = SetupHelper::enableAppIfNotEnabled(
160
			'files_texteditor'
161
		);
162
	}
163
164
	/**
165
	 * This will run once at the end of a whole suite
166
	 * of features with scenarios.
167
	 *
168
	 * @param AfterSuiteScope $scope
169
	 * @return void
170
	 * @AfterSuite
171
	 */
172
	public static function afterTextEditorSuite(AfterSuiteScope $scope) {
173
		if (self::$appHadToBeEnabled) {
174
			SetupHelper::disableApp('files_texteditor');
175
		}
176
	}
177
178
	/**
179
	 * general before scenario for all text editor tests.
180
	 * This will run before EVERY scenario.
181
	 * It will set the properties for this object.
182
	 *
183
	 * @param BeforeScenarioScope $scope
184
	 * @return void
185
	 * @BeforeScenario
186
	 */
187
	public function before(BeforeScenarioScope $scope) {
188
		// Get the environment
189
		$environment = $scope->getEnvironment();
190
		// Get all the contexts you need in this context
191
		$this->featureContext = $environment->getContext('FeatureContext');
192
		$this->filesContext = $environment->getContext('FilesContext');
193
		$this->tmpDir = $this->getMinkParameter("show_tmp_dir");
194
	}
195
}
196