Completed
Push — master ( 026716...d5b3a1 )
by Phil
23:32
created

TextEditorContext::createATextFileWithTheName()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 1
nop 2
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 $featureContext;
37
	private $filesContext;
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 /^I create a text file with the name ((?:'[^']*')|(?:"[^"]*"))( without changing the default file extension|)$/
50
	 *
51
	 * @param string $name
52
	 * @param string $useDefaultFileExtension
53
	 * @return void
54
	 */
55
	public function createATextFileWithTheName(
56
		$name,
57
		$useDefaultFileExtension = ''
58
	) {
59
		// The capturing group of the regex always includes the quotes at each
60
		// end of the captured string, so trim them.
61
		$name = trim($name, $name[0]);
62
		$this->textEditorPage->createTextFile(
63
			$this->getSession(),
64
			$name,
65
			strlen($useDefaultFileExtension) ? true : false
66
		);
67
		$this->textEditorPage->waitTillEditorIsLoaded();
68
	}
69
70
71
	/**
72
	 * @Then near the new text file box a tooltip with the text :toolTipText should be displayed
73
	 */
74
	public function nearTheNewTextFileBoxATooltipShouldBeDisplayed($toolTipText)
75
	{
76
		PHPUnit_Framework_Assert::assertEquals($toolTipText,
77
			$this->textEditorPage->getTooltipOfNewTextFileBox()
78
		);
79
	}
80
81
	/**
82
	 * @When I input :text in the text area
83
	 * @param string $text
84
	 * @return void
85
	 */
86
	public function iInputTextInTheTextArea($text) {
87
		$this->textEditorPage->typeIntoTextFile(
88
			$this->getSession(),
89
			$text
90
		);
91
	}
92
93
	/**
94
	 * @When I input the following text in the text area:
95
	 * @param PyStringNode $multiLineText
96
	 * @return void
97
	 */
98
	public function iInputTheFollowingInTheTextArea(PyStringNode $multiLineText) {
99
		$this->textEditorPage->typeIntoTextFile(
100
			$this->getSession(),
101
			$multiLineText->getRaw()
102
		);
103
	}
104
105
	/**
106
	 * @Then there is/are :number line(s) of text
107
	 * @param int $number
108
	 * @return void
109
	 */
110
	public function thereAreLinesOfText($number) {
111
		PHPUnit_Framework_Assert::assertEquals(
112
			$number,
113
			count($this->textEditorPage->textFileContent())
114
		);
115
	}
116
117
	/**
118
	 * @Then line :number of the text is :text
119
	 * @param int $number
120
	 * @param string $text
121
	 * @return void
122
	 */
123
	public function lineOfTheTextIs($number, $text) {
124
		$lineIndex = $number - 1;
125
		$textFileContent = $this->textEditorPage->textFileContent();
126
		PHPUnit_Framework_Assert::assertEquals(
127
			$text,
128
			$textFileContent[$lineIndex]
129
		);
130
	}
131
	/**
132
	 * @When I close the text editor
133
	 * @return void
134
	 */
135
	public function iCloseTheTextEditor() {
136
		$this->textEditorPage->closeTheTextEditor($this->getSession());
137
	}
138
	/**
139
	 * general before scenario for all text editor tests.
140
	 * This will run before EVERY scenario.
141
	 * It will set the properties for this object.
142
	 *
143
	 * @param BeforeScenarioScope $scope
144
	 * @return void
145
	 * @BeforeScenario
146
	 */
147
	public function before(BeforeScenarioScope $scope) {
148
		// Get the environment
149
		$environment = $scope->getEnvironment();
150
		// Get all the contexts you need in this context
151
		$this->featureContext = $environment->getContext('FeatureContext');
152
		$this->filesContext = $environment->getContext('FilesContext');
153
		$this->tmpDir = $this->getMinkParameter("show_tmp_dir");
154
		$suiteParameters = $scope->getEnvironment()->getSuite()
155
			->getSettings() ['context'] ['parameters'];
156
		$this->ocPath = $suiteParameters['ocPath'];
157
	}
158
}
159