WebformGeneralTestCase.test in Webform 7.4
File
tests/WebformGeneralTestCase.test
View source
<?php
class WebformGeneralTestCase extends WebformTestCase {
public static function getInfo() {
return array(
'name' => t('Webform'),
'description' => t('Checks global Webform settings and content types.'),
'group' => t('Webform'),
);
}
public function testWebformCreate() {
$settings = array(
'title' => 'Test webform, no components',
'type' => 'webform',
);
$node = $this
->drupalCreateNode($settings);
$this
->assertTrue($this
->webformRecordExists($node->nid), t('Webform record made in the database for the new webform node.'));
$node->title .= '!';
node_save($node);
$this
->assertTrue($this
->webformRecordExists($node->nid), t('Webform record still in the database after modifying webform node.'));
}
public function testWebformCreateNewType() {
variable_set('webform_node_webform', TRUE);
variable_set('webform_node_page', TRUE);
$settings = array(
'title' => 'Test webform-enabled page',
'type' => 'page',
);
$node = $this
->drupalCreateNode($settings);
$this
->assertFalse($this
->webformRecordExists($node->nid), t('Webform record not in the database for the new page node.'));
$node->title .= '!';
node_save($node);
$this
->assertFalse($this
->webformRecordExists($node->nid), t('Webform record still not in the database after modifying page node.'));
$components = $this
->webformComponents();
$textarea = $components['textarea'];
$textarea['type'] = 'textarea';
$textarea['form_key'] = 'textarea';
$textarea['cid'] = 1;
$textarea['pid'] = 0;
$textarea = array_merge(webform_component_invoke('textarea', 'defaults'), $textarea);
$node->webform['components'][1] = $textarea;
node_save($node);
$this
->assertTrue($this
->webformRecordExists($node->nid), t('Webform record now exists after adding a new component.'));
$node->webform['components'] = array();
node_save($node);
$this
->assertFalse($this
->webformRecordExists($node->nid), t('Webform record deleted after deleting last component.'));
}
public function webformRecordExists($nid) {
return (bool) db_query("SELECT nid FROM {webform} WHERE nid = :nid", array(
':nid' => $nid,
))
->fetchField();
}
}