Completed
Push — master ( 82c92d...22fc86 )
by Phil
02:19
created

theUserInputsTheFollowingInTheTextArea()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
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 Page\TextEditorPage;
28
29
require_once 'bootstrap.php';
30
31
/**
32
 * Text Editor context.
33
 */
34
class TextEditorContext extends RawMinkContext implements Context {
35
36
	private $textEditorPage;
37
	private $webUIGeneralContext;
38
	private $webUIFilesContext;
39
40
	/**
41
	 * TextEditorContext constructor.
42
	 *
43
	 * @param TextEditorPage $textEditorPage
44
	 */
45
	public function __construct(TextEditorPage $textEditorPage) {
46
		$this->textEditorPage = $textEditorPage;
47
	}
48
49
	/**
50
	 * @When /^the user creates a text file with the name ((?:'[^']*')|(?:"[^"]*")) using the webUI( without changing the default file extension|)$/
51
	 *
52
	 * @param string $name
53
	 * @param string $useDefaultFileExtension
54
	 *
55
	 * @return void
56
	 */
57
	public function createATextFileWithTheNameUsingTheWebUI(
58
		$name,
59
		$useDefaultFileExtension = ''
60
	) {
61
		// The capturing group of the regex always includes the quotes at each
62
		// end of the captured string, so trim them.
63
		$name = trim($name, $name[0]);
64
		$this->textEditorPage->createTextFile(
65
			$this->getSession(),
66
			$name,
67
			strlen($useDefaultFileExtension) ? true : false
68
		);
69
		$this->textEditorPage->waitTillEditorIsLoaded();
70
	}
71
72
73
	/**
74
	 * @Then near the new text file box a tooltip with the text :toolTipText should be displayed on the webUI
75
	 *
76
	 * @param string $toolTipText
77
	 *
78
	 * @return void
79
	 */
80
	public function nearTheNewTextFileBoxATooltipShouldBeDisplayedOnTheWebUI(
81
		$toolTipText
82
	) {
83
		PHPUnit_Framework_Assert::assertEquals(
84
			$toolTipText,
85
			$this->textEditorPage->getTooltipOfNewTextFileBox()
86
		);
87
	}
88
89
	/**
90
	 * @When the user inputs :text in the text area
91
	 *
92
	 * @param string $text
93
	 *
94
	 * @return void
95
	 */
96
	public function theUserInputsTextInTheTextArea($text) {
97
		$this->textEditorPage->typeIntoTextFile(
98
			$this->getSession(),
99
			$text
100
		);
101
	}
102
103
	/**
104
	 * @When the user inputs the following text in the text area:
105
	 *
106
	 * @param PyStringNode $multiLineText
107
	 *
108
	 * @return void
109
	 */
110
	public function theUserInputsTheFollowingInTheTextArea(
111
		PyStringNode $multiLineText
112
	) {
113
		$this->textEditorPage->typeIntoTextFile(
114
			$this->getSession(),
115
			$multiLineText->getRaw()
116
		);
117
	}
118
119
	/**
120
	 * @Then there should be :number line(s) of text in the text area
121
	 *
122
	 * @param int $number
123
	 *
124
	 * @return void
125
	 */
126
	public function thereShouldBeLinesOfTextInTheTextArea($number) {
127
		PHPUnit_Framework_Assert::assertEquals(
128
			$number,
129
			count($this->textEditorPage->textFileContent())
130
		);
131
	}
132
133
	/**
134
	 * @Then line :number of the text should be :text
135
	 *
136
	 * @param int $number
137
	 * @param string $text
138
	 *
139
	 * @return void
140
	 */
141
	public function lineOfTheTextShouldBe($number, $text) {
142
		$lineIndex = $number - 1;
143
		$textFileContent = $this->textEditorPage->textFileContent();
144
		PHPUnit_Framework_Assert::assertEquals(
145
			$text,
146
			$textFileContent[$lineIndex]
147
		);
148
	}
149
	/**
150
	 * @When the user closes the text editor
151
	 *
152
	 * @return void
153
	 */
154
	public function theUserClosesTheTextEditor() {
155
		$this->textEditorPage->closeTheTextEditor($this->getSession());
156
	}
157
158
	/**
159
	 * general before scenario for all text editor tests.
160
	 * This will run before EVERY scenario.
161
	 * It will set the properties for this object.
162
	 *
163
	 * @BeforeScenario
164
	 *
165
	 * @param BeforeScenarioScope $scope
166
	 *
167
	 * @return void
168
	 */
169
	public function before(BeforeScenarioScope $scope) {
170
		// Get the environment
171
		$environment = $scope->getEnvironment();
172
		// Get all the contexts you need in this context
173
		$this->webUIGeneralContext = $environment->getContext('WebUIGeneralContext');
174
		$this->webUIFilesContext = $environment->getContext('WebUIFilesContext');
175
		$this->tmpDir = $this->getMinkParameter("show_tmp_dir");
176
	}
177
}
178