Completed
Push — master ( de9e2d...f59dfb )
by Henry
08:37
created

InstallationTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testTitle() 0 11 1
A testBehaviour() 0 54 1
A testInstall() 0 33 1
1
<?php
2
namespace Redaxscript\Tests;
3
4
use Facebook\WebDriver\WebDriverBy;
5
use Facebook\WebDriver\WebDriverExpectedCondition;
6
use Facebook\WebDriver\WebDriverSelect;
7
8
/**
9
 * InstallationTest
10
 *
11
 * @since 4.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 */
17
18
class InstallationTest extends TestCaseAbstract
19
{
20
	/**
21
	 * setUp
22
	 *
23
	 * @since 4.0.0
24
	 */
25
26
	public function setUp()
27
	{
28
		parent::setUp();
29
		$this->_driver->get('http://localhost:8000/install.php');
30
	}
31
32
	/**
33
	 * testTitle
34
	 *
35
	 * @since 4.0.0
36
	 */
37
38
	public function testTitle()
39
	{
40
		/* expect and actual */
41
42
		$expect = $this->_language->get('installation');
43
		$actual = $this->_driver->getTitle();
44
45
		/* compare */
46
47
		$this->assertEquals($expect, $actual);
48
	}
49
50
	/**
51
	 * testBehaviour
52
	 *
53
	 * @since 4.0.0
54
	 */
55
56
	public function testBehaviour()
57
	{
58
		/* prepare */
59
60
		$formElement = $this->_driver->findElement(WebDriverBy::tagName('form'));
61
		$dbHostElement = $formElement->findElement(WebDriverBy::id('db-host'));
62
		$dbTypeElement = $formElement->findElement(WebDriverBy::id('db-type'));
63
		$dbNameElement = $formElement->findElement(WebDriverBy::id('db-name'));
64
		$dbUserElement = $formElement->findElement(WebDriverBy::id('db-user'));
65
		$dbPasswordElement = $formElement->findElement(WebDriverBy::id('db-password'));
66
		$dbPrefixElement = $formElement->findElement(WebDriverBy::id('db-prefix'));
67
		$adminNameElement = $formElement->findElement(WebDriverBy::id('admin-name'));
68
		$adminUserElement = $formElement->findElement(WebDriverBy::id('admin-user'));
69
		$adminPasswordElement = $formElement->findElement(WebDriverBy::id('admin-password'));
70
		$adminEmailElement = $formElement->findElement(WebDriverBy::id('admin-email'));
71
		$labelAccountElement =  $formElement->findElement(WebDriverBy::cssSelector('[for*="Account"]'));
72
73
		/* setup */
74
75
		$dbTypeSelect = new WebDriverSelect($dbTypeElement);
76
77
		/* compare */
78
79
		$this->assertFalse($adminNameElement->isDisplayed());
80
		$this->assertFalse($adminUserElement->isDisplayed());
81
		$this->assertFalse($adminPasswordElement->isDisplayed());
82
		$this->assertFalse($adminEmailElement->isDisplayed());
83
84
		/* setup and compare */
85
86
		$dbTypeSelect->selectByValue('sqlite');
87
		$this->assertTrue($dbHostElement->isDisplayed());
88
		$this->assertFalse($dbNameElement->isDisplayed());
89
		$this->assertFalse($dbUserElement->isDisplayed());
90
		$this->assertFalse($dbPasswordElement->isDisplayed());
91
		$this->assertTrue($dbPrefixElement->isDisplayed());
92
93
		/* setup and compare */
94
95
		$dbTypeSelect->selectByValue('mysql');
96
		$this->assertTrue($dbHostElement->isDisplayed());
97
		$this->assertTrue($dbNameElement->isDisplayed());
98
		$this->assertTrue($dbUserElement->isDisplayed());
99
		$this->assertTrue($dbPasswordElement->isDisplayed());
100
		$this->assertTrue($dbPrefixElement->isDisplayed());
101
102
		/* setup and compare */
103
104
		$labelAccountElement->click();
105
		$this->assertTrue($adminNameElement->isDisplayed());
106
		$this->assertTrue($adminUserElement->isDisplayed());
107
		$this->assertTrue($adminPasswordElement->isDisplayed());
108
		$this->assertTrue($adminEmailElement->isDisplayed());
109
	}
110
111
	/**
112
	 * testInstall
113
	 *
114
	 * @since 4.0.0
115
	 */
116
117
	public function testInstall()
118
	{
119
		/* prepare */
120
121
		$formElement = $this->_driver->findElement(WebDriverBy::tagName('form'));
122
		$dbHostElement = $formElement->findElement(WebDriverBy::id('db-host'));
123
		$dbTypeElement = $formElement->findElement(WebDriverBy::id('db-type'));
124
		$dbPrefixElement = $formElement->findElement(WebDriverBy::id('db-prefix'));
125
		$adminNameElement = $formElement->findElement(WebDriverBy::id('admin-name'));
126
		$adminUserElement = $formElement->findElement(WebDriverBy::id('admin-user'));
127
		$adminPasswordElement = $formElement->findElement(WebDriverBy::id('admin-password'));
128
		$adminEmailElement = $formElement->findElement(WebDriverBy::id('admin-email'));
129
		$labelAccountElement =  $formElement->findElement(WebDriverBy::cssSelector('[for*="Account"]'));
130
		$buttonElement = $formElement->findElement(WebDriverBy::tagName('button'));
131
		$dbTypeSelect = new WebDriverSelect($dbTypeElement);
132
133
		/* setup */
134
135
		$dbTypeSelect->selectByValue('sqlite');
136
		$dbHostElement->sendKeys('build/test.sqlite');
137
		$dbPrefixElement->sendKeys('test_');
138
		$labelAccountElement->click();
139
		$adminNameElement->sendKeys('Test');
140
		$adminUserElement->sendKeys('test');
141
		$adminPasswordElement->sendKeys('test');
142
		$adminEmailElement->sendKeys('[email protected]');
143
		$buttonElement->click();
144
145
		/* compare */
146
147
		$this->_driver->wait(5)->until(WebDriverExpectedCondition::urlIs('http://localhost:8000/index.php'));
148
		$this->expectNotToPerformAssertions();
149
	}
150
}
151