Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
links example
$crawler
=
$this
->
createCrawler
(
)
;
$crawler
->
addHtmlContent
(
$this
->
getDoctype
(
)
.'<html><div class="foo">Tiếng Việt</html>', 'UTF-8'
)
;
$this
->
assertEquals
(
'Tiếng Việt',
$crawler
->
filterXPath
(
'//div'
)
->
text
(
)
)
;
}
public
function
testAddHtmlContentInvalidBaseTag
(
)
{
$crawler
=
$this
->
createCrawler
(
null, 'http://symfony.com'
)
;
$crawler
->
addHtmlContent
(
$this
->
getDoctype
(
)
.'<html><head><base target="_top"></head><a href="/contact"></a></html>', 'UTF-8'
)
;
$this
->
assertEquals
(
'http://symfony.com/contact',
current
(
$crawler
->
filterXPath
(
'//a'
)
->
links
(
)
)
->
getUri
(
)
, '->addHtmlContent() correctly handles a non-existent base tag href attribute'
)
;
}
/** * @requires extension mbstring */
public
function
testAddHtmlContentCharsetGbk
(
)
{
$crawler
=
$this
->
createCrawler
(
)
;
// gbk encode of <html><p>中文</p></html>
$crawler
->
addHtmlContent
(
$this
->
getDoctype
(
)
.
base64_decode
(
'PGh0bWw+PHA+1tDOxDwvcD48L2h0bWw+'
)
, 'gbk'
)
;
$form
[
'_password'
]
= 'test';
$client
->
submit
(
$form
)
;
$this
->
assertRedirect
(
$client
->
getResponse
(
)
, '/profile'
)
;
$crawler
=
$client
->
followRedirect
(
)
;
$text
=
$crawler
->
text
(
null, true
)
;
$this
->
assertStringContainsString
(
'Hello johannes!',
$text
)
;
$this
->
assertStringContainsString
(
'You\'re browsing to path "/profile".',
$text
)
;
$logoutLinks
=
$crawler
->
selectLink
(
'Log out'
)
->
links
(
)
;
$this
->
assertCount
(
6,
$logoutLinks
)
;
$this
->
assertSame
(
$logoutLinks
[
0
]
->
getUri
(
)
,
$logoutLinks
[
1
]
->
getUri
(
)
)
;
$this
->
assertSame
(
$logoutLinks
[
2
]
->
getUri
(
)
,
$logoutLinks
[
3
]
->
getUri
(
)
)
;
$this
->
assertSame
(
$logoutLinks
[
4
]
->
getUri
(
)
,
$logoutLinks
[
5
]
->
getUri
(
)
)
;
$this
->
assertNotSame
(
$logoutLinks
[
0
]
->
getUri
(
)
,
$logoutLinks
[
2
]
->
getUri
(
)
)
;
$this
->
assertNotSame
(
$logoutLinks
[
1
]
->
getUri
(
)
,
$logoutLinks
[
3
]
->
getUri
(
)
)
;
$this
->
assertSame
(
$logoutLinks
[
0
]
->
getUri
(
)
,
$logoutLinks
[
4
]
->
getUri
(
)
)
;
$this
->
assertSame
(
$logoutLinks
[
1
]
->
getUri
(
)
,
$logoutLinks
[
5
]
->
getUri
(
)
)
;
}
<?=
$pager
->
getFirst
(
)
?>" aria-label="<?=
lang
(
'Pager.first'
)
?>"> <span aria-hidden="true"><?=
lang
(
'Pager.first'
)
?></span> </a> </li> <li> <a href="<?=
$pager
->
getPrevious
(
)
?>" aria-label="<?=
lang
(
'Pager.previous'
)
?>"> <span aria-hidden="true"><?=
lang
(
'Pager.previous'
)
?></span> </a> </li> <?php
endif
?> <?php
foreach
(
$pager
->
links
(
)
as
$link
)
: ?> <li <?=
$link
[
'active'
]
? 'class="active"' : '' ?>> <a href="<?=
$link
[
'uri'
]
?>"> <?=
$link
[
'title'
]
?> </a> </li> <?php
endforeach
?> <?php
if
(
$pager
->
hasNext
(
)
)
: ?> <li> <a href="<?=
$pager
->
getNext
(
)
?>" aria-label="<?=
lang
(
'Pager.next'
)
?>"> <span aria-hidden="true"><?=
lang
(
'Pager.next'
)
?></span> </a> </li> <li> <a href="
$form
[
'user_login[password]'
]
= 'test';
$client
->
submit
(
$form
)
;
$this
->
assertRedirect
(
$client
->
getResponse
(
)
, '/profile'
)
;
$crawler
=
$client
->
followRedirect
(
)
;
$text
=
$crawler
->
text
(
null, true
)
;
$this
->
assertStringContainsString
(
'Hello johannes!',
$text
)
;
$this
->
assertStringContainsString
(
'You\'re browsing to path "/profile".',
$text
)
;
$logoutLinks
=
$crawler
->
selectLink
(
'Log out'
)
->
links
(
)
;
$this
->
assertCount
(
2,
$logoutLinks
)
;
$this
->
assertStringContainsString
(
'_csrf_token=',
$logoutLinks
[
0
]
->
getUri
(
)
)
;
$client
->
click
(
$logoutLinks
[
0
]
)
;
$this
->
assertRedirect
(
$client
->
getResponse
(
)
, '/'
)
;
$this
->
callInRequestContext
(
$client
,
function
D
)
{
$this
->
assertFalse
(
static
::
getContainer
(
)
->
get
(
'security.csrf.token_storage'
)
->
hasToken
(
'foo'
)
)
;
}
)
;
}