Completed
Pull Request — master (#204)
by Phil
47:07 queued 22:02
created

TextEditorContext   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A createATextFileWithTheName() 0 14 2
A iInputTextInTheTextArea() 0 3 1
A iInputTheFollowingInTheTextArea() 0 3 1
A iCloseTheTextEditor() 0 3 1
A before() 0 11 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 $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 boolean $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
	 * @When I input :text in the text area
72
	 * @param string $text
73
	 * @return void
74
	 */
75
	public function iInputTextInTheTextArea($text) {
76
		$this->textEditorPage->typeIntoTextFile($text);
77
	}
78
79
	/**
80
	 * @When I input the following text in the text area:
81
	 * @param PyStringNode $multiLineText
82
	 * @return void
83
	 */
84
	public function iInputTheFollowingInTheTextArea(PyStringNode $multiLineText) {
85
		$this->textEditorPage->typeIntoTextFile($multiLineText->getRaw());
86
	}
87
88
	/**
89
	 * @When I close the text editor
90
	 * @return void
91
	 */
92
	public function iCloseTheTextEditor() {
93
		$this->textEditorPage->closeTheTextEditor();
94
	}
95
96
	/**
97
	 * general before scenario for all text editor tests.
98
	 * This will run before EVERY scenario.
99
	 * It will set the properties for this object.
100
	 *
101
	 * @param BeforeScenarioScope $scope
102
	 * @return void
103
	 * @BeforeScenario
104
	 */
105
	public function before(BeforeScenarioScope $scope) {
106
		// Get the environment
107
		$environment = $scope->getEnvironment();
108
		// Get all the contexts you need in this context
109
		$this->featureContext = $environment->getContext('FeatureContext');
110
		$this->filesContext = $environment->getContext('FilesContext');
111
		$this->tmpDir = $this->getMinkParameter("show_tmp_dir");
112
		$suiteParameters = $scope->getEnvironment()->getSuite()
113
			->getSettings() ['context'] ['parameters'];
114
		$this->ocPath = $suiteParameters['ocPath'];
115
	}
116
}
117