-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmaxlength.test
106 lines (84 loc) · 3.07 KB
/
maxlength.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
<?php
/**
* @file
* Test maxlength module.
*/
class MaxlengthTestCase extends BackdropWebTestCase {
private $hyphen_type;
private $type;
public static function getInfo() {
return array(
'name' => 'Test maxlength module',
'description' => 'Tests the different features of the maxlength module.',
'group' => 'Maxlength',
);
}
protected function setUp() {
parent::setUp('maxlength');
$type = $this->backdropCreateContentType();
$this->type = $type->type;
$this->hyphen_type = str_replace('_', '-', $this->type);
$this->admin = $this->backdropCreateUser(array('administer content types', 'bypass node access'));
}
/**
* Test fieldapi field.
*/
function testField() {
$this->backdropLogin($this->admin);
$edit = array(
'instance[widget][settings][maxlength_js]' => rand(50, 100),
'instance[widget][settings][maxlength_js_label]' => $this->randomString(30),
);
$this->backdropPost('admin/structure/types/manage/' . $this->hyphen_type . '/fields/body', $edit, t('Save settings'));
$this->backdropGet('node/add/' . $this->hyphen_type);
// Check the maxlength html attributes.
$elements = $this->xpath('//textarea[@id=:id]', array(':id' => 'edit-body-und-0-value'));
foreach ($elements[0]->attributes() as $key => $value) {
switch ($key) {
case 'class':
$this->assertTrue(strpos($value, 'maxlength'), 'Take sure the maxlength class is existant');
break;
case 'maxlength_js':
$this->assertTrue($value, 'Take sure that the maxlenght_js attribute is set.');
break;
case 'maxlength_js_label':
$this->assertEqual($edit['instance[widget][settings][maxlength_js_label]'], $value, 'Take sure that the maxlenght_js_label is the defined one.');
break;
case 'maxlength':
$this->assertEqual($edit['instance[widget][settings][maxlength_js]'], $value);
}
}
}
/**
* Test title field.
*/
function testTitle() {
$this->backdropLogin($this->admin);
$edit = array(
'maxlength_js' => rand(50, 100),
'maxlength_js_label' => $this->randomString(30),
);
$this->backdropPost('admin/structure/types/manage/' . $this->hyphen_type . '/edit', $edit, t('Save content type'));
$this->backdropGet('node/add/' . $this->hyphen_type);
// Check the maxlength html attributes.
$elements = $this->xpath('//input[@id=:id]', array(':id' => 'edit-title'));
/*
foreach ($elements[0]->attributes() as $key => $value) {
switch ($key) {
case 'class':
$this->assertTrue(strpos($value, 'maxlength'), 'Take sure the maxlength class is existant');
break;
case 'maxlength_js':
$this->assertTrue($value, 'Take sure that the maxlenght_js attribute is set.');
break;
case 'maxlength_js_label':
$this->assertEqual($edit['maxlength_js_label'], $value, 'Take sure that the maxlenght_js_label is the defined one.');
break;
case 'maxlength':
$this->assertEqual($edit['maxlenght_js'], $value);
break;
}
}
*/
}
}