-
Notifications
You must be signed in to change notification settings - Fork 0
/
nivo_slider.test
127 lines (107 loc) · 3.77 KB
/
nivo_slider.test
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
<?php
/**
* @file
* Tests for nivo_slider.module.
*/
/**
* Defines a base class for testing the Nivo Slider module.
*/
class NivoSliderWebTestCase extends BackdropWebTestCase {
function setUp() {
parent::setUp('libraries', 'nivo_slider', 'jquery_update');
$web_user = $this->drupalCreateUser(array('administer nivo slider'));
$this->drupalLogin($web_user);
}
/**
* Retrieves a sample image file.
*/
function getTestImage() {
// Get a file to upload.
$file = current($this->drupalGetTestFiles('image'));
return $file;
}
}
/**
* Test creating, editing and deleting slides.
*/
class SlideTest extends NivoSliderWebTestCase {
public static function getInfo() {
return array(
'name' => 'Slides',
'description' => 'Test creating, editing and deleting slides.',
'group' => 'Nivo Slider',
);
}
function setUp() {
parent::setUp();
}
/**
* Add a new slide and ensure that it was created successfully.
*/
function testSlideTest() {
// Check to ensure that the slider is not displayed.
$this->drupalGet('<front>');
$this->assertNoRaw('//div[@id="slider"]', 'There is no slider on the front page.');
// Load the slider slides administration page.
$this->drupalGet('admin/structure/nivo-slider');
$this->assertResponse(200, t('The privileged user can access the slider slides administration page.'));
$file = $this->getTestImage();
// Create five new slide.
for ($i = 0; $i <= 5; $i++) {
$edit = array();
$edit['files[upload]'] = backdrop_realpath($file->uri);
$this->drupalPost('admin/structure/nivo-slider', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
}
// Check to ensure that the slider is displayed.
$this->drupalGet('<front>');
$elements = $this->xpath('//div[@id="slider"]');
$this->assertEqual(count($elements), 1, t('There is exactly one slider on the front page.'));
// Delete the five existing slides.
for ($i = 5; $i <= 0; $i--) {
$edit = array();
$edit["images[{$i}][delete]"] = TRUE;
$this->drupalPost('admin/structure/nivo-slider', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
}
}
}
/**
* Test configuring slide options.
*/
class OptionTest extends NivoSliderWebTestCase {
public static function getInfo() {
return array(
'name' => 'Options',
'description' => 'Test configuring slider options.',
'group' => 'Nivo Slider',
);
}
function setUp() {
parent::setUp();
}
/**
* Add a new slide and ensure that it was created successfully.
*/
function testOptionTest() {
$file = $this->getTestImage();
// Create a new slide.
$edit = array();
$edit['files[upload]'] = backdrop_realpath($file->uri);
$this->drupalPost('admin/structure/nivo-slider', $edit, t('Save configuration'));
// Load the slider options administration page.
$this->drupalGet('admin/structure/nivo-slider/options');
$this->assertResponse(200, t('The privileged user can access the slider options administration page.'));
$themes = array('bar', 'dark', 'default', 'light');
// Test to ensure that the slider theme can be changed.
foreach ($themes as $theme) {
$edit = array();
$edit['nivo_slider_theme'] = $theme;
$this->drupalPost('admin/structure/nivo-slider/options', $edit, t('Save configuration'));
// Check to ensure that the slider is displayed with the proper theme.
$this->drupalGet('<front>');
$elements = $this->xpath('//div[@class="slider-wrapper theme-' . $theme . '"]');
$this->assertEqual(count($elements), 1, t('There is exactly one slider with the current theme on the front page.'));
}
}
}