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
Comment | File | Size | Author |
---|---|---|---|
drupalPostForm-error.png | 120.25 KB | mccrodp | |
green-light-500-error.png | 374.2 KB | mccrodp |
Comments
Comment #2
mccrodp CreditAttribution: mccrodp at X-Team commentedCorrecting to be filed against release: 8.0.3.
Comment #5
quietone CreditAttribution: quietone as a volunteer commentedTriaging 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.
Comment #9
larowlandrupalPostForm has been removed, use submitForm now