View source
<?php
class ModuleBuilderTest extends DrupalTestCase {
function get_info() {
return array(
'name' => t('Test creating a module'),
'desc' => t('Creates a module using the module builder'),
'group' => 'Module Builder',
);
}
function testModuleBuilderModule() {
$account = $this
->drupalCreateUserRolePerm(array(
'build modules',
));
$this
->drupalLoginUser($account);
$edit = array(
'title' => $this
->randomName(10, ''),
'description' => $this
->randomName(255, ''),
);
$edit['machine'] = strtolower($edit['title']);
$this
->drupalPostRequest(url("admin/build/module_builder/new", array(
'absolute' => TRUE,
)), array(
'title' => $edit['title'],
), t('Submit'));
$url = explode('/', $this->_browser->_history
->getUrl()->_path);
unset($url[0]);
unset($url[1]);
$title = $edit['title'];
unset($edit['title']);
$this
->drupalPostRequest(implode('/', $url), $edit, t('Submit'));
$mid = db_result(db_query("SELECT mid FROM {module_builder_basic} WHERE name = '%s'", $title));
$this
->clickLink(t('Menu'));
$_menu_edit = array(
array(
'title' => $this
->randomName(10, ''),
'path' => $this
->randomName(10, '') . '/' . $this
->randomName(10, ''),
'type' => array_rand(drupal_map_assoc(array(
'Normal',
'Tab',
'Default tab',
'Callback',
'Suggested item',
))),
'callback' => $this
->randomName(10, ''),
),
array(
'title' => $this
->randomName(10, ''),
'path' => $this
->randomName(10, '') . '/' . $this
->randomName(10, ''),
'type' => array_rand(drupal_map_assoc(array(
'Normal',
'Tab',
'Default tab',
'Callback',
'Suggested item',
))),
'callback' => $this
->randomName(10, ''),
),
);
$menu_edit = array();
foreach ($_menu_edit[0] as $name => $item) {
$menu_edit['items[0][' . $name . ']'] = $item;
}
$url = explode('/', $this->_browser->_history
->getUrl()->_path);
unset($url[0]);
unset($url[1]);
$this
->drupalPostRequest(implode('/', $url), $menu_edit, t('Submit'));
foreach ($_menu_edit[1] as $name => $item) {
$menu_edit['items[1][' . $name . ']'] = $item;
}
$this
->drupalPostRequest(implode('/', $url), $menu_edit, t('Submit'));
$this
->drupalPostRequest('admin/build/module_builder/edit/' . $mid . '/delete', array(), t('Confirm'));
}
}