Updated: Comment #0
Problem/Motivation
This took a while to track down, and I'm actually extremely surprised that it hasn't been caught by testbot by now. However, it appears that drupalGet()/drupalPost() do not work at all without clean URLs working. Regardless of whether the page is being triggered from a clean url-using page or not, simpletest will always generate clean URLs for making requests back to itself. If clean URLs don't resolve, the result is always an Apache 404 (not even a Drupal 404).
I think it's best demonstrated by looking at the code. In WebTestBase's setup process is this:
protected function prepareRequestForGenerator($clean_urls = TRUE, $override_server_vars = array()) {
// ...
if ($clean_urls) {
$request_path = $base_path ? $base_path . '/user' : 'user';
}
else {
$request_path = $base_path ? $base_path . '/index.php/user' : '/index.php/user';
}
$server = array_merge($server, $override_server_vars);
$request = Request::create($request_path, 'GET', array(), array(), array(), $server);
$generator->setRequest($request);
return $request;
}
That method is called from a few places, but most notably for our purposes is WebTestBase::rebuildContainer():
protected function rebuildContainer() {
parent::rebuildContainer();
// Make sure the url generator has a request object, otherwise calls to
// $this->drupalGet() will fail.
$this->prepareRequestForGenerator();
}
That is, prepareRequestForGenerator() is called without a clean URL parameter, so it defaults to true even if it shouldn't. As a result, drupalGet() always then uses a clean URL.
There's another no-parameter call to prepareRequestForGenerator() in LanguageUrlRewritingTest::testUrlRewritingEdgeCases(). I don't know if that's appropriate or not. It looks like the other calls to that method always pass in a value.
Proposed resolution
I don't know; Kat said to assign it to her and she'll figure it out. :-)
Remaining tasks
Fix the bug.
User interface changes
None.
API changes
Should be none?
Comments
Comment #1
StuartJNCC CreditAttribution: StuartJNCC commentedSurely, a simple fix here is to make the default FALSE in function prepareRequestForGenerator. That way, if it is called with no parameters it will not attempt to use clean URLs - which should always work whether Clean URLs are on or not.
Comment #2
tim.plunkettI thought D8 required clean URLs?
Comment #3
Crell CreditAttribution: Crell commentedNo, D8 still works with unclean URLs. The format of unclean URLs changed to foo.com/index.php/node/5, however. But that is supposed to work at present.
Kat has indicated she has no core time anymore, so unassigning so someone else can look into it.
Comment #4
tim.plunkettHonestly, if you want to run simpletests, turn on clean urls.
Comment #5
Crell CreditAttribution: Crell commentedThat's not documented. The original reporter (not me, I was reporting it on her behalf) was confused and frustrated by this for weeks until we realized what the problem was. Frustrating new contributors for weeks is not good. :-)
Comment #14
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 #18
quietone CreditAttribution: quietone at PreviousNext commentedI asked about this issue in #bugsmash. Both acbramely and I think this is outdated.
However, instead of closing as outdated we agree we should check further.
Is this still valid?
Since we need more information to move forward with this issue, I am setting the status to Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #19
Mile23Moved to Simpletest contrib module.
Comment #20
Mile23@quietone points out that similar code still exists in FunctionalTestSetupTrait and thus BrowserTestBase.
Moving back to core project.
Comment #21
Mile23Comment #22
mondrakehttps://www.drupal.org/docs/troubleshooting-drupal/fix-drupal-clean-urls...
This is for archeocodologists, now.