Skip to content
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

PhpBrowser does not honouring <base href=""> meta tag #3764

Closed
hubbyist opened this issue Nov 22, 2016 · 8 comments
Closed

PhpBrowser does not honouring <base href=""> meta tag #3764

hubbyist opened this issue Nov 22, 2016 · 8 comments

Comments

@hubbyist
Copy link

@hubbyist hubbyist commented Nov 22, 2016

What are you trying to achieve?

By using PhpBrowser trying to click an anchor link.
page url is in 'http://example.com/sitefolder/folder/service/panel' format.
page is containing <base href="http://example.com/sitefolder/folder/"/> tag.
anchor href attribute is "service/action".
after click operation current URL must be 'http://example.com/sitefolder/folder/service/action.

What do you get instead?

current URL becomes 'http://example.com/sitefolder/folder/service/service/action' as if there is no <base href=""> meta tag in the page. From a normal browser link is working.

Provide test source code if related

    $I->amOnPage('/service/panel');
    $I->seeLink('Action', 'service/action');
    $I->click(['link' => 'Action']);
    $I->seeCurrentUrlEquals('http://example.com/sitefolder/folder/service/action');

Details

  • Codeception version: Codeception version 2.2.6
  • PHP Version: PHP 7.0.8-0ubuntu0.16.04.3
  • Operating System: linux mint 18.0
  • Installation type: Phar
  • List of installed packages (composer show) : none
  • Suite configuration:
class_name: AcceptanceTester
modules:
    enabled:
        - Asserts
        - PhpBrowser:
            url: http://example.com/sitefolder/folder
        - \Module\RESTAPI:
            depends: PhpBrowser
        - Db:
            dsn: 'pgsql:host=localhost;dbname=dbname'
            user: 'username'
            password: 'password'
            dump: dump.sql
            populate: true
            cleanup: false
            reconnect: false
@hubbyist
Copy link
Author

@hubbyist hubbyist commented Nov 23, 2016

It seems modifying click() function from InnerBrowser class, within a Module which extends \Codeception\Module\REST is nearly impossible due to lots of missing function errors caused by deep rooted dependency tree. No luck with getAbsoluteUrlFor() function either.

I have to clone whole InnerBrowser class into my custom module to fix this issue without modifying codeception itself I think. Any suggestions?

@hubbyist
Copy link
Author

@hubbyist hubbyist commented Nov 23, 2016

Only related change since november 2015 seems to be:

function getAbsoluteUrlFor($uri)
    ....
---    if (empty($uri) || $uri === '#') 
+++    if (empty($uri) || $uri[0] === '#')
@hubbyist
Copy link
Author

@hubbyist hubbyist commented Nov 23, 2016

By comparing 2.1.5 with 2.2.6 I found that anchor link processing code of click() function in InnerBrowser
class seem to be moved to openHrefFromDomNode() function.

v2.1.5 :

public function click($link, $context = null)
{
	....
	if (count($anchor)) {
		$this->crawler = $this->clientClick($anchor->first()->link());
		$this->forms = [];
		return;
	}
	...
}

v2.2.6:

public function click($link, $context = null)
{
	....
	if (count($anchor)) {
		$this->openHrefFromDomNode($anchor->getNode(0));
		return;
	}
	...
}

private function openHrefFromDomNode(\DOMNode $node)
{
	$this->amOnPage($this->getAbsoluteUrlFor($node->getAttribute('href')));
}

Does these two code block doing exactly the same thing?

@hubbyist
Copy link
Author

@hubbyist hubbyist commented Nov 23, 2016

What is the source of Link class in clientClick function?

	protected function clientClick(Link $link)
	{
		...
		return $this->clientRequest($link->getMethod(), $link->getUri());
	}

It seems to have getUri() function of its own. May it be using the baseHref value from Crawler somehow?

@Naktibalda
Copy link
Member

@Naktibalda Naktibalda commented Nov 24, 2016

It is Symfony\Component\DomCrawler\Link.

Don't try to clone InnerBrowser, fix it instead.
Please add some tests for base href to https://github.com/Codeception/Codeception/blob/2.2/tests/unit/Codeception/Module/TestsForWeb.php
HTML goes to: https://github.com/Codeception/Codeception/tree/2.2/tests/data/app/view

Or I can try to fix it this weekend.

@hubbyist
Copy link
Author

@hubbyist hubbyist commented Nov 24, 2016

Are these sufficient for testing?
hubbyist@b973637

And how can I directly trigger TestsForWeb.php or related group. I couldn't find the group definition for these tests?

@Naktibalda
Copy link
Member

@Naktibalda Naktibalda commented Nov 25, 2016

Your tests look good.
Run them with php codecept run tests/unit/Codeception/Module/PhpBrowserTest.php:Base

Naktibalda added a commit to Naktibalda/Codeception that referenced this issue Nov 26, 2016
@hubbyist
Copy link
Author

@hubbyist hubbyist commented Nov 28, 2016

I have done work on the subject at hubbyist@812f0a3 in paralel. So if any portion of my work is usefull I can make a seperate PR of them.

Naktibalda added a commit to Naktibalda/Codeception that referenced this issue Nov 29, 2016
DavertMik added a commit that referenced this issue Nov 30, 2016
* [PhpBrowser][Frameworks] Honour base tag

Fixes #3764

* Bumped minimum version of DomCrawler to 2.7.5 because it doesn't honour base tag in lower versions
chris1312 pushed a commit to chris1312/Codeception that referenced this issue Jun 16, 2017
* [PhpBrowser][Frameworks] Honour base tag

Fixes Codeception#3764

* Bumped minimum version of DomCrawler to 2.7.5 because it doesn't honour base tag in lower versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.