1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Test general functionality of Webform.
|
6
|
*/
|
7
|
class WebformGeneralTestCase extends WebformTestCase {
|
8
|
/**
|
9
|
* {@inheritdoc}
|
10
|
*/
|
11
|
public static function getInfo() {
|
12
|
return array(
|
13
|
'name' => t('Webform'),
|
14
|
'description' => t('Checks global Webform settings and content types.'),
|
15
|
'group' => t('Webform'),
|
16
|
);
|
17
|
}
|
18
|
|
19
|
/**
|
20
|
* Test creating a new Webform node.
|
21
|
*/
|
22
|
function testWebformCreate() {
|
23
|
$settings = array(
|
24
|
'title' => 'Test webform, no components',
|
25
|
'type' => 'webform',
|
26
|
);
|
27
|
$node = $this->drupalCreateNode($settings);
|
28
|
|
29
|
// Because this is a "webform" type node, it should have an entry in the
|
30
|
// database even though it's using the default settings.
|
31
|
$this->assertTrue($this->webformRecordExists($node->nid), t('Webform record made in the database for the new webform node.'));
|
32
|
|
33
|
// Make a change to the node, ensure that the record stays intact.
|
34
|
$node->title .= '!';
|
35
|
node_save($node);
|
36
|
$this->assertTrue($this->webformRecordExists($node->nid), t('Webform record still in the database after modifying webform node.'));
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* Test webform-enabling a different node type and testing behavior.
|
41
|
*/
|
42
|
function testWebformCreateNewType() {
|
43
|
// Enable webforms on the page content type.
|
44
|
variable_set('webform_node_webform', TRUE);
|
45
|
variable_set('webform_node_page', TRUE);
|
46
|
|
47
|
$settings = array(
|
48
|
'title' => 'Test webform-enabled page',
|
49
|
'type' => 'page',
|
50
|
);
|
51
|
$node = $this->drupalCreateNode($settings);
|
52
|
|
53
|
// Because this is a webform-enabled type node but does not yet have any
|
54
|
// components, it should not have an entry in the database because it is
|
55
|
// using the default settings.
|
56
|
$this->assertFalse($this->webformRecordExists($node->nid), t('Webform record not in the database for the new page node.'));
|
57
|
|
58
|
// Make a change to the node, ensure that the record stays empty.
|
59
|
$node->title .= '!';
|
60
|
node_save($node);
|
61
|
$this->assertFalse($this->webformRecordExists($node->nid), t('Webform record still not in the database after modifying page node.'));
|
62
|
|
63
|
// Add a new component to the node and check that a record is made in the
|
64
|
// webform table.
|
65
|
$components = $this->webformComponents();
|
66
|
$textarea = $components['textarea'];
|
67
|
$textarea['type'] = 'textarea';
|
68
|
$textarea['form_key'] = 'textarea';
|
69
|
$textarea['cid'] = 1;
|
70
|
$textarea['pid'] = 0;
|
71
|
$textarea = array_merge(webform_component_invoke('textarea', 'defaults'), $textarea);
|
72
|
$node->webform['components'][1] = $textarea;
|
73
|
node_save($node);
|
74
|
$this->assertTrue($this->webformRecordExists($node->nid), t('Webform record now exists after adding a new component.'));
|
75
|
|
76
|
// Remove the new component and ensure that the record is deleted.
|
77
|
$node->webform['components'] = array();
|
78
|
node_save($node);
|
79
|
$this->assertFalse($this->webformRecordExists($node->nid), t('Webform record deleted after deleting last component.'));
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* @return bool
|
84
|
*/
|
85
|
function webformRecordExists($nid) {
|
86
|
return (bool) db_query("SELECT nid FROM {webform} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
|
87
|
}
|
88
|
}
|