public function CCKSelectOtherTest::setUp in CCK Select Other 6
Same name and namespace in other branches
- 7.2 tests/cck_select_other.test \CCKSelectOtherTest::setUp()
- 7 tests/cck_select_other.test \CCKSelectOtherTest::setUp()
Implementation of setUp() method
Overrides DrupalWebTestCase::setUp
File
- tests/
cck_select_other.test, line 82 - test file for cck_select_other Testing file
Class
- CCKSelectOtherTest
- SimpleTest class for cck_select_other
Code
public function setUp() {
parent::setUp('content', 'text', 'optionwidgets', 'cck_select_other');
// We need to include CCK's CRUD and Admin include files ourselves.
module_load_include('inc', 'content', 'includes/content.crud');
module_load_include('inc', 'content', 'includes/content.admin');
// Create a content admin user
$this->admin_user = $this
->drupalCreateUser(array(
'create page content',
'edit own page content',
'delete own page content',
'administer content types',
'access content',
));
// Login as our admin user for the duration of the test.
$this
->drupalLogin($this->admin_user);
// Create our field instance
$this->test_field = $this->new_field;
// Copy over our new field to test field
for ($i = 0; $i < 4; $i++) {
$this->test_field['widget']['select_list_options'] .= $this
->randomName(4);
if ($i < 3) {
$this->test_field['widget']['select_list_options'] .= "\n";
}
}
$this->options = $this->test_field['widget']['select_list_options'];
module_invoke_all('content_fieldapi', 'create instance', $this->test_field);
_content_field_write($this->test_field, 'create');
_content_field_instance_write($this->test_field, 'create');
content_alter_schema(array(), $this->test_field);
$this->test_field = content_fields($this->test_field['field_name'], 'page');
$this
->assertEqual($this->test_field['field_name'], $this->new_field['field_name'], t('Field name @first is equal to @second. Field saved successfully.', array(
'@first' => $this->test_field['field_name'],
'@second' => $this->new_field['field_name'],
)));
// Create our node
$options_arr = cck_select_other_options($this->test_field);
$option = array_rand($options_arr);
if ($option == 'other') {
$option = $this
->randomName(5);
}
$settings = array(
'type' => 'page',
);
$this->test_node = $this
->drupalCreateNode($settings);
}