Completed
Pull Request — master (#204)
by Phil
25:17 queued 23:57
created

TextEditorContext   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createATextFileWithTheName() 0 11 2
A iInputTextInTheTextArea() 0 4 1
A iInputTheFollowingInTheTextArea() 0 4 1
A iCloseTheTextEditor() 0 4 1
A before() 0 11 1
1
<?php
2
/**
3
* ownCloud
4
*
5
* @author Phillip Davis
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
 * Files context.
33
 */
34
class TextEditorContext extends RawMinkContext implements Context
35
{
36
	private $textEditorPage;
37
	private $featureContext;
38
	private $filesContext;
39
40
	public function __construct(TextEditorPage $textEditorPage)
41
	{
42
		$this->textEditorPage = $textEditorPage;
43
	}
44
45
	/**
46
	 * @When /^I create a text file with the name ((?:'[^']*')|(?:"[^"]*"))( without changing the default file extension|)$/
47
	 *
48
	 * @param string $name
49
	 * @return void
50
	 */
51
	public function createATextFileWithTheName($name, $useDefaultFileExtension = '') {
52
		// The capturing group of the regex always includes the quotes at each
53
		// end of the captured string, so trim them.
54
		$name = trim($name, $name[0]);
55
		$this->textEditorPage->createTextFile(
56
			$this->getSession(),
57
			$name,
58
			strlen($useDefaultFileExtension) ? true : false
59
		);
60
		$this->textEditorPage->waitTillEditorIsLoaded();
61
	}
62
63
	/**
64
	 * @When I input :text in the text area
65
	 */
66
	public function iInputTextInTheTextArea($text)
67
	{
68
		$this->textEditorPage->typeIntoTextFile($text);
69
	}
70
71
	/**
72
	 * @When I input the following text in the text area:
73
	 */
74
	public function iInputTheFollowingInTheTextArea(PyStringNode $multiLineText)
75
	{
76
		$this->textEditorPage->typeIntoTextFile($multiLineText->getRaw());
77
	}
78
79
	/**
80
	 * @When I close the text editor
81
	 */
82
	public function iCloseTheTextEditor()
83
	{
84
		$this->textEditorPage->closeTheTextEditor();
85
	}
86
87
	/**
88
	 * general before scenario for all text editor tests.
89
	 * This will run before EVERY scenario.
90
	 * It will set the properties for this object.
91
	 *
92
	 * @param BeforeScenarioScope $scope
93
	 * @return void
94
	 * @BeforeScenario
95
	 */
96
	public function before(BeforeScenarioScope $scope) {
97
		// Get the environment
98
		$environment = $scope->getEnvironment();
99
		// Get all the contexts you need in this context
100
		$this->featureContext = $environment->getContext('FeatureContext');
101
		$this->filesContext = $environment->getContext('FilesContext');
102
		$this->tmpDir = $this->getMinkParameter("show_tmp_dir");
103
		$suiteParameters = $scope->getEnvironment()->getSuite()
104
			->getSettings() ['context'] ['parameters'];
105
		$this->ocPath = $suiteParameters['ocPath'];
106
	}
107
}
108