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
|
|
|
use TestHelpers\SetupHelper; |
29
|
|
|
|
30
|
|
|
require_once 'bootstrap.php'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Text Editor context. |
34
|
|
|
*/ |
35
|
|
|
class TextEditorContext extends RawMinkContext implements Context { |
36
|
|
|
private $textEditorPage; |
37
|
|
|
private $featureContext; |
38
|
|
|
private $filesContext; |
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 /^I create a text file with the name ((?:'[^']*')|(?:"[^"]*"))( without changing the default file extension|)$/ |
51
|
|
|
* |
52
|
|
|
* @param string $name |
53
|
|
|
* @param string $useDefaultFileExtension |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function createATextFileWithTheName( |
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
|
|
|
/** |
73
|
|
|
* @Then near the new text file box a tooltip with the text :toolTipText should be displayed |
74
|
|
|
* @param string $toolTipText |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function nearTheNewTextFileBoxATooltipShouldBeDisplayed($toolTipText) { |
78
|
|
|
PHPUnit_Framework_Assert::assertEquals( |
79
|
|
|
$toolTipText, |
80
|
|
|
$this->textEditorPage->getTooltipOfNewTextFileBox() |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @When I input :text in the text area |
86
|
|
|
* @param string $text |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
public function iInputTextInTheTextArea($text) { |
90
|
|
|
$this->textEditorPage->typeIntoTextFile( |
91
|
|
|
$this->getSession(), |
92
|
|
|
$text |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @When I input the following text in the text area: |
98
|
|
|
* @param PyStringNode $multiLineText |
99
|
|
|
* @return void |
100
|
|
|
*/ |
101
|
|
|
public function iInputTheFollowingInTheTextArea(PyStringNode $multiLineText) { |
102
|
|
|
$this->textEditorPage->typeIntoTextFile( |
103
|
|
|
$this->getSession(), |
104
|
|
|
$multiLineText->getRaw() |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @Then there is/are :number line(s) of text |
110
|
|
|
* @param int $number |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
|
|
public function thereAreLinesOfText($number) { |
114
|
|
|
PHPUnit_Framework_Assert::assertEquals( |
115
|
|
|
$number, |
116
|
|
|
count($this->textEditorPage->textFileContent()) |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @Then line :number of the text is :text |
122
|
|
|
* @param int $number |
123
|
|
|
* @param string $text |
124
|
|
|
* @return void |
125
|
|
|
*/ |
126
|
|
|
public function lineOfTheTextIs($number, $text) { |
127
|
|
|
$lineIndex = $number - 1; |
128
|
|
|
$textFileContent = $this->textEditorPage->textFileContent(); |
129
|
|
|
PHPUnit_Framework_Assert::assertEquals( |
130
|
|
|
$text, |
131
|
|
|
$textFileContent[$lineIndex] |
132
|
|
|
); |
133
|
|
|
} |
134
|
|
|
/** |
135
|
|
|
* @When I close the text editor |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
public function iCloseTheTextEditor() { |
139
|
|
|
$this->textEditorPage->closeTheTextEditor($this->getSession()); |
140
|
|
|
} |
141
|
|
|
/** |
142
|
|
|
* general before scenario for all text editor tests. |
143
|
|
|
* This will run before EVERY scenario. |
144
|
|
|
* It will set the properties for this object. |
145
|
|
|
* |
146
|
|
|
* @param BeforeScenarioScope $scope |
147
|
|
|
* @return void |
148
|
|
|
* @BeforeScenario |
149
|
|
|
*/ |
150
|
|
|
public function before(BeforeScenarioScope $scope) { |
151
|
|
|
// Get the environment |
152
|
|
|
$environment = $scope->getEnvironment(); |
153
|
|
|
// Get all the contexts you need in this context |
154
|
|
|
$this->featureContext = $environment->getContext('FeatureContext'); |
155
|
|
|
$this->filesContext = $environment->getContext('FilesContext'); |
156
|
|
|
$this->tmpDir = $this->getMinkParameter("show_tmp_dir"); |
157
|
|
|
SetupHelper::setOcPath($scope); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|