I have used Drupal 9 version and PHPUnit 9.5.26 version, i have tried to test one of the PHPunit test class with drupalLogin() method.
I tried to check in my virtualhost with port. While trying to access drupalLogin() with specific url using drupalGet('user/login'), i got 403 Forbidden issue.
But the page is working in my browser very well and i can able to acces hostname:port/user/login without any issue.
The only problem is using to run phpunit test with my test file having this problem.
I have set up with Drupal7 for another local portal, and seems that is working if i change the base url for the below code base.
I tried with both $client->request and drupalGet('http://:
/user/login/'), and both side response was "403 Forbidden"
$client = \Drupal::httpClient();
$url = 'http://:
/user/login/';
$request = $client->request('GET', $url, $options);
My respones is below:
< HTTP/1.1 403 Forbidden
< Date: Thu, 05 Jan 2023 11:24:29 GMT
< Server: Apache/2.4.53 (Unix) PHP/7.4.28
< X-Content-Type-Options: nosniff
< X-Powered-By: PHP/7.4.28
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
Client error: `GET http://:
/user/login/` resulted in a `403 Forbidden` response
Can anyone suggest me if any configuration/settings is required to work with "user/login" page.
Comments
Comment #2
xjmComment #3
lendudeYou say
Does that mean that other tests, that are not your own do work? If you run a test from Drupal core (most of them should log in a user at some point) do those work? If the core tests don't work, it is certainly something in your setup that is the problem, since those should always be passing.
Are you following the steps in https://www.drupal.org/node/2116263 ? If those steps don't work I would suggest asking in the #support or #testing channel on Drupal Slack for specific advise, you will have more chance of getting a working setup.
Comment #4
mathisomu commentedHi,
Thanks for your reply, i have followed all the steps which you have mentioned here(https://www.drupal.org/node/2116263) and i can ran some of the testcases which passes successfully.
The problem is one of the test case i have used to check with drupalLogin() method, which checking my local user portal url, and throws 403 Forbidden and the same url is working fine when i ran in to the browser.
The page could be /user/login. Seems this page doesn't require any user credentials to access, so i don't know why its throwing like that.
I have share the output response for your response for the same.
/lib/apps/share/php/bin/php target/dist/share/drupal/vendor/bin/phpunit -c target/dist/share/www_root/core/phpunit.xml /workspace/drupal_modules//core/testmodule/tests/src/Functional/RequestsTest.php
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.
Warning: Your XML configuration validates against a deprecated schema.
Suggestion: Migrate your XML configuration using "--migrate-configuration"!
Testing Drupal\Tests\testmodule\Functional\RequestsTest
E 1 / 1 (100%)* Found bundle for host mylocalportal:4050: 0x22d4950
* Re-using existing connection! (#0) with host mylocalportal
* Connected to mylocalportal (10.xx7.xx1.xx2) port 4050 (#0)
> GET /user/login/ HTTP/1.1
Host: mylocalportal:4050
Content-Type: text/html
User-Agent: simpletest90992221:1672917869:63b6b36d752d39.35976327:Rpu7x0ccqarbEfmMbcuorD-uxfu2_xtFtHItUjZIfiI
< HTTP/1.1 403 Forbidden
< Date: Thu, 05 Jan 2023 11:24:29 GMT
< Server: Apache/2.4.53 (Unix) PHP/7.4.28
< X-Content-Type-Options: nosniff
< X-Powered-By: PHP/7.4.28
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
<
* Connection #0 to host mylocalportal left intact
Time: 00:14.589, Memory: 22.00 MB
There was 1 error:
1) Drupal\Tests\testmodule\Functional\RequestsTest::testExternalRequestPermissions
GuzzleHttp\Exception\ClientException: Client error: `GET mylocalportal:4050/user/login/` resulted in a `403 Forbidden` response
But, i have another setup local user portal which is D7(mylocalportal:2000), and i can able to access mylocalportal:2000/user/login in D9 code base.
Please let me know if you have any more information required from my end.
Thanks