-
-
Notifications
You must be signed in to change notification settings - Fork 529
/
Copy pathWelcomeControllerTest.php
170 lines (154 loc) · 5.26 KB
/
WelcomeControllerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/*
* This file is part of the MODX Revolution package.
*
* Copyright (c) MODX, LLC
*
* For complete copyright and license information, see the COPYRIGHT and LICENSE
* files found in the top-level directory of this distribution.
*
*/
/**
* Tests related to the Welcome controller
*
* @package modx-test
* @subpackage modx
* @group Controllers
* @group Dashboard
* @group WelcomeController
*/
class WelcomeControllerTest extends MODxControllerTestCase {
/** @var WelcomeManagerController $controller */
public $controller;
public $controllerName = 'WelcomeManagerController';
public $controllerPath = 'welcome';
public function setUp(): void
{
parent::setUp();
/** @var modDashboard $dashboard */
$this->controller->dashboard = $this->modx->newObject('modDashboard');
$this->controller->dashboard->fromArray(array(
'id' => 10000,
'name' => 'Unit Test Dashboard',
),'',true,true);
$this->controller->dashboard->save();
/** @var modDashboardWidget $dashboardWidget */
$dashboardWidget = $this->modx->newObject('modDashboardWidget');
$dashboardWidget->fromArray(array(
'id' => 10000,
'name' => 'Unit Test Dashboard Widget',
'type' => 'html',
'content' => '<h2>Unit Test Widget Output</h2>',
'namespace' => 'core',
'lexicon' => 'core:dashboards',
'size' => 'half',
),'',true,true);
$dashboardWidget->save();
/** @var modDashboardWidgetPlacement $dashboardWidgetPlacement */
$dashboardWidgetPlacement = $this->modx->newObject('modDashboardWidgetPlacement');
$dashboardWidgetPlacement->fromArray(array(
'dashboard' => $this->controller->dashboard->get('id'),
'widget' => $dashboardWidget->get('id'),
'rank' => 0,
),'',true,true);
$dashboardWidgetPlacement->save();
/** @var modUserGroup $userGroup */
$userGroup = $this->modx->newObject('modUserGroup');
$userGroup->fromArray(array(
'id' => 10000,
'name' => 'Unit Test User Group 1',
'parent' => 0,
'rank' => 0,
'dashboard' => 10000,
),'',true,true);
$userGroup->save();
}
public function tearDown(): void
{
parent::tearDown();
$userGroups = $this->modx->getCollection('modUserGroup',array('name:LIKE' => '%Unit Test%'));
/** @var modUserGroup $userGroup */
foreach ($userGroups as $userGroup) {
$userGroup->remove();
}
$dashboards = $this->modx->getCollection('modDashboard',array('name:LIKE' => '%Unit Test%'));
/** @var modDashboard $dashboard */
foreach ($dashboards as $dashboard) {
$dashboard->remove();
}
$widgets = $this->modx->getCollection('modDashboardWidget',array('name:LIKE' => '%Unit Test%'));
/** @var modDashboardWidget $widget */
foreach ($widgets as $widget) {
$widget->remove();
}
$this->modx->user->set('primary_group',0);
}
/**
* @param string|int $userGroupPk
* @dataProvider providerGetDashboard
*/
public function testGetDashboard($userGroupPk) {
$this->modx->user->set('primary_group',$userGroupPk);
$dashboard = $this->controller->dashboard;
$this->assertInstanceOf('modDashboard',$dashboard);
}
/**
* @return array
*/
public function providerGetDashboard() {
return array(
array(0), /* default dashboard */
array(10000),/* custom unit test dashboard */
array(99999),/* invalid primary group, should fallback to default dashboard */
);
}
/**
* Run a test to ensure custom dashboards work as expected
*/
public function testCustomDashboardRender() {
$this->modx->user->set('primary_group',10000);
$dashboard = $this->controller->dashboard;
$content = $dashboard->render($this->controller);
$this->assertContains('<h2>Unit Test Widget Output</h2>',$content);
}
/**
* Test to see if the welcome screen loads as expected
* @param boolean $showWelcomeScreen
* @dataProvider providerWelcomeScreen
*/
public function testWelcomeScreen($showWelcomeScreen) {
$this->modx->setOption('welcome_screen',$showWelcomeScreen);
$this->controller->checkForWelcomeScreen();
$this->assertEquals($showWelcomeScreen,$this->controller->showWelcomeScreen);
}
/**
* @return array
*/
public function providerWelcomeScreen() {
return array(
array(false),
array(true),
);
}
/**
* @return void
*/
public function testLoadCustomCssJs() {
$this->controller->loadCustomCssJs();
$this->assertNotEmpty($this->controller->head['js']);
}
/**
* @return void
*/
public function testGetTemplateFile() {
$templateFile = $this->controller->getTemplateFile();
$this->assertNotEmpty($templateFile);
}
/**
* @return void
*/
public function testGetPageTitle() {
$pageTitle = $this->controller->getPageTitle();
$this->assertNotEmpty($pageTitle);
}
}