0

I have written an automated test to create a node of a specific content type.

Here is the code:

class GlueTestingBuySystemTestCase extends DrupalWebTestCase {

  protected $privileged_user;

  public static function getInfo() {
    return array(
      'name' => 'Buying system',
      'description' => 'Buying system test',
      'group' => 'GLUE',
    );
  }

  public function setUp() {
    $this->profile = 'testing';
    // Enable any modules required for the test. This should be an array of
    // module names.
    parent::setUp(array('glue_testing'));

    // Create and log in our privileged user.
    $this->privileged_user = $this->drupalCreateUser(array(
      'administer nodes',
      ));
    $this->drupalLogin($this->privileged_user);
  }

  public function testBuyingSystem() {
    $edit = array();
    $edit['title'] = $this->randomName(8);
    $this->drupalPost('node/add/test', $edit, t('Save'));
    $this->assertText(t('Test Node Type @title has been created.', array('@title' => $edit['title'])));
  }

}

It does appear in the group "GLUE" but when I run the test it gives me the errors:

Failed to set field title to lLzjWnd0
Found the Save button
Found the requested form fields at node/add/test
"Testing Node Type lLzjWnd0 has been created." found

And does not create any node nor created the user. Any one who have idea that what is wrong in my code?

1 Answer 1

0

afaik there's any content-type in the testing site. You need to create it first. For example date module creates one in DateFieldBasic::setUp (surely there're more examples in core, but I've got that one at hand).

2
  • $this->profile="testing". It means the simpletest will use a testing site? If yes then how will I enforce my test case to use my current site?
    – Ahmad
    Commented Jun 27, 2014 at 8:12
  • I've never used $this->profile. Not sure if this means anything. You can't use your current site for testing. Simpletest installs testing site isolated from your current site. See documentation: drupal.org/node/394888
    – jonhattan
    Commented Jun 27, 2014 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.