TextEditorContext   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 1
dl 0
loc 141
rs 10
c 0
b 0
f 0

9 Methods

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