Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
addAttributeMatching example
$translator
->
registerExtension
(
new
HtmlExtension
(
$translator
)
)
;
$xpath
=
new
XPathExpr
(
)
;
$translator
->
addPseudoClass
(
$xpath
, 'fake'
)
;
}
public
function
testAddAttributeMatchingClassNotExistsClass
(
)
{
$this
->
expectException
(
ExpressionErrorException::
class
)
;
$translator
=
new
Translator
(
)
;
$translator
->
registerExtension
(
new
HtmlExtension
(
$translator
)
)
;
$xpath
=
new
XPathExpr
(
)
;
$translator
->
addAttributeMatching
(
$xpath
, '', '', ''
)
;
}
/** @dataProvider getXmlLangTestData */
public
function
testXmlLang
(
$css
, array
$elementsId
)
{
$translator
=
new
Translator
(
)
;
$document
=
new
\
SimpleXMLElement
(
file_get_contents
(
__DIR__.'/Fixtures/lang.xml'
)
)
;
$elements
=
$document
->
xpath
(
$translator
->
cssToXPath
(
$css
)
)
;
$this
->
assertCount
(
\
count
(
$elementsId
)
,
$elements
)
;
foreach
(
$elements
as
$element
)
{
$this
->
assertContains
(
(string)
$element
->
attributes
(
)
->id,
$elementsId
)
;
}
$safe
=
$safe
&&
$this
->
isSafeName
(
$node
->
getNamespace
(
)
)
;
}
$attribute
=
$safe
? '@'.
$name
:
sprintf
(
'attribute::*[name() = %s]', Translator::
getXpathLiteral
(
$name
)
)
;
$value
=
$node
->
getValue
(
)
;
$xpath
=
$translator
->
nodeToXPath
(
$node
->
getSelector
(
)
)
;
if
(
$this
->
hasFlag
(
self::ATTRIBUTE_VALUE_IN_LOWER_CASE
)
)
{
$value
=
strtolower
(
$value
)
;
}
return
$translator
->
addAttributeMatching
(
$xpath
,
$node
->
getOperator
(
)
,
$attribute
,
$value
)
;
}
public
function
translateClass
(
Node\ClassNode
$node
, Translator
$translator
)
: XPathExpr
{
$xpath
=
$translator
->
nodeToXPath
(
$node
->
getSelector
(
)
)
;
return
$translator
->
addAttributeMatching
(
$xpath
, '~=', '@class',
$node
->
getName
(
)
)
;
}
public
function
translateHash
(
Node\HashNode
$node
, Translator
$translator
)
: XPathExpr
{