Hey all,
Im having trouble setting up simpletest for testing one of my custom CCK content types. At the moment my Setup function is like this:
public function setUp() {
$args = func_get_args();
$modules = array_merge(array('content', 'content copy', 'content permissions', 'option widgets', 'text', 'node reference' , 'user reference', 'schema'), $args);
call_user_func_array(array('parent','setUp'), $modules);
// Create and log in our user
$permissions = array(
'access content',
'administer content types',
'administer nodes',
'administer filters',
);
$privileged_user = $this->drupalCreateUser($permissions);
$this->drupalLogin($privileged_user);
$project = 'project';
$project_name = 'Project';
$edit = array(
'type' => $project,
'name' => $project_name,
'body_label' => 'Project Description',
'description' => 'PwnBug Project'
);
$this->drupalPost('admin/content/types/add', $edit, 'Save content type');
$admin_project_url = 'admin/content/node-type/'. $project;
// Setting up the projectmanager field!
$projectmanager = array(
'_add_new_field[label]' => 'testfield',
'_add_new_field[weight]' => '-99',
'_add_new_field[field_name]' => 'testfield',
//'_add_new_field[type]' => 'text',
//'_add_new_field[widget_type]' => 'text_textfield',
'_add_new_field[type]' => 'userreference',
'_add_new_field[widget_type]' => 'userreference_select',
);
$this->drupalPost($admin_project_url .'/fields', $projectmanager, 'Save');
}
Things all go bad when with the user reference field. When i use a text field (currently commented in the code) it works fine. All the modules required are added in the Setup function. The form it tries to POST on is the correct form. Ive debugged through CCK abit so im sure the names of the type and widget type are correct.
Ive tried to check the output with the outputScreenContents function as used in the Simpletest tutorial on http://drupal.org/node/395012. If just shows the form so thats not of much help either.
UPDATE: Ive also tried too add my own module to load in the setup. My own module programatically adds a CCK content type. This solution is suggested in topic: http://drupal.org/node/316260. However it seems like that install is not getting hit when i debug it :S
Im kinda stuck at the moment, any help on this matter will be greatly appreciated!
Cheers
Comments
Different approach, still no luck.... :S
Hey all,
Still struggling with the same issue....tried a different approach, adding my CCK content type with the import form (admin/content/types/import). My Simpletest Setup() function looks like this:
Still no luck...when i run my tests i get errors like:
Failed to set field type_name to (fail1)
Failed to set field macro to $content[type]....huge array (fail2)
Found the Import button (fail3)
Found the requested form fields at admin/content/types/import (fail 4)
It seems like somehow the form doesn't accept the data i feed it... again any on this matter will be greatly appreciated!
UPDATE: ive used the simpletest automater to simulate what i want to do. I've copied the exact code which it produced...which worked when i clicked through the test and still....the test fails with the same four fails as described above...i honestly don't get how it is possible to that the simulated tests works and when it with the same code it fails :S
There must be some way to get simpletest working with custom CCK types....anywone willing to share how they did it..?? It would make me a happy camper!
UPDATE: I have put this matter up for discussion in the Drupal Groups, check it out for more info: http://groups.drupal.org/node/26251
Cheers!
Working example
this took two days to get right. this procedure assumes you have this http://drupal.org/files/issues/297972_drupal_execute_batch_api.patch installed in your forms.inc. otherwise the drupal_execute function will not work for form submission using the content_copy module.
most of my errors were from incorrect setup. to help diagnose i put the following code in my setUp right after the modules:
where outputAdminPage was defined in the class as:
this gives you the ability to literally "see" what's going on in the simpletest drupal instance.
the core challenge with getting a cck installed is that its using drupal_execute and a form submission which is instrumented to report form errors, not watchdog errors, and since the forms are being submitted via code, you never see any failures, just downstream damage.
the first step was to export my custom cck content type to a file and save it in a new cck folder under my module folder.
then i created the following mymodule.install file:
in addition, i modified the content_copy_import_form_submit function within the content_copy module of cck to use watchdog on errors:
and here is the mymodule.test file. to get the exact field names for adding the fake instance of my content type, e.g. whether they have [0] or [value] or [nid] etc. i viewed the html source on the node/add/mytype page and looked at the name attribute of the html field.