Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5990511
AttributeMatcher.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
AttributeMatcher.php
View Options
<?php
namespace
WMDE\HamcrestHtml
;
use
DOMAttr
;
use
DOMElement
;
use
Hamcrest\Description
;
use
Hamcrest\Matcher
;
use
Hamcrest\Util
;
class
AttributeMatcher
extends
TagMatcher
{
/**
* @var Matcher
*/
private
$attributeNameMatcher
;
/**
* @var Matcher|null
*/
private
$valueMatcher
;
/**
* @param Matcher|string $attributeName
*
* @return self
*/
public
static
function
withAttribute
(
$attributeName
)
{
return
new
static
(
Util
::
wrapValueWithIsEqual
(
$attributeName
)
);
}
/**
* @param Matcher $attributeNameMatcher
*/
public
function
__construct
(
Matcher
$attributeNameMatcher
)
{
parent
::
__construct
();
$this
->
attributeNameMatcher
=
$attributeNameMatcher
;
}
/**
* @param Matcher|string $value
*
* @return AttributeMatcher
*/
public
function
havingValue
(
$value
)
{
// TODO: Throw exception if value is set
$result
=
clone
$this
;
$result
->
valueMatcher
=
Util
::
wrapValueWithIsEqual
(
$value
);
return
$result
;
}
public
function
describeTo
(
Description
$description
)
{
$description
->
appendText
(
'with attribute '
)
->
appendDescriptionOf
(
$this
->
attributeNameMatcher
);
if
(
$this
->
valueMatcher
)
{
$description
->
appendText
(
' having value '
)
->
appendDescriptionOf
(
$this
->
valueMatcher
);
}
}
/**
* @param DOMElement $item
* @param Description $mismatchDescription
*
* @return bool
*/
protected
function
matchesSafelyWithDiagnosticDescription
(
$item
,
Description
$mismatchDescription
)
{
/** @var DOMAttr $attribute */
foreach
(
$item
->
attributes
as
$attribute
)
{
if
(
$this
->
valueMatcher
)
{
if
(
$this
->
attributeNameMatcher
->
matches
(
$attribute
->
name
)
&&
$this
->
valueMatcher
->
matches
(
$attribute
->
value
)
)
{
return
true
;
}
}
elseif
(
$this
->
attributeNameMatcher
->
matches
(
$attribute
->
name
)
)
{
return
true
;
}
}
return
false
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Oct 4, 01:32 (3 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
1a/27/a9886314bfb718d1e98333975565
Default Alt Text
AttributeMatcher.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment