protected function LocationTestCase::drupalCreateNodeViaForm in Location 7.3
Same name and namespace in other branches
- 6.3 tests/location_testcase.php \LocationTestCase::drupalCreateNodeViaForm()
- 7.5 tests/location_testcase.php \LocationTestCase::drupalCreateNodeViaForm()
- 7.4 tests/location_testcase.php \LocationTestCase::drupalCreateNodeViaForm()
Creates a node based on default settings. This uses the internal simpletest browser, meaning the node will be owned by the current simpletest _browser user.
Code modified from #212304. This is mainly for testing for differences between node_save() and submitting a node/add/* form.
Parameters
values: An associative array of values to change from the defaults, keys are node properties, for example 'body' => 'Hello, world!'.
Return value
object Created node object.
File
- tests/
location_testcase.test, line 151 - Common functions for Location tests.
Class
- LocationTestCase
- Class LocationTestCase.
Code
protected function drupalCreateNodeViaForm($values = array()) {
$defaults = array(
'type' => 'page',
'title' => $this
->randomName(8),
);
$edit = $values + $defaults;
if (empty($edit['body'])) {
$content_type = db_fetch_array(db_query("select name, has_body from {node_type} where type='%s'", $edit['type']));
if ($content_type['has_body']) {
$edit['body'] = $this
->randomName(32);
}
}
$type = $edit['type'];
// Only used in URL.
unset($edit['type']);
$this
->flattenPostData($edit);
$this
->drupalPost('node/add/' . str_replace('_', '-', $type), $edit, t('Save'));
$node = node_load(array(
'title' => $edit['title'],
));
$this
->assertRaw(t('@type %title has been created.', array(
'@type' => node_get_types('name', $node),
'%title' => $edit['title'],
)), t('Node created successfully.'));
return $node;
}