Completed
Branchmaster (48c558)
created

DetectorTest::setUpBeforeClass()   A

↳ Parent: DetectorTest

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 17
Code Lines 13

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
namespace Redaxscript\Tests\Detector;
3
4
use Redaxscript\Db;
5
use Redaxscript\Detector;
6
use Redaxscript\Registry;
7
use Redaxscript\Request;
8
use Redaxscript\Tests\TestCaseAbstract;
9
10
/**
11
 * DetectorTest
12
 *
13
 * @since 2.1.0
14
 *
15
 * @package Redaxscript
16
 * @category Tests
17
 * @author Henry Ruhs
18
 */
19
20
class DetectorTest extends TestCaseAbstract
21
{
22
	/**
23
	 * instance of the registry class
24
	 *
25
	 * @var object
26
	 */
27
28
	protected $_registry;
29
30
	/**
31
	 * instance of the request class
32
	 *
33
	 * @var object
34
	 */
35
36
	protected $_request;
37
38
	/**
39
	 * setUp
40
	 *
41
	 * @since 3.0.0
42
	 */
43
44
	public function setUp()
45
	{
46
		$this->_registry = Registry::getInstance();
47
		$this->_request = Request::getInstance();
48
	}
49
50
	/**
51
	 * setUpBeforeClass
52
	 *
53
	 * @since 3.0.0
54
	 */
55
56
	public static function setUpBeforeClass()
57
	{
58
		Db::forTablePrefix('articles')
59
			->create()
60
			->set(
61
			[
62
				'id' => 2,
63
				'title' => 'test',
64
				'alias' => 'test',
65
				'author' => 'test',
66
				'text' => 'test',
67
				'language' => 'de',
68
				'template' => 'wide',
69
				'date' => '2016-01-01 00:00:00'
70
			])
71
			->save();
72
	}
73
74
	/**
75
	 * tearDownAfterClass
76
	 *
77
	 * @since 3.0.0
78
	 */
79
80
	public static function tearDownAfterClass()
81
	{
82
		Db::setSetting('language', null);
83
		Db::setSetting('template', null);
84
		Db::forTablePrefix('articles')->whereIdIs(2)->deleteMany();
85
	}
86
87
	/**
88
	 * providerLanguage
89
	 *
90
	 * @since 2.1.0
91
	 *
92
	 * @return array
93
	 */
94
95
	public function providerLanguage()
96
	{
97
		return $this->getProvider('tests/provider/Detector/language.json');
98
	}
99
100
	/**
101
	 * providerTemplate
102
	 *
103
	 * @since 2.1.0
104
	 *
105
	 * @return array
106
	 */
107
108
	public function providerTemplate()
109
	{
110
		return $this->getProvider('tests/provider/Detector/template.json');
111
	}
112
113
	/**
114
	 * testLanguage
115
	 *
116
	 * @since 3.0.0
117
	 *
118
	 * @param array $queryArray
119
	 * @param array $sessionArray
120
	 * @param array $serverArray
121
	 * @param array $settingArray
122
	 * @param array $registryArray
123
	 * @param string $expect
124
	 *
125
	 * @dataProvider providerLanguage
126
	 */
127
128
	public function testLanguage($queryArray = [], $sessionArray = [], $serverArray = [], $settingArray = [], $registryArray = [], $expect = null)
129
	{
130
		/* setup */
131
132
		$this->_request->set('get', $queryArray);
133
		$this->_request->set('session', $sessionArray);
134
		$this->_request->set('server', $serverArray);
135
		Db::setSetting('language', $settingArray['language']);
136
		$this->_registry->init($registryArray);
137
		$detector = new Detector\Language($this->_registry, $this->_request);
138
139
		/* actual */
140
141
		$actual = $detector->getOutput();
142
143
		/* compare */
144
145
		$this->assertEquals($expect, $actual);
146
	}
147
148
	/**
149
	 * testTemplate
150
	 *
151
	 * @since 3.0.0
152
	 *
153
	 * @param array $queryArray
154
	 * @param array $sessionArray
155
	 * @param array $settingArray
156
	 * @param array $registryArray
157
	 * @param string $expect
158
	 *
159
	 * @dataProvider providerTemplate
160
	 */
161
162
	public function testTemplate($queryArray = [], $sessionArray = [], $settingArray = [], $registryArray = [], $expect = null)
163
	{
164
		/* setup */
165
166
		$this->_request->set('get', $queryArray);
167
		$this->_request->set('session', $sessionArray);
168
		Db::setSetting('template', $settingArray['template']);
169
		$this->_registry->init($registryArray);
170
		$detector = new Detector\Template($this->_registry, $this->_request);
171
172
		/* actual */
173
174
		$actual = $detector->getOutput();
175
176
		/* compare */
177
178
		$this->assertEquals($expect, $actual);
179
	}
180
}