0

I am trying to implement simple test for my custom module. But the test case always failing for user login. In the test script what I am trying to test is whether admin page is loading properly without any errors.

I am following similar code from core modules and other contributed modules. But couldn't figureout what I am missig in mine. My test script is given below:

<?php

/**
 * @file
 * Test file for custom_module module.
 */

/**
 * Default test case for the custom_module module.
 *
 * @ingroup custom_module
 */
class MyCustomModule extends DrupalWebTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'My Custom Module Test Case',
      'description' => 'Functional test for My Custom Module Module',
      'group' => 'My Custom Module',
    );
  }

  /**
   * {@inheritdoc}
   */
  function setUp() {
    parent::setUp('custom_module');

    $permissions = array(
      'access administration pages',
      'administer custom module',
    );
    $this->admin_user = $this->drupalCreateUser($permissions);
    $this->drupalLogin($this->admin_user);
  }

  /**
   * Test site working properly after installs the module.
   */
  function testCustomModulePageLoads() {
    $paths = array(
      '/admin/config/custom_module/manage',
    );
    foreach($paths as $path) {
      $this->drupalGet($path);
      $this->assertResponse(200, '200 response for the path ' . $path);
    }
  }

}

Result: enter image description here

5
  • The user probably needs the 'access administration pages' permission as well
    – Clive
    Mar 27 '17 at 12:19
  • Thanks @Clive, I updated my code. But no difference, getting same result.
    – ARUN
    Mar 27 '17 at 12:25
  • Sorry, my answer was for D8.
    – Kevin
    Mar 27 '17 at 13:56
  • Could you provide the first Verbose message in that list? And also, are the code lines reported in the screenshot in sync with the code you provided? How much memory do you have assigned to your Drupal? And what does the error log shows for the "Parsed page successfully" failure? Apr 10 '17 at 12:34
  • Are you using an install profile on the site in which you are running the tests?
    – nvahalik
    Apr 11 '17 at 22:48
0

Try calling $this->setUp(); from the testCustomPageLoads() function.

1
  • I tried.. still not working.
    – ARUN
    Apr 13 '17 at 3:20
0

With the info given here, it's essentially impossible to say what's wrong.

The code you have provided and test results doesn't match. It says user creation happens on line 36 and user login happens on line 43/44 but this not what the code says.

Also it's worth noting that you are getting 500 response (internal server error) and invalid HTML meaning something fundamentally is failing in your tests. It's not possible to say what it causing this, could be any kind of coding error on your part.

If the module works in non test scenario, most likely you have unmet dependencies, like some module/theme not being enabled which is causing errors and trouble.

Looking at the debug messages and DrupalWebTestCase::parse would be a good place to start debugging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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