Posted by Balth on December 15, 2010 at 8:23am
4 followers
Jump to:
| Project: | SimpleTest |
| Version: | 6.x-2.11 |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Issue Summary
Hi all,
I'm facing few problems using Simpletest module.
I can't fill cck fields in a page node type.
The question is "How to do it?"
I've check subject about that : http://groups.drupal.org/node/26251 but I've not found answer.
My code :
<?php
// $Id: simpletest_example.test,v 1.1.2.4 2010/05/07 01:47:53 rfay Exp $
/**
* Tests the SimpleTest Example module's content type.
*/
class SimpleTestPageTestCase extends DrupalWebTestCase {
protected $privileged_user;
public static function getInfo() {
return array(
'name' => 'SimpleTest Page',
'description' => 'Ensure that the page content type provided functions properly.',
'group' => 'SimpleTest',
);
}
public function setUp() {
parent::setUp(
'node',
'content',
'fieldgroup',
'optionwidget',
'text',
'number',
'date_api',
'date_timezone',
'date',
'date_popup',
'text');
// Create and log in our privileged user.
$this->privileged_user = $this->drupalCreateUser( array('create page content'));
$this->drupalLogin($this->privileged_user);
}
public function testPageCreate() {
// Create node to edit.
$edit = array (
'title' => 'Test Fonctionnement Automator N2',
'field_page_footnote[0][value]' => $this->randomName(350),
'language' => 'nl-BE',
'field_generic_date_autopub[0][value][date]' => '16/12/2010',
'field_generic_date_autopub[0][value][time]' => '08:22',
'field_generic_date_autounpub[0][value][date]' => '30/12/2010',
'field_generic_date_autounpub[0][value][time]' => '17:22',
);
$this->drupalPost('node/add/page', $edit, t('Save'));
$this->assertText(t('page @title has been created.', array('@title' => $edit['title'])));
}
}
?>Errors returned :
Failed to set field field_page_footnote[0][value] to s37572OTca2FK6WFzhFjjkHp8(...)
Failed to set field language to nl-BE
Failed to set field field_generic_date_autopub[0][value][date] to 16/12/2010
Failed to set field field_generic_date_autopub[0][value][time] to 08:22
Failed to set field field_generic_date_autounpub[0][value][date] to 30/12/2010
Failed to set field field_generic_date_autounpub[0][value][time] to 17:22Thanks in advance
Best regards.
Comments
#1
Hi,
First of all I would suggest having a look at the tests that are in the CCK module. You will find there a ContentOptionWidgetTest class that tests node add/edits.
From a first look at your code I think you don't have the right permissions for the fields you want to edit. In the CCK tests, to make things simple they create a user (see method
loginWithPermissions) with 'administer content types' and 'administer nodes' among other permissions.Hope this helps,
Andrei
#2
It also looks like your setUp() function just installs the modules but doesn't actually create any fields. SimpleTests start with a clean install.
#3
ah, yes, of course. Dave Reid is right: you need to add those CCK fields to the page content type in your test. My advice still applies though: have a look at the tests in the CCK module.
#4
Please I will like to know, what about fields that are not CCK fields? I mean fields that are added in template files and taken through drupalPost for editing? How do I initialize them within the test. I see test functions such as createFieldText, so I'm, wondering if I have to create the fields within the test?
Thanks