Skip to content

Fix crawler not being updated when manually following redirect #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Codeception/Lib/InnerBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,9 @@ public function startFollowingRedirects(): void
*/
public function followRedirect(): void
{
$this->client->followRedirect();
$this->crawler = $this->client->followRedirect();
$this->baseUrl = $this->retrieveBaseUrl();
$this->forms = [];
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/data/app/view/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</div>

<a href="/info" title="Link Title">Link Text</a>
<a href="/redirect">Test redirect</a>


A wise man said: "debug!"
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/Codeception/Module/TestsForWeb.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Codeception\Test\Unit;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\ExpectationFailedException;
use Symfony\Component\BrowserKit\Response;

/**
* Author: davert
Expand Down Expand Up @@ -1866,4 +1867,26 @@ public function testUncheckHidden()
$this->assertFalse(isset($form['butter']));

}

public function testManualRedirect()
{
$this->module->amOnPage('/info');
$this->module->see('Information', 'h1');

$this->module->stopFollowingRedirects();
$this->module->amOnPage('/');
$this->module->seeResponseCodeIsBetween(200, 299);
$this->module->see('Welcome to test app!', 'h1');

// Workaround https://github.com/Codeception/util-universalframework/issues/3
$this->module->client->mockResponse(new Response('', 301, [
'Location' => '/info',
]));

$this->module->click('Test redirect');
$this->module->seeResponseCodeIs(301);
$this->module->followRedirect();
$this->module->seeCurrentUrlEquals('/info');
$this->module->see('Information', 'h1');
}
}