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
|
|
|
|
39
|
|
|
use BasicStructure; |
40
|
|
|
|
41
|
|
|
private $adminPassword; |
42
|
|
|
private $textEditorPage; |
43
|
|
|
private $featureContext; |
44
|
|
|
private $filesContext; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* TextEditorContext constructor. |
48
|
|
|
* |
49
|
|
|
* @param TextEditorPage $textEditorPage |
50
|
|
|
*/ |
51
|
|
|
public function __construct(TextEditorPage $textEditorPage) { |
52
|
|
|
$this->textEditorPage = $textEditorPage; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @When /^I create a text file with the name ((?:'[^']*')|(?:"[^"]*"))( without changing the default file extension|)$/ |
57
|
|
|
* |
58
|
|
|
* @param string $name |
59
|
|
|
* @param string $useDefaultFileExtension |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
public function createATextFileWithTheName( |
63
|
|
|
$name, |
64
|
|
|
$useDefaultFileExtension = '' |
65
|
|
|
) { |
66
|
|
|
// The capturing group of the regex always includes the quotes at each |
67
|
|
|
// end of the captured string, so trim them. |
68
|
|
|
$name = trim($name, $name[0]); |
69
|
|
|
$this->textEditorPage->createTextFile( |
70
|
|
|
$this->getSession(), |
71
|
|
|
$name, |
72
|
|
|
strlen($useDefaultFileExtension) ? true : false |
73
|
|
|
); |
74
|
|
|
$this->textEditorPage->waitTillEditorIsLoaded(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @Then near the new text file box a tooltip with the text :toolTipText should be displayed |
80
|
|
|
* @param string $toolTipText |
81
|
|
|
* @return void |
82
|
|
|
*/ |
83
|
|
|
public function nearTheNewTextFileBoxATooltipShouldBeDisplayed($toolTipText) { |
84
|
|
|
PHPUnit_Framework_Assert::assertEquals( |
85
|
|
|
$toolTipText, |
86
|
|
|
$this->textEditorPage->getTooltipOfNewTextFileBox() |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @When I input :text in the text area |
92
|
|
|
* @param string $text |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
public function iInputTextInTheTextArea($text) { |
96
|
|
|
$this->textEditorPage->typeIntoTextFile( |
97
|
|
|
$this->getSession(), |
98
|
|
|
$text |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @When I input the following text in the text area: |
104
|
|
|
* @param PyStringNode $multiLineText |
105
|
|
|
* @return void |
106
|
|
|
*/ |
107
|
|
|
public function iInputTheFollowingInTheTextArea(PyStringNode $multiLineText) { |
108
|
|
|
$this->textEditorPage->typeIntoTextFile( |
109
|
|
|
$this->getSession(), |
110
|
|
|
$multiLineText->getRaw() |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @Then there is/are :number line(s) of text |
116
|
|
|
* @param int $number |
117
|
|
|
* @return void |
118
|
|
|
*/ |
119
|
|
|
public function thereAreLinesOfText($number) { |
120
|
|
|
PHPUnit_Framework_Assert::assertEquals( |
121
|
|
|
$number, |
122
|
|
|
count($this->textEditorPage->textFileContent()) |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @Then line :number of the text is :text |
128
|
|
|
* @param int $number |
129
|
|
|
* @param string $text |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function lineOfTheTextIs($number, $text) { |
133
|
|
|
$lineIndex = $number - 1; |
134
|
|
|
$textFileContent = $this->textEditorPage->textFileContent(); |
135
|
|
|
PHPUnit_Framework_Assert::assertEquals( |
136
|
|
|
$text, |
137
|
|
|
$textFileContent[$lineIndex] |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
/** |
141
|
|
|
* @When I close the text editor |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
|
|
public function iCloseTheTextEditor() { |
145
|
|
|
$this->textEditorPage->closeTheTextEditor($this->getSession()); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* general before scenario for all text editor tests. |
150
|
|
|
* This will run before EVERY scenario. |
151
|
|
|
* It will set the properties for this object. |
152
|
|
|
* |
153
|
|
|
* @param BeforeScenarioScope $scope |
154
|
|
|
* @return void |
155
|
|
|
* @BeforeScenario |
156
|
|
|
*/ |
157
|
|
|
public function before(BeforeScenarioScope $scope) { |
158
|
|
|
// Get the environment |
159
|
|
|
$environment = $scope->getEnvironment(); |
160
|
|
|
// Get all the contexts you need in this context |
161
|
|
|
$this->featureContext = $environment->getContext('FeatureContext'); |
162
|
|
|
$this->filesContext = $environment->getContext('FilesContext'); |
163
|
|
|
$this->tmpDir = $this->getMinkParameter("show_tmp_dir"); |
164
|
|
|
// Initialize the setup helper so it can be used |
165
|
|
|
$suiteParameters = SetupHelper::getSuiteParameters($scope); |
166
|
|
|
$this->adminPassword = (string)$suiteParameters['adminPassword']; |
167
|
|
|
SetupHelper::init( |
168
|
|
|
"admin", $this->getUserPassword("admin"), |
169
|
|
|
$this->getMinkParameter('base_url'), $suiteParameters['ocPath'] |
170
|
|
|
); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|