-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
315 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# perform LF normalization | ||
*.php text eol=lf | ||
*.js text eol=lf | ||
*.json text eol=lf | ||
*.md text eol=lf | ||
*.xml text eol=lf | ||
*.yml text eol=lf | ||
|
||
*.png binary | ||
|
||
/.code-climate.json export-ignore | ||
/.gitattributes export-ignore | ||
/.github export-ignore | ||
/.gitignore export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/tests export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: PHPUnit | ||
on: [push, pull_request] | ||
jobs: | ||
run: | ||
runs-on: ${{ matrix.operating-system }} | ||
strategy: | ||
matrix: | ||
# windows-latest, macOS-latest | ||
operating-system: [ubuntu-latest] | ||
php-version: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] | ||
name: PHP ${{ matrix.php-version }} Test on ${{ matrix.operating-system }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Install PHP | ||
uses: shivammathur/setup-php@v2 # https://github.com/marketplace/actions/setup-php-action | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
extensions: intl #optional | ||
ini-values: "post_max_size=256M, memory_limit=512M" | ||
coverage: xdebug #optional | ||
- name: Check PHP Version | ||
run: php -v | ||
- name: Validate composer.json and composer.lock | ||
run: composer validate --strict | ||
- name: Cache composer packages | ||
uses: actions/cache@v3 | ||
id: composer-cache | ||
with: | ||
path: vendor | ||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-php- | ||
- name: Install dependencies | ||
run: | | ||
composer --version | ||
composer install --prefer-dist --no-progress | ||
- name: Unit test | ||
run: composer run test | ||
- name: Publish code coverage | ||
uses: paambaati/[email protected] | ||
if: matrix.php-version == '8.2' && ${{ github.ref_name == 'master' }} | ||
continue-on-error: true | ||
env: | ||
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | ||
with: | ||
debug: false | ||
coverageCommand: vendor/bin/phpunit --coverage-clover coverage/clover.xml | ||
coverageLocations: coverage/clover.xml:clover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/.phpunit.result.cache | ||
/composer.lock | ||
/coverage | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
* @package CssXPath | ||
* @author Brad Kent <[email protected]> | ||
* @license http://opensource.org/licenses/MIT MIT | ||
* @copyright 2018 Brad Kent | ||
* @copyright 2018-2023 Brad Kent | ||
* @version 1.0 | ||
* | ||
* @link http://www.github.com/bkdotcom/CssXpath | ||
|
@@ -15,6 +15,10 @@ | |
namespace bdk\CssXpath; | ||
|
||
use bdk\CssXpath\CssXpath; | ||
use DOMDocument; | ||
use DOMElement; | ||
use DOMNodeList; | ||
use DOMXpath; | ||
|
||
/** | ||
* CSS selector class | ||
|
@@ -33,7 +37,6 @@ | |
*/ | ||
class CssSelect | ||
{ | ||
|
||
protected $domXpath; | ||
|
||
/** | ||
|
@@ -146,11 +149,11 @@ protected function selectNonStatic($selector, $asDomList = false) | |
/** | ||
* Convert DOMNodeList to an array. | ||
* | ||
* @param \DOMNodeList $elements elements | ||
* @param DOMNodeList $elements elements | ||
* | ||
* @return array | ||
*/ | ||
protected static function elementsToArray(\DOMNodeList $elements) | ||
protected static function elementsToArray(DOMNodeList $elements) | ||
{ | ||
$array = array(); | ||
for ($i = 0, $length = $elements->length; $i < $length; ++$i) { | ||
|
@@ -164,16 +167,16 @@ protected static function elementsToArray(\DOMNodeList $elements) | |
/** | ||
* Convert DOMElement to an array. | ||
* | ||
* @param \DOMElement $element element | ||
* @param DOMElement $element element | ||
* | ||
* @return array | ||
*/ | ||
protected static function elementToArray(\DOMElement $element) | ||
protected static function elementToArray(DOMElement $element) | ||
{ | ||
$array = array( | ||
'name' => $element->nodeName, | ||
'attributes' => array(), | ||
'innerHTML' => self::domInnerHtml($element), | ||
'name' => $element->nodeName, | ||
); | ||
foreach ($element->attributes as $key => $attr) { | ||
$array['attributes'][$key] = $attr->value; | ||
|
@@ -184,48 +187,42 @@ protected static function elementToArray(\DOMElement $element) | |
/** | ||
* Build inner html for given DOMElement | ||
* | ||
* @param \DOMElement $element dom element | ||
* @param DOMElement $element dom element | ||
* | ||
* @return string html | ||
*/ | ||
protected static function domInnerHtml(\DOMElement $element) | ||
protected static function domInnerHtml(DOMElement $element) | ||
{ | ||
$innerHTML = ''; | ||
foreach ($element->childNodes as $child) { | ||
$innerHTML .= $element->ownerDocument->saveHTML($child); | ||
} | ||
$innerHTML = \preg_replace('/{amp}([0-9a-z]+);/i', '&\1;', $innerHTML); | ||
// $innerHTML = str_replace("\xc2\xa0", ' ', $innerHTML); // &&   get converted to UTF-8 \xc2\xa0 | ||
/* | ||
saveHTML doesn't close "void" tags :( | ||
*/ | ||
$voidTags = array('area','base','br','col','command','embed','hr','img','input','keygen','link','meta','param','source','track','wbr'); | ||
$voidTags = array('area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'); | ||
$regEx = '#<(' . \implode('|', $voidTags) . ')(\b[^>]*)>#'; | ||
$innerHTML = \preg_replace($regEx, '<\\1\\2 />', $innerHTML); | ||
return \trim($innerHTML); | ||
} | ||
|
||
/** | ||
* Return \DOMXpath object | ||
* Return DOMXpath object | ||
* | ||
* @param string|\DOMDocument $html HTML string or \DOMDocument object | ||
* @param string|DOMDocument $html HTML string or DOMDocument object | ||
* | ||
* @return DOUMXpath | ||
*/ | ||
protected static function getDomXpath($html) | ||
{ | ||
if ($html instanceof \DOMDocument) { | ||
return new \DOMXpath($html); | ||
if ($html instanceof DOMDocument) { | ||
return new DOMXpath($html); | ||
} | ||
\libxml_use_internal_errors(true); | ||
if (empty($html)) { | ||
$html = '<!-- empty document -->'; | ||
} | ||
$dom = new \DOMDocument(); | ||
/* | ||
PHP bug: entities get converted | ||
*/ | ||
// $html = preg_replace('/&([0-9a-z]+);/i', '{amp}\1;', $html); | ||
$dom = new DOMDocument(); | ||
$dom->loadHTML('<?xml encoding="UTF-8">' . $html); // seriously? | ||
foreach ($dom->childNodes as $node) { | ||
if ($node->nodeType === XML_PI_NODE) { | ||
|
@@ -234,6 +231,6 @@ protected static function getDomXpath($html) | |
} | ||
} | ||
$dom->encoding = 'UTF-8'; | ||
return new \DOMXpath($dom); | ||
return new DOMXpath($dom); | ||
} | ||
} |
Oops, something went wrong.