Problem/Motivation

I am getting a 500 internal server error response but a green light in my tests when running MessageuiPermission:testMessageUiPermissions =>

php core/scripts/run-tests.sh --browser --url "http://test.drupal-8.0.3.ie" --class "Drupal\message_ui\Tests\MessageUiPermissions"

D8 version of Message UI module found at: https://github.com/mccrodp/message_ui/tree/8.x-1.x

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

    $this->account = $this->drupalCreateUser();

    // Load 'authenticated' user role.
    $this->rid = Role::load(RoleInterface::AUTHENTICATED_ID)->id();

    // Create Message type foo.
    $this->createMessageType('foo', 'Dummy test', 'Example text.', array('Dummy message'));
  }

  /**
   * Test message_access use case.
   */
  function testMessageUiPermissions() {
    $this->drupalLogin($this->account); // User login.
    $create_url = 'admin/content/messages/create/foo'; // Set our create url.

    // Verify the user can't create the message.
    $this->drupalGet($create_url);
    $this->assertResponse(403, t("The user can't create a message."));

    // Grant and check create permissions for a message.
    $this->grantMessageUiPermission('create');
    $this->drupalGet($create_url);

    // If we get a valid response, create a message.
    if ($this->assertResponse(200, t("The user can create a message."))) {
      // Create a message at current page / url.
      $this->drupalPostForm($create_url, array(), t('Save'));
    }
}

When drupalPostForm is called I would either expect to be able to assert to a particular response 200, 404, etc., or to only get a green light on a 200, 201, 202 or successful response code. As you can see in the attached screengrab (green-light-500-error.png) I get a green light on a 500 error (drupalPostForm-error.png).

Proposed resolution

For the case this is working as designed:
Unless I am missing something, possible improvement to documentation of drupalPostForm at https://api.drupal.org/api/drupal/core%21modules%21simpletest%21src%21We...

If it is erroneous, contribute code to help fix the issue.

I am unsure why / how the code in drupalPostForm calculates $submit_matches before getting the http result code from curlExec method. i.e. in my test $submit_matches = TRUE, then curlExec gets an error 500 code. Then the following code executes and gives a green light:

// We have not found a form which contained all fields of $edit.
      foreach ($edit as $name => $value) {
        $this->fail(SafeMarkup::format('Failed to set field @name to @value', array('@name' => $name, '@value' => $value)));
      }
      if (!$ajax && isset($submit)) {
        $this->assertTrue($submit_matches, format_string('Found the @submit button', array('@submit' => $submit)));
      }
      $this->fail(format_string('Found the requested form fields at @path', array('@path' => ($path instanceof Url) ? $path->toString() : $path)));

Remaining tasks

As above

User interface changes

N/A

API changes

N/A

Data model changes

N/A

CommentFileSizeAuthor
drupalPostForm-error.png120.25 KBmccrodp
green-light-500-error.png374.2 KBmccrodp
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mccrodp created an issue. See original summary.

mccrodp’s picture

Version: 8.1.x-dev » 8.0.3

Correcting to be filed against release: 8.0.3.

Version: 8.0.3 » 8.0.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.0.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Component: simpletest.module » phpunit

Triaging issues in simpletest.module as part of the Bug Smash Initiative to determine if they should be in the Simpletest Project or core.

This looks like it a Phpunit issue, changing component.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Status: Active » Closed (outdated)
Issue tags: +Bug Smash Initiative

drupalPostForm has been removed, use submitForm now