diff --git a/composer.json b/composer.json index 70e737f..ba632fd 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,12 @@ } ], "require": { - "php": ">=8.0", + "php": ">=7.4", "guzzlehttp/guzzle": "^7.5.0", "kaltura/api-client-library": "^17.2" }, "scripts": { - "test": "./vendor/bin/phpunit tests" + "test": "./vendor/bin/phpunit tests --verbose" }, "autoload": { "classmap": [ diff --git a/composer.lock b/composer.lock index 423efbb..01f9395 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "22032ad7e71146735c1e48edd1f4c298", + "content-hash": "4f61c8e8a3d9d2758edcaf81821dbf60", "packages": [ { "name": "guzzlehttp/guzzle", @@ -220,16 +220,16 @@ }, { "name": "guzzlehttp/psr7", - "version": "2.4.1", + "version": "2.4.3", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379" + "reference": "67c26b443f348a51926030c83481b85718457d3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/69568e4293f4fa993f3b0e51c9723e1e17c41379", - "reference": "69568e4293f4fa993f3b0e51c9723e1e17c41379", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/67c26b443f348a51926030c83481b85718457d3d", + "reference": "67c26b443f348a51926030c83481b85718457d3d", "shasum": "" }, "require": { @@ -319,7 +319,7 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.4.1" + "source": "https://github.com/guzzle/psr7/tree/2.4.3" }, "funding": [ { @@ -335,7 +335,7 @@ "type": "tidelift" } ], - "time": "2022-08-28T14:45:39+00:00" + "time": "2022-10-26T14:07:24+00:00" }, { "name": "kaltura/api-client-library", @@ -591,25 +591,25 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.1.1", + "version": "v2.5.2", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918" + "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", - "reference": "07f1b9cc2ffee6aaafcf4b710fbc38ff736bd918", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66", + "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66", "shasum": "" }, "require": { - "php": ">=8.1" + "php": ">=7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "3.1-dev" + "dev-main": "2.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -638,7 +638,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.1.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.2" }, "funding": [ { @@ -654,36 +654,36 @@ "type": "tidelift" } ], - "time": "2022-02-25T11:15:52+00:00" + "time": "2022-01-02T09:53:40+00:00" } ], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.4.1", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", + "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^9 || ^11", "ext-pdo": "*", "ext-phar": "*", "phpbench/phpbench": "^0.16 || ^1", "phpstan/phpstan": "^1.4", "phpstan/phpstan-phpunit": "^1", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.22" + "vimeo/psalm": "^4.30 || ^5.4" }, "type": "library", "autoload": { @@ -710,7 +710,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.1" + "source": "https://github.com/doctrine/instantiator/tree/1.5.0" }, "funding": [ { @@ -726,7 +726,7 @@ "type": "tidelift" } ], - "time": "2022-03-03T08:28:38+00:00" + "time": "2022-12-30T00:15:36+00:00" }, { "name": "myclabs/deep-copy", @@ -1197,16 +1197,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.5.29", + "version": "8.5.32", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "e8c563c47a9a303662955518ca532b022b337f4d" + "reference": "375686930d05c9fd7d20f6e5fc38121e8d7a9d55" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e8c563c47a9a303662955518ca532b022b337f4d", - "reference": "e8c563c47a9a303662955518ca532b022b337f4d", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/375686930d05c9fd7d20f6e5fc38121e8d7a9d55", + "reference": "375686930d05c9fd7d20f6e5fc38121e8d7a9d55", "shasum": "" }, "require": { @@ -1225,10 +1225,10 @@ "phpunit/php-file-iterator": "^2.0.4", "phpunit/php-text-template": "^1.2.1", "phpunit/php-timer": "^2.1.2", - "sebastian/comparator": "^3.0.2", + "sebastian/comparator": "^3.0.5", "sebastian/diff": "^3.0.2", "sebastian/environment": "^4.2.3", - "sebastian/exporter": "^3.1.2", + "sebastian/exporter": "^3.1.5", "sebastian/global-state": "^3.0.0", "sebastian/object-enumerator": "^3.0.3", "sebastian/resource-operations": "^2.0.1", @@ -1274,7 +1274,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.29" + "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.32" }, "funding": [ { @@ -1284,9 +1284,13 @@ { "url": "https://github.com/sebastianbergmann", "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" } ], - "time": "2022-08-22T13:59:39+00:00" + "time": "2023-01-26T08:30:25+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -2074,7 +2078,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=8.0" + "php": ">=7.4" }, "platform-dev": [], "plugin-api-version": "2.0.0" diff --git a/src/PhpAllyIssue.php b/src/PhpAllyIssue.php index 9839a7f..f3f6249 100644 --- a/src/PhpAllyIssue.php +++ b/src/PhpAllyIssue.php @@ -9,6 +9,7 @@ class PhpAllyIssue implements \JsonSerializable protected $ruleId; protected $element; protected $previewElement; + protected $metadata; public function __construct($ruleId, DOMElement $element = null, DOMElement $previewElement = null, $metadata = null) { @@ -56,6 +57,14 @@ public function getHtml() return ''; } + $metaStr = $this->getMetadata(); + if ($metaStr) { + $metadata = \json_decode($metaStr, true); + if (!empty($metadata['isDocumentElement'])) { + return ''; + } + } + return $this->element->ownerDocument->saveHTML($this->element); } @@ -64,8 +73,18 @@ public function getPreview() if (!$this->previewElement) { return ''; } + + $metaStr = $this->getMetadata(); + if ($metaStr) { + $metadata = \json_decode($metaStr, true); + if (!empty($metadata['isDocumentElement'])) { + return ''; + } + } + + $preview = $this->element->ownerDocument->saveHTML($this->previewElement); - return $this->element->ownerDocument->saveHTML($this->previewElement); + return str_replace('', '', $preview); } public function toArray(): array diff --git a/src/Rule/BaseRule.php b/src/Rule/BaseRule.php index 8000d46..36765cd 100644 --- a/src/Rule/BaseRule.php +++ b/src/Rule/BaseRule.php @@ -17,6 +17,7 @@ class BaseRule implements PhpAllyRuleInterface { protected $errors = []; protected $lang; protected $strings = array('en' => ''); + protected $options; const ALT_TEXT_LENGTH_LIMIT = 150; const DOC_LENGTH = 1500; @@ -272,7 +273,6 @@ public function setIssue($element, $ruleId = null, $metadata = null) $ruleId = str_replace(['CidiLabs\\PhpAlly\\Rule\\','App\\Rule\\'], '', $ruleId); $previewElement = $this->previewElement; - $isDocumentElement = false; if ($element) { $elementClasses = $element->getAttribute('class'); diff --git a/src/Rule/DocumentReadingDirection.php b/src/Rule/DocumentReadingDirection.php index 48ba1a8..3fc9ef9 100644 --- a/src/Rule/DocumentReadingDirection.php +++ b/src/Rule/DocumentReadingDirection.php @@ -31,8 +31,9 @@ public function check() if ($element->getAttribute('dir') != 'rtl') $this->setIssue($element); } - $this->totalTests++; } + + $this->totalTests++; return count($this->issues); } diff --git a/src/Rule/NoHeadings.php b/src/Rule/NoHeadings.php index 19e3407..0b892b1 100644 --- a/src/Rule/NoHeadings.php +++ b/src/Rule/NoHeadings.php @@ -45,5 +45,10 @@ public function check() return count($this->issues); } } + + public function getPreviewElement(DOMElement $a = null) + { + return $a; + } } \ No newline at end of file diff --git a/tests/ContentTooLongTest.php b/tests/ContentTooLongTest.php index d459a80..c0c6f1d 100644 --- a/tests/ContentTooLongTest.php +++ b/tests/ContentTooLongTest.php @@ -52,4 +52,20 @@ public function testCheckSkipScriptTags() $this->assertEquals(0, $rule->check(), 'Content Too Long should have no issues.'); } + + public function testCheckMetadata() + { + $html = file_get_contents(__DIR__ . '/../tests/testFiles/ContentTooLong.html'); + $dom = new \DOMDocument('1.0', 'utf-8'); + $dom->loadHTML($html); + $rule = new ContentTooLong($dom); + + $this->assertEquals(1, $rule->check(), 'Content Too Long should have issues.'); + + $issues = $rule->getIssues(); + $issue = reset($issues); + + $this->assertEquals('', $issue->getHtml(), 'Content Too Long getHtml() returns an empty string.'); + $this->assertEquals('', $issue->getPreview(), 'Content Too Long getHtml() returns an empty string.'); + } } \ No newline at end of file