diff --git a/Mf2/Parser.php b/Mf2/Parser.php index c7cc02d..3cb5b82 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -62,7 +62,7 @@ function parse($input, $url = null, $convertClassic = true) { * @param &array $curlInfo (optional) the results of curl_getinfo will be placed in this variable for debugging * @return array|null canonical microformats2 array structure on success, null on failure */ -function fetch($url, $convertClassic = true, &$curlInfo=null) { +function fetch($url, $convertClassic = true, &$curlInfo = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @@ -127,7 +127,7 @@ function unicodeTrim($str) { * @param string $prefix The prefix to look for * @return string|array The prefixed name of the first microfomats class found or false */ -function mfNamesFromClass($class, $prefix='h-') { +function mfNamesFromClass($class, $prefix = 'h-') { $class = str_replace(array(' ', ' ', "\n"), ' ', $class); $classes = explode(' ', $class); $classes = preg_grep('#^(h|p|u|dt|e)-([a-z0-9]+-)?[a-z]+(-[a-z]+)*$#', $classes); @@ -366,7 +366,7 @@ public function __construct($input, $url = null, $jsonMode = false) { if (empty($input)) { $input = $emptyDocDefault; } - + if (class_exists('Masterminds\\HTML5')) { $doc = new \Masterminds\HTML5(array('disable_html_ns' => true)); $doc = $doc->loadHTML($input); @@ -482,7 +482,7 @@ private function resolveChildUrls(DOMElement $el) { * @param bool $implied * @see https://wiki.zegnat.net/media/textparsing.html **/ - public function textContent(DOMElement $element, $implied=false) + public function textContent(DOMElement $element, $implied = false) { return preg_replace( '/(^[\t\n\f\r ]+| +(?=\n)|(?<=\n) +| +(?= )|[\t\n\f\r ]+$)/', @@ -490,7 +490,7 @@ public function textContent(DOMElement $element, $implied=false) $this->elementToString($element, $implied) ); } - private function elementToString(DOMElement $input, $implied=false) + private function elementToString(DOMElement $input, $implied = false) { $output = ''; foreach ($input->childNodes as $child) { @@ -1179,7 +1179,7 @@ public function parseH(\DOMElement $e, $is_backcompat = false, $has_nested_mf = ); if(trim($e->getAttribute('id')) !== '') { - $parsed['id'] = trim($e->getAttribute("id")); + $parsed['id'] = trim($e->getAttribute('id')); } if($this->lang) { @@ -1385,7 +1385,7 @@ public function upgradeRelTagToCategory(DOMElement $el) { */ public function parse($convertClassic = true, DOMElement $context = null) { $this->convertClassic = $convertClassic; - $mfs = $this->parse_recursive($context); + $mfs = $this->parseRecursive($context); // Parse rels list($rels, $rel_urls, $alternates) = $this->parseRelsAndAlternates(); @@ -1411,7 +1411,7 @@ public function parse($convertClassic = true, DOMElement $context = null) { * @param int $depth: recursion depth * @return array */ - public function parse_recursive(DOMElement $context = null, $depth = 0) { + public function parseRecursive(DOMElement $context = null, $depth = 0) { $mfs = array(); $mfElements = $this->getRootMF($context); @@ -1422,7 +1422,7 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) { $this->backcompat($node); } - $recurse = $this->parse_recursive($node, $depth + 1); + $recurse = $this->parseRecursive($node, $depth + 1); // set bool flag for nested mf $has_nested_mf = (bool) $recurse; @@ -1486,6 +1486,18 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) { return $mfs; } + /** + * Parse microformats recursively (deprecated) + * @param DOMElement $context: node to start with + * @param int $depth: recursion depth + * @return array + * @deprecated Use parseRecursive() instead + */ + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps + public function parse_recursive(DOMElement $context = null, $depth = 0) { + return $this->parseRecursive($context, $depth); + } + /** * Parse From ID @@ -1502,7 +1514,7 @@ public function parse_recursive(DOMElement $context = null, $depth = 0) { * @param bool $htmlSafe = false whether or not to HTML-encode angle brackets in non e-* properties * @return array */ - public function parseFromId($id, $convertClassic=true) { + public function parseFromId($id, $convertClassic = true) { $matches = $this->xpath->query("//*[@id='{$id}']"); if (empty($matches)) diff --git a/phpcs.xml b/phpcs.xml index 8e94cdd..5851760 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,7 +1,49 @@ - PHP-MF2 Standards + PHP-MF2 Coding Standards + ./Mf2/Parser.php + ./tests/ + + + + + + + + + + + tests/Mf2/ParseDTTest.php + + + + + + + + + + + + + + + + + + + + + + + + + + + + tests/* + diff --git a/tests/Mf2/ClassicMicroformatsTest.php b/tests/Mf2/ClassicMicroformatsTest.php index e1c2481..6240636 100644 --- a/tests/Mf2/ClassicMicroformatsTest.php +++ b/tests/Mf2/ClassicMicroformatsTest.php @@ -18,6 +18,7 @@ * Mainly based off BC tables on https://microformats.org/wiki/microformats2#v2_vocabularies */ class ClassicMicroformatsTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -147,7 +148,7 @@ public function testParsesHProduct() { /** * @see https://github.com/indieweb/php-mf2/issues/81 */ - public function test_vevent() { + public function testVevent() { $input = <<< EOT

XYZ Project Review

@@ -896,7 +897,7 @@ public function testHEntryRelTag() { } public function testHEntryRelTagInContent() { - $input = <<< END + $input = <<< END
Entry content should not include the generated data element for rel tag backcompat @@ -904,13 +905,13 @@ public function testHEntryRelTagInContent() {
END; - $parser = new Parser($input); - $output = $parser->parse(); - $item = $output['items'][0]; + $parser = new Parser($input); + $output = $parser->parse(); + $item = $output['items'][0]; - $this->assertEquals(['test'], $item['properties']['category']); - $this->assertEquals('Entry content should not include the generated data element for rel tag backcompat test', $item['properties']['content'][0]['value']); - $this->assertEquals('Entry content should not include the generated data element for rel tag backcompat ', $item['properties']['content'][0]['html']); + $this->assertEquals(['test'], $item['properties']['category']); + $this->assertEquals('Entry content should not include the generated data element for rel tag backcompat test', $item['properties']['content'][0]['value']); + $this->assertEquals('Entry content should not include the generated data element for rel tag backcompat ', $item['properties']['content'][0]['html']); } /** diff --git a/tests/Mf2/CombinedMicroformatsTest.php b/tests/Mf2/CombinedMicroformatsTest.php index b275cb6..ae0638b 100644 --- a/tests/Mf2/CombinedMicroformatsTest.php +++ b/tests/Mf2/CombinedMicroformatsTest.php @@ -18,6 +18,7 @@ class CombinedMicroformatsTest extends TestCase { use AssertIsType; + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -294,7 +295,7 @@ public function testMicroformatsNestedUnderUPropertyClassnamesDeriveValueFromURL "rels":[], "rel-urls": [] }'; - $mf = Mf2\parse($input); + $mf = Mf2\parse($input); $this->assertJsonStringEqualsJsonString(json_encode($mf), $expected); $this->assertEquals($mf['items'][0]['properties']['comment'][0]['value'], 'https://example.com/post1234'); @@ -345,18 +346,18 @@ public function testNestedMf1() { } public function testNoUrlFromRelOnMf2() { - $input = <<< END + $input = <<< END

Title of Post

This is the post

END; - $parser = new Parser($input); - $output = $parser->parse(); + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('name', $output['items'][0]['properties']); - $this->assertArrayHasKey('content', $output['items'][0]['properties']); - $this->assertArrayNotHasKey('url', $output['items'][0]['properties']); + $this->assertArrayHasKey('name', $output['items'][0]['properties']); + $this->assertArrayHasKey('content', $output['items'][0]['properties']); + $this->assertArrayNotHasKey('url', $output['items'][0]['properties']); } /** @@ -378,7 +379,7 @@ public function testNestedValuePProperty() { $output = $parser->parse(); $this->assertArrayHasKey('value', $output['items'][0]['properties']['location'][0]); - $this->assertEquals("Portland, Oregon • 44°F", $output['items'][0]['properties']['location'][0]['value']); + $this->assertEquals('Portland, Oregon • 44°F', $output['items'][0]['properties']['location'][0]['value']); } /** diff --git a/tests/Mf2/MicroformatsTestSuiteTest.php b/tests/Mf2/MicroformatsTestSuiteTest.php index 855c1fd..ef8668f 100644 --- a/tests/Mf2/MicroformatsTestSuiteTest.php +++ b/tests/Mf2/MicroformatsTestSuiteTest.php @@ -6,164 +6,164 @@ final class TestSuiteParser extends \Mf2\Parser { - /** Actually textContent from before the whitespace normalisation merge (e8da04f93d548d26287a8980eca4216639cbc61d) */ - public function textContent(\DOMElement $el, $dummy=false) { - $excludeTags = array('noframe', 'noscript', 'script', 'style', 'frames', 'frameset'); - - if (isset($el->tagName) and in_array(strtolower($el->tagName), $excludeTags)) { - return ''; - } - - $this->_resolveChildUrls($el); - - $clonedEl = $el->cloneNode(true); - - foreach ($this->xpath->query('.//img', $clonedEl) as $imgEl) { - if ($imgEl->hasAttribute('alt')) { - $replacement = $imgEl->getAttribute('alt'); - } else if ($imgEl->hasAttribute('src')) { - $replacement = ' ' . $imgEl->getAttribute('src') . ' '; - } else { - $replacement = ''; // Bye bye IMG element. - } - $newNode = $this->doc->createTextNode($replacement); - $imgEl->parentNode->replaceChild($newNode, $imgEl); - } - - foreach ($excludeTags as $tagName) { - foreach ($this->xpath->query(".//{$tagName}", $clonedEl) as $elToRemove) { - $elToRemove->parentNode->removeChild($elToRemove); - } - } - - return \Mf2\unicodeTrim($clonedEl->textContent); - } - - // Hack. Old textContent requires "resolveChildUrls", but that method is private. - private $__resolveChildUrls = null; - private function _resolveChildUrls(\DOMElement $element) { - if (null === $this->__resolveChildUrls) { - $reflectUpon = new \ReflectionClass($this); - $this->__resolveChildUrls = $reflectUpon->getMethod('resolveChildUrls'); - $this->__resolveChildUrls->setAccessible(true); - } - return $this->__resolveChildUrls->invoke($this, $element); - } + /** Actually textContent from before the whitespace normalisation merge (e8da04f93d548d26287a8980eca4216639cbc61d) */ + public function textContent(\DOMElement $el, $dummy = false) { + $excludeTags = array('noframe', 'noscript', 'script', 'style', 'frames', 'frameset'); + + if (isset($el->tagName) and in_array(strtolower($el->tagName), $excludeTags)) { + return ''; + } + + $this->_resolveChildUrls($el); + + $clonedEl = $el->cloneNode(true); + + foreach ($this->xpath->query('.//img', $clonedEl) as $imgEl) { + if ($imgEl->hasAttribute('alt')) { + $replacement = $imgEl->getAttribute('alt'); + } else if ($imgEl->hasAttribute('src')) { + $replacement = ' ' . $imgEl->getAttribute('src') . ' '; + } else { + $replacement = ''; // Bye bye IMG element. + } + $newNode = $this->doc->createTextNode($replacement); + $imgEl->parentNode->replaceChild($newNode, $imgEl); + } + + foreach ($excludeTags as $tagName) { + foreach ($this->xpath->query(".//{$tagName}", $clonedEl) as $elToRemove) { + $elToRemove->parentNode->removeChild($elToRemove); + } + } + + return \Mf2\unicodeTrim($clonedEl->textContent); + } + + // Hack. Old textContent requires "resolveChildUrls", but that method is private. + private $__resolveChildUrls = null; + private function _resolveChildUrls(\DOMElement $element) { + if (null === $this->__resolveChildUrls) { + $reflectUpon = new \ReflectionClass($this); + $this->__resolveChildUrls = $reflectUpon->getMethod('resolveChildUrls'); + $this->__resolveChildUrls->setAccessible(true); + } + return $this->__resolveChildUrls->invoke($this, $element); + } } class MicroformatsTestSuiteTest extends TestCase { - /** - * @dataProvider mf1TestsProvider - * @group microformats/tests/mf1 - */ - public function testMf1FromTestSuite($input, $expectedOutput) - { - $parser = new TestSuiteParser($input, 'http://example.com/'); - $this->assertEquals( - $this->makeComparible(json_decode($expectedOutput, true)), - $this->makeComparible(json_decode(json_encode($parser->parse()), true)) - ); - } - - /** - * @dataProvider mf2TestsProvider - * @group microformats/tests/mf2 - */ - public function testMf2FromTestSuite($input, $expectedOutput, $test) - { - if ($test === 'h-event/time') { - $this->markTestIncomplete('This test does not match because we implement a proposed spec: https://github.com/microformats/microformats2-parsing/issues/4#issuecomment-373457720.'); - } - - $parser = new TestSuiteParser($input, 'http://example.com/'); - $this->assertEquals( - $this->makeComparible(json_decode($expectedOutput, true)), - $this->makeComparible(json_decode(json_encode($parser->parse()), true)) - ); - } - - /** - * @dataProvider mixedTestsProvider - * @group microformats/tests/mixed - */ - public function testMixedFromTestSuite($input, $expectedOutput) - { - $parser = new TestSuiteParser($input, 'http://example.com/'); - $this->assertEquals( - $this->makeComparible(json_decode($expectedOutput, true)), - $this->makeComparible(json_decode(json_encode($parser->parse()), true)) - ); - } - - /** - * To make arrays coming from JSON more easily comparible by PHPUnit: - * * We sort arrays by key, normalising them, because JSON objects are unordered. - * * We json_encode strings, and cut the starting and ending ", so PHPUnit better - * shows whitespace characters like tabs and newlines. - **/ - public function makeComparible($array) - { - ksort($array); - foreach ($array as $key => $value) { - if (gettype($value) === 'array') { - $array[$key] = $this->makeComparible($value); - } else if (gettype($value) === 'string') { - $array[$key] = substr(json_encode($value), 1, -1); - } - } - return $array; - } - - /** - * Data provider lists all tests from a specific directory in mf2/tests. - **/ - public function htmlAndJsonProvider($subFolder = '') - { - // Get the actual wanted subfolder. - $subFolder = '/mf2/tests/tests' . $subFolder; - // Ripped out of the test-suite.php code: - $finder = new \RegexIterator( - new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator( - dirname(__FILE__) . '/../../vendor/' . $subFolder, - \RecursiveDirectoryIterator::SKIP_DOTS - )), - '/^.+\.html$/i', - \RecursiveRegexIterator::GET_MATCH - ); - // Build the array of separate tests: - $tests = array(); - foreach ($finder as $key => $value) { - $dir = realpath(pathinfo($key, PATHINFO_DIRNAME)); - $testname = substr($dir, strpos($dir, $subFolder) + strlen($subFolder) + 1) . '/' . pathinfo($key, PATHINFO_FILENAME); - $test = pathinfo($key, PATHINFO_BASENAME); - $result = pathinfo($key, PATHINFO_FILENAME) . '.json'; - if (is_file($dir . '/' . $result)) { - $tests[$testname] = array( - 'input' => file_get_contents($dir . '/' . $test), - 'expectedOutput' => file_get_contents($dir . '/' . $result), - 'name' => $testname - ); - } - } - return $tests; - } - - /** - * Following three functions are the actual dataProviders used by the test methods. - */ - public function mf1TestsProvider() - { - return $this->htmlAndJsonProvider('/microformats-v1'); - } - - public function mf2TestsProvider() - { - return $this->htmlAndJsonProvider('/microformats-v2'); - } - - public function mixedTestsProvider() - { - return $this->htmlAndJsonProvider('/microformats-mixed'); - } + /** + * @dataProvider mf1TestsProvider + * @group microformats/tests/mf1 + */ + public function testMf1FromTestSuite($input, $expectedOutput) + { + $parser = new TestSuiteParser($input, 'http://example.com/'); + $this->assertEquals( + $this->makeComparible(json_decode($expectedOutput, true)), + $this->makeComparible(json_decode(json_encode($parser->parse()), true)) + ); + } + + /** + * @dataProvider mf2TestsProvider + * @group microformats/tests/mf2 + */ + public function testMf2FromTestSuite($input, $expectedOutput, $test) + { + if ($test === 'h-event/time') { + $this->markTestIncomplete('This test does not match because we implement a proposed spec: https://github.com/microformats/microformats2-parsing/issues/4#issuecomment-373457720.'); + } + + $parser = new TestSuiteParser($input, 'http://example.com/'); + $this->assertEquals( + $this->makeComparible(json_decode($expectedOutput, true)), + $this->makeComparible(json_decode(json_encode($parser->parse()), true)) + ); + } + + /** + * @dataProvider mixedTestsProvider + * @group microformats/tests/mixed + */ + public function testMixedFromTestSuite($input, $expectedOutput) + { + $parser = new TestSuiteParser($input, 'http://example.com/'); + $this->assertEquals( + $this->makeComparible(json_decode($expectedOutput, true)), + $this->makeComparible(json_decode(json_encode($parser->parse()), true)) + ); + } + + /** + * To make arrays coming from JSON more easily comparible by PHPUnit: + * * We sort arrays by key, normalising them, because JSON objects are unordered. + * * We json_encode strings, and cut the starting and ending ", so PHPUnit better + * shows whitespace characters like tabs and newlines. + **/ + public function makeComparible($array) + { + ksort($array); + foreach ($array as $key => $value) { + if (gettype($value) === 'array') { + $array[$key] = $this->makeComparible($value); + } else if (gettype($value) === 'string') { + $array[$key] = substr(json_encode($value), 1, -1); + } + } + return $array; + } + + /** + * Data provider lists all tests from a specific directory in mf2/tests. + **/ + public function htmlAndJsonProvider($subFolder = '') + { + // Get the actual wanted subfolder. + $subFolder = '/mf2/tests/tests' . $subFolder; + // Ripped out of the test-suite.php code: + $finder = new \RegexIterator( + new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator( + dirname(__FILE__) . '/../../vendor/' . $subFolder, + \RecursiveDirectoryIterator::SKIP_DOTS + )), + '/^.+\.html$/i', + \RecursiveRegexIterator::GET_MATCH + ); + // Build the array of separate tests: + $tests = array(); + foreach ($finder as $key => $value) { + $dir = realpath(pathinfo($key, PATHINFO_DIRNAME)); + $testname = substr($dir, strpos($dir, $subFolder) + strlen($subFolder) + 1) . '/' . pathinfo($key, PATHINFO_FILENAME); + $test = pathinfo($key, PATHINFO_BASENAME); + $result = pathinfo($key, PATHINFO_FILENAME) . '.json'; + if (is_file($dir . '/' . $result)) { + $tests[$testname] = array( + 'input' => file_get_contents($dir . '/' . $test), + 'expectedOutput' => file_get_contents($dir . '/' . $result), + 'name' => $testname + ); + } + } + return $tests; + } + + /** + * Following three functions are the actual dataProviders used by the test methods. + */ + public function mf1TestsProvider() + { + return $this->htmlAndJsonProvider('/microformats-v1'); + } + + public function mf2TestsProvider() + { + return $this->htmlAndJsonProvider('/microformats-v2'); + } + + public function mixedTestsProvider() + { + return $this->htmlAndJsonProvider('/microformats-mixed'); + } } diff --git a/tests/Mf2/MicroformatsWikiExamplesTest.php b/tests/Mf2/MicroformatsWikiExamplesTest.php index f269485..d3d0777 100644 --- a/tests/Mf2/MicroformatsWikiExamplesTest.php +++ b/tests/Mf2/MicroformatsWikiExamplesTest.php @@ -20,6 +20,7 @@ * @author Barnaby Walters waterpigs.co.uk */ class MicroformatsWikiExamplesTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -39,7 +40,7 @@ public function testHandlesEmptyStringsCorrectly() { } public function testHandlesNullCorrectly() { - $input = Null; + $input = null; $expected = '{ "rels": {}, "rel-urls": {}, diff --git a/tests/Mf2/ParseDTTest.php b/tests/Mf2/ParseDTTest.php index 28027d6..29252de 100644 --- a/tests/Mf2/ParseDTTest.php +++ b/tests/Mf2/ParseDTTest.php @@ -10,6 +10,7 @@ use Yoast\PHPUnitPolyfills\TestCases\TestCase; class ParseDTTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -48,7 +49,6 @@ public function testParseDTHandlesDataInnerHTML() { $parser = new Parser($input); $output = $parser->parse(); - $this->assertArrayHasKey('start', $output['items'][0]['properties']); $this->assertEquals('2012-08-05T14:50', $output['items'][0]['properties']['start'][0]); } @@ -93,36 +93,36 @@ public function testParseDTHandlesTimeDatetimeAttr() { * @group parseDT */ public function testParseDTHandlesTimeDatetimeAttrWithZ() { - $input = '
'; - $parser = new Parser($input); - $output = $parser->parse(); + $input = '
'; + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('start', $output['items'][0]['properties']); - $this->assertEquals('2012-08-05T14:50:00Z', $output['items'][0]['properties']['start'][0]); + $this->assertArrayHasKey('start', $output['items'][0]['properties']); + $this->assertEquals('2012-08-05T14:50:00Z', $output['items'][0]['properties']['start'][0]); } /** * @group parseDT */ public function testParseDTHandlesTimeDatetimeAttrWithTZOffset() { - $input = '
'; - $parser = new Parser($input); - $output = $parser->parse(); + $input = '
'; + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('start', $output['items'][0]['properties']); - $this->assertEquals('2012-08-05T14:50:00-0700', $output['items'][0]['properties']['start'][0]); + $this->assertArrayHasKey('start', $output['items'][0]['properties']); + $this->assertEquals('2012-08-05T14:50:00-0700', $output['items'][0]['properties']['start'][0]); } /** * @group parseDT */ public function testParseDTHandlesTimeDatetimeAttrWithTZOffset2() { - $input = '
'; - $parser = new Parser($input); - $output = $parser->parse(); + $input = '
'; + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('start', $output['items'][0]['properties']); - $this->assertEquals('2012-08-05T14:50:00-07:00', $output['items'][0]['properties']['start'][0]); + $this->assertArrayHasKey('start', $output['items'][0]['properties']); + $this->assertEquals('2012-08-05T14:50:00-07:00', $output['items'][0]['properties']['start'][0]); } /** @@ -133,7 +133,6 @@ public function testParseDTHandlesTimeInnerHTML() { $parser = new Parser($input); $output = $parser->parse(); - $this->assertArrayHasKey('start', $output['items'][0]['properties']); $this->assertEquals('2012-08-05T14:50', $output['items'][0]['properties']['start'][0]); } diff --git a/tests/Mf2/ParseHtmlIdTest.php b/tests/Mf2/ParseHtmlIdTest.php index 235dd86..d00390c 100644 --- a/tests/Mf2/ParseHtmlIdTest.php +++ b/tests/Mf2/ParseHtmlIdTest.php @@ -13,6 +13,7 @@ * */ class ParseHtmlIdTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } diff --git a/tests/Mf2/ParseImpliedTest.php b/tests/Mf2/ParseImpliedTest.php index 46a50b0..a11e400 100644 --- a/tests/Mf2/ParseImpliedTest.php +++ b/tests/Mf2/ParseImpliedTest.php @@ -13,6 +13,7 @@ * @todo some of these can be made into single tests with dataProviders */ class ParseImpliedTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -147,22 +148,22 @@ public function testParsesImpliedUUrlFromNestedAHref() { } public function testParsesImpliedUUrlWithExplicitName() { - $input = 'Some Name'; - $parser = new Parser($input); - $output = $parser->parse(); + $input = 'Some Name'; + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('url', $output['items'][0]['properties']); - $this->assertEquals('https://example.com/', $output['items'][0]['properties']['url'][0]); + $this->assertArrayHasKey('url', $output['items'][0]['properties']); + $this->assertEquals('https://example.com/', $output['items'][0]['properties']['url'][0]); } public function testParsesImpliedNameWithExplicitURL() { - $input = 'Some Name'; - $parser = new Parser($input); - $output = $parser->parse(); + $input = 'Some Name'; + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('url', $output['items'][0]['properties']); - $this->assertEquals('https://example.com/', $output['items'][0]['properties']['url'][0]); - $this->assertEquals('Some Name', $output['items'][0]['properties']['name'][0]); + $this->assertArrayHasKey('url', $output['items'][0]['properties']); + $this->assertEquals('https://example.com/', $output['items'][0]['properties']['url'][0]); + $this->assertEquals('Some Name', $output['items'][0]['properties']['name'][0]); } public function testMultipleImpliedHCards() { diff --git a/tests/Mf2/ParseLanguageTest.php b/tests/Mf2/ParseLanguageTest.php index be96da9..1e7af0d 100644 --- a/tests/Mf2/ParseLanguageTest.php +++ b/tests/Mf2/ParseLanguageTest.php @@ -11,6 +11,7 @@ use Yoast\PHPUnitPolyfills\TestCases\TestCase; class ParseLanguageTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -57,45 +58,45 @@ public function testHtmlAndHEntryLang() $this->assertEquals('es', $result['items'][0]['lang']); } # end method testHtmlAndHEntryLang() - /** - * Test HTML fragment with only h-entry lang - */ - public function testFragmentHEntryLangOnly() - { - $input = '
This test is in English.
'; - $parser = new Parser($input); - $parser->lang = true; - $result = $parser->parse(); - - $this->assertArrayHasKey('lang', $result['items'][0]); - $this->assertEquals('en', $result['items'][0]['lang']); - } # end method testFragmentHEntryLangOnly() - - /** - * Test HTML fragment with no lang - */ - public function testFragmentHEntryNoLang() - { - $input = '
This test is in English.
'; - $parser = new Parser($input); - $parser->lang = true; - $result = $parser->parse(); - - $this->assertArrayNotHasKey('lang', $result['items'][0]); - } # end method testFragmentHEntryNoLang() - - /** - * Test HTML fragment with no lang, loaded with loadXML() - */ - public function testFragmentHEntryNoLangXML() - { - $input = new \DOMDocument(); - $input->loadXML('
This test is in English.
'); - $parser = new Parser($input); - $result = $parser->parse(); - - $this->assertArrayNotHasKey('lang', $result['items'][0]); - } # end method testFragmentHEntryNoLangXML() + /** + * Test HTML fragment with only h-entry lang + */ + public function testFragmentHEntryLangOnly() + { + $input = '
This test is in English.
'; + $parser = new Parser($input); + $parser->lang = true; + $result = $parser->parse(); + + $this->assertArrayHasKey('lang', $result['items'][0]); + $this->assertEquals('en', $result['items'][0]['lang']); + } # end method testFragmentHEntryLangOnly() + + /** + * Test HTML fragment with no lang + */ + public function testFragmentHEntryNoLang() + { + $input = '
This test is in English.
'; + $parser = new Parser($input); + $parser->lang = true; + $result = $parser->parse(); + + $this->assertArrayNotHasKey('lang', $result['items'][0]); + } # end method testFragmentHEntryNoLang() + + /** + * Test HTML fragment with no lang, loaded with loadXML() + */ + public function testFragmentHEntryNoLangXML() + { + $input = new \DOMDocument(); + $input->loadXML('
This test is in English.
'); + $parser = new Parser($input); + $result = $parser->parse(); + + $this->assertArrayNotHasKey('lang', $result['items'][0]); + } # end method testFragmentHEntryNoLangXML() /** * Test with different , h-entry lang, and h-entry without lang, diff --git a/tests/Mf2/ParsePTest.php b/tests/Mf2/ParsePTest.php index 746f7c1..6129ff0 100644 --- a/tests/Mf2/ParsePTest.php +++ b/tests/Mf2/ParsePTest.php @@ -12,6 +12,7 @@ class ParsePTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -36,7 +37,6 @@ public function testParsePHandlesImg() { $parser = new Parser($input); $output = $parser->parse(); - $this->assertArrayHasKey('name', $output['items'][0]['properties']); $this->assertEquals('Example User', $output['items'][0]['properties']['name'][0]); } @@ -61,7 +61,6 @@ public function testParsePHandlesData() { $parser = new Parser($input); $output = $parser->parse(); - $this->assertArrayHasKey('name', $output['items'][0]['properties']); $this->assertEquals('Example User', $output['items'][0]['properties']['name'][0]); } diff --git a/tests/Mf2/ParseUTest.php b/tests/Mf2/ParseUTest.php index b116df6..97a57a5 100644 --- a/tests/Mf2/ParseUTest.php +++ b/tests/Mf2/ParseUTest.php @@ -10,6 +10,7 @@ use Yoast\PHPUnitPolyfills\TestCases\TestCase; class ParseUTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -31,7 +32,7 @@ public function testParseUHandlesA() { */ public function testParseUHandlesEmptyHrefAttribute() { $input = ''; - $parser = new Parser($input, "https://example.com/"); + $parser = new Parser($input, 'https://example.com/'); $output = $parser->parse(); $this->assertArrayHasKey('url', $output['items'][0]['properties']); @@ -43,7 +44,7 @@ public function testParseUHandlesEmptyHrefAttribute() { */ public function testParseUHandlesMissingHrefAttribute() { $input = ''; - $parser = new Parser($input, "https://example.com/"); + $parser = new Parser($input, 'https://example.com/'); $output = $parser->parse(); $this->assertArrayHasKey('url', $output['items'][0]['properties']); diff --git a/tests/Mf2/ParseValueClassTitleTest.php b/tests/Mf2/ParseValueClassTitleTest.php index 5947c09..77aead2 100644 --- a/tests/Mf2/ParseValueClassTitleTest.php +++ b/tests/Mf2/ParseValueClassTitleTest.php @@ -11,6 +11,7 @@ use Yoast\PHPUnitPolyfills\TestCases\TestCase; class ParseValueClassTitleTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } diff --git a/tests/Mf2/ParserTest.php b/tests/Mf2/ParserTest.php index 3f76d1b..a5c3241 100644 --- a/tests/Mf2/ParserTest.php +++ b/tests/Mf2/ParserTest.php @@ -20,6 +20,7 @@ class ParserTest extends TestCase { use AssertIsType; use AssertStringContains; + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -930,7 +931,7 @@ public function testNewlineBeforePrefix() { $this->assertEquals('Page Title', $result['items'][0]['properties']['name'][0]); $this->assertEquals('A summary so the p-name won\'t be implied. This test demonstrates p-name is not being parsed.', $result['items'][0]['properties']['summary'][0]); } - + /** * @see https://github.com/microformats/php-mf2/issues/249 */ diff --git a/tests/Mf2/PlainTextTest.php b/tests/Mf2/PlainTextTest.php index 621276e..0bcdd3e 100644 --- a/tests/Mf2/PlainTextTest.php +++ b/tests/Mf2/PlainTextTest.php @@ -4,74 +4,74 @@ use Yoast\PHPUnitPolyfills\TestCases\TestCase; class PlainTextTest extends TestCase { - /** - * @dataProvider aaronpkExpectations - */ - public function testAaronpkExpectations($input, $pName, $eValue, $eHtml) { - $parser = new \Mf2\Parser($input); - $output = $parser->parse(); - $entryProperties = $output['items'][0]['properties']; - $this->assertEquals($pName, $entryProperties['name'][0]); - $this->assertEquals($eValue, $entryProperties['content'][0]['value']); - $this->assertEquals($eHtml, $entryProperties['content'][0]['html']); - } + /** + * @dataProvider aaronpkExpectations + */ + public function testAaronpkExpectations($input, $pName, $eValue, $eHtml) { + $parser = new \Mf2\Parser($input); + $output = $parser->parse(); + $entryProperties = $output['items'][0]['properties']; + $this->assertEquals($pName, $entryProperties['name'][0]); + $this->assertEquals($eValue, $entryProperties['content'][0]['value']); + $this->assertEquals($eHtml, $entryProperties['content'][0]['html']); + } - public function aaronpkExpectations() { - return array( - 1 => array( - "
\n

Hello World

\n
", - "Hello World", - "Hello World", - "

Hello World

" - ), - 2 => array( - "
\n

Hello
World

\n
", - "Hello\nWorld", - "Hello\nWorld", - "

Hello
World

" - ), - 3 => array( - "
\n

Hello
\nWorld

\n
", - "Hello\nWorld", - "Hello\nWorld", - "

Hello
\nWorld

" - ), - 4 => array( - "
\n
\n

Hello World

\n
\n
", - "Hello World", - "Hello World", - "

Hello World

" - ), - 5 => array( - "
\n
Hello\nWorld
\n
", - "Hello World", - "Hello World", - "Hello\nWorld" - ), - 6 => array( - "
\n

Hello

World

\n
", - "Hello\nWorld", - "Hello\nWorld", - "

Hello

World

" - ), - 7 => array( - "
\n
Hello
\n World
\n
", - "Hello\nWorld", - "Hello\nWorld", - "Hello
\n World", - ), - 8 => array( - "
\n

Hello
World
\n
", - "Hello\nWorld", - "Hello\nWorld", - "
Hello
World
" - ), - 9 => array( - "
\n
\n

One

\n

Two

\n

Three

\n
\n
", - "One\nTwo\nThree", - "One\nTwo\nThree", - "

One

\n

Two

\n

Three

" - ) - ); - } + public function aaronpkExpectations() { + return array( + 1 => array( + "
\n

Hello World

\n
", + 'Hello World', + 'Hello World', + '

Hello World

' + ), + 2 => array( + "
\n

Hello
World

\n
", + "Hello\nWorld", + "Hello\nWorld", + '

Hello
World

' + ), + 3 => array( + "
\n

Hello
\nWorld

\n
", + "Hello\nWorld", + "Hello\nWorld", + "

Hello
\nWorld

" + ), + 4 => array( + "
\n
\n

Hello World

\n
\n
", + 'Hello World', + 'Hello World', + '

Hello World

' + ), + 5 => array( + "
\n
Hello\nWorld
\n
", + 'Hello World', + 'Hello World', + "Hello\nWorld" + ), + 6 => array( + "
\n

Hello

World

\n
", + "Hello\nWorld", + "Hello\nWorld", + '

Hello

World

' + ), + 7 => array( + "
\n
Hello
\n World
\n
", + "Hello\nWorld", + "Hello\nWorld", + "Hello
\n World", + ), + 8 => array( + "
\n

Hello
World
\n
", + "Hello\nWorld", + "Hello\nWorld", + '
Hello
World
' + ), + 9 => array( + "
\n
\n

One

\n

Two

\n

Three

\n
\n
", + "One\nTwo\nThree", + "One\nTwo\nThree", + "

One

\n

Two

\n

Three

" + ) + ); + } } diff --git a/tests/Mf2/RelTest.php b/tests/Mf2/RelTest.php index 1effd19..a4f1d32 100644 --- a/tests/Mf2/RelTest.php +++ b/tests/Mf2/RelTest.php @@ -11,60 +11,60 @@ class RelTest extends TestCase { public function testRelValueOnLinkTag() { - $input = ''; - $parser = new Parser($input); - $output = $parser->parse(); + $input = ''; + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('webmention', $output['rels']); - $this->assertEquals('https://example.com/webmention', $output['rels']['webmention'][0]); + $this->assertArrayHasKey('webmention', $output['rels']); + $this->assertEquals('https://example.com/webmention', $output['rels']['webmention'][0]); } public function testRelValueOnATag() { - $input = 'webmention me'; - $parser = new Parser($input); - $output = $parser->parse(); + $input = 'webmention me'; + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('webmention', $output['rels']); - $this->assertEquals('https://example.com/webmention', $output['rels']['webmention'][0]); + $this->assertArrayHasKey('webmention', $output['rels']); + $this->assertEquals('https://example.com/webmention', $output['rels']['webmention'][0]); } public function testRelValueOnAreaTag() { - $input = ''; - $parser = new Parser($input); - $output = $parser->parse(); + $input = ''; + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('webmention', $output['rels']); - $this->assertEquals('https://example.com/webmention', $output['rels']['webmention'][0]); + $this->assertArrayHasKey('webmention', $output['rels']); + $this->assertEquals('https://example.com/webmention', $output['rels']['webmention'][0]); } public function testRelValueOrder() { - $input = ' + $input = ' webmention me '; - $parser = new Parser($input); - $output = $parser->parse(); + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('webmention', $output['rels']); - $this->assertEquals('https://example.com/area', $output['rels']['webmention'][0]); - $this->assertEquals('https://example.com/a', $output['rels']['webmention'][1]); - $this->assertEquals('https://example.com/link', $output['rels']['webmention'][2]); + $this->assertArrayHasKey('webmention', $output['rels']); + $this->assertEquals('https://example.com/area', $output['rels']['webmention'][0]); + $this->assertEquals('https://example.com/a', $output['rels']['webmention'][1]); + $this->assertEquals('https://example.com/link', $output['rels']['webmention'][2]); } public function testRelValueOrder2() { - $input = ' + $input = ' webmention me'; - $parser = new Parser($input); - $output = $parser->parse(); + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('webmention', $output['rels']); - $this->assertEquals('https://example.com/area', $output['rels']['webmention'][0]); - $this->assertEquals('https://example.com/link', $output['rels']['webmention'][1]); - $this->assertEquals('https://example.com/a', $output['rels']['webmention'][2]); + $this->assertArrayHasKey('webmention', $output['rels']); + $this->assertEquals('https://example.com/area', $output['rels']['webmention'][0]); + $this->assertEquals('https://example.com/link', $output['rels']['webmention'][1]); + $this->assertEquals('https://example.com/a', $output['rels']['webmention'][2]); } public function testRelValueOrder3() { - $input = ' + $input = ' @@ -73,25 +73,25 @@ public function testRelValueOrder3() { '; - $parser = new Parser($input); - $output = $parser->parse(); + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayHasKey('webmention', $output['rels']); - $this->assertEquals('https://example.com/link', $output['rels']['webmention'][0]); - $this->assertEquals('https://example.com/a', $output['rels']['webmention'][1]); - $this->assertEquals('https://example.com/area', $output['rels']['webmention'][2]); + $this->assertArrayHasKey('webmention', $output['rels']); + $this->assertEquals('https://example.com/link', $output['rels']['webmention'][0]); + $this->assertEquals('https://example.com/a', $output['rels']['webmention'][1]); + $this->assertEquals('https://example.com/area', $output['rels']['webmention'][2]); } public function testRelValueOnBTag() { - $input = 'this makes no sense'; - $parser = new Parser($input); - $output = $parser->parse(); + $input = 'this makes no sense'; + $parser = new Parser($input); + $output = $parser->parse(); - $this->assertArrayNotHasKey('webmention', $output['rels']); + $this->assertArrayNotHasKey('webmention', $output['rels']); } public function testEnableAlternatesFlagTrue() { - $input = ' + $input = ' post 1 post 2 @@ -99,15 +99,15 @@ public function testEnableAlternatesFlagTrue() { href="https://example.com/fr" media="handheld" hreflang="fr">French mobile homepage'; - $parser = new Parser($input); - $parser->enableAlternates = true; - $output = $parser->parse(); + $parser = new Parser($input); + $parser->enableAlternates = true; + $output = $parser->parse(); - $this->assertArrayHasKey('alternates', $output); + $this->assertArrayHasKey('alternates', $output); } public function testEnableAlternatesFlagFalse() { - $input = ' + $input = ' post 1 post 2 @@ -115,11 +115,11 @@ public function testEnableAlternatesFlagFalse() { href="https://example.com/fr" media="handheld" hreflang="fr">French mobile homepage'; - $parser = new Parser($input); - $parser->enableAlternates = false; - $output = $parser->parse(); + $parser = new Parser($input); + $parser->enableAlternates = false; + $output = $parser->parse(); - $this->assertArrayNotHasKey('alternates', $output); + $this->assertArrayNotHasKey('alternates', $output); } /** @@ -127,7 +127,7 @@ public function testEnableAlternatesFlagFalse() { * @see https://microformats.org/wiki/microformats2-parsing#rel_parse_examples */ public function testRelURLs() { - $input = ' + $input = ' post 1 post 2 @@ -136,40 +136,40 @@ public function testRelURLs() { media="handheld" hreflang="fr">French mobile homepage '; - $parser = new Parser($input); - $output = $parser->parse(); - - $this->assertArrayHasKey('rels', $output); - $this->assertCount(4, $output['rels']); - $this->assertArrayHasKey('author', $output['rels']); - $this->assertArrayHasKey('in-reply-to', $output['rels']); - $this->assertArrayHasKey('alternate', $output['rels']); - $this->assertArrayHasKey('home', $output['rels']); - - $this->assertArrayHasKey('rel-urls', $output); - $this->assertCount(6, $output['rel-urls']); - $this->assertArrayHasKey('https://example.com/a', $output['rel-urls']); - $this->assertArrayHasKey('https://example.com/b', $output['rel-urls']); - $this->assertArrayHasKey('https://example.com/1', $output['rel-urls']); - $this->assertArrayHasKey('https://example.com/2', $output['rel-urls']); - $this->assertArrayHasKey('https://example.com/fr', $output['rel-urls']); - $this->assertArrayHasKey('https://example.com/articles.atom', $output['rel-urls']); - - $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/a']); - $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/a']); - $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/b']); - $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/b']); - $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/1']); - $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/1']); - $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/2']); - $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/2']); - $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/fr']); - $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/fr']); - $this->assertArrayHasKey('media', $output['rel-urls']['https://example.com/fr']); - $this->assertArrayHasKey('hreflang', $output['rel-urls']['https://example.com/fr']); - $this->assertArrayHasKey('title', $output['rel-urls']['https://example.com/articles.atom']); - $this->assertArrayHasKey('type', $output['rel-urls']['https://example.com/articles.atom']); - $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/articles.atom']); + $parser = new Parser($input); + $output = $parser->parse(); + + $this->assertArrayHasKey('rels', $output); + $this->assertCount(4, $output['rels']); + $this->assertArrayHasKey('author', $output['rels']); + $this->assertArrayHasKey('in-reply-to', $output['rels']); + $this->assertArrayHasKey('alternate', $output['rels']); + $this->assertArrayHasKey('home', $output['rels']); + + $this->assertArrayHasKey('rel-urls', $output); + $this->assertCount(6, $output['rel-urls']); + $this->assertArrayHasKey('https://example.com/a', $output['rel-urls']); + $this->assertArrayHasKey('https://example.com/b', $output['rel-urls']); + $this->assertArrayHasKey('https://example.com/1', $output['rel-urls']); + $this->assertArrayHasKey('https://example.com/2', $output['rel-urls']); + $this->assertArrayHasKey('https://example.com/fr', $output['rel-urls']); + $this->assertArrayHasKey('https://example.com/articles.atom', $output['rel-urls']); + + $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/a']); + $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/a']); + $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/b']); + $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/b']); + $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/1']); + $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/1']); + $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/2']); + $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/2']); + $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/fr']); + $this->assertArrayHasKey('text', $output['rel-urls']['https://example.com/fr']); + $this->assertArrayHasKey('media', $output['rel-urls']['https://example.com/fr']); + $this->assertArrayHasKey('hreflang', $output['rel-urls']['https://example.com/fr']); + $this->assertArrayHasKey('title', $output['rel-urls']['https://example.com/articles.atom']); + $this->assertArrayHasKey('type', $output['rel-urls']['https://example.com/articles.atom']); + $this->assertArrayHasKey('rels', $output['rel-urls']['https://example.com/articles.atom']); } /** @@ -177,42 +177,42 @@ public function testRelURLs() { * @see https://github.com/microformats/microformats2-parsing/issues/30 */ public function testRelURLsRelsUniqueAndSorted() { - $input = ' + $input = ' '; - $parser = new Parser($input); - $output = $parser->parse(); - $this->assertEquals($output['rel-urls']['#']['rels'], array('archived', 'bookmark', 'me')); + $parser = new Parser($input); + $output = $parser->parse(); + $this->assertEquals($output['rel-urls']['#']['rels'], array('archived', 'bookmark', 'me')); } public function testRelURLsInfoMergesCorrectly() { - $input = 'This nodeValue + $input = 'This nodeValue Not this nodeValue'; - $parser = new Parser($input); - $output = $parser->parse(); - $this->assertEquals($output['rel-urls']['#']['hreflang'], 'en'); - $this->assertArrayNotHasKey('media', $output['rel-urls']['#']); - $this->assertArrayNotHasKey('title', $output['rel-urls']['#']); - $this->assertArrayNotHasKey('type', $output['rel-urls']['#']); - $this->assertEquals($output['rel-urls']['#']['text'], 'This nodeValue'); + $parser = new Parser($input); + $output = $parser->parse(); + $this->assertEquals($output['rel-urls']['#']['hreflang'], 'en'); + $this->assertArrayNotHasKey('media', $output['rel-urls']['#']); + $this->assertArrayNotHasKey('title', $output['rel-urls']['#']); + $this->assertArrayNotHasKey('type', $output['rel-urls']['#']); + $this->assertEquals($output['rel-urls']['#']['text'], 'This nodeValue'); } public function testRelURLsNoDuplicates() { - $input = ' + $input = ' '; - $parser = new Parser($input); - $output = $parser->parse(); - $this->assertEquals($output['rels']['a'], array('#a', '#b')); + $parser = new Parser($input); + $output = $parser->parse(); + $this->assertEquals($output['rels']['a'], array('#a', '#b')); } public function testRelURLsFalsyTextVSEmpty() { - $input = '0 + $input = '0 '; - $parser = new Parser($input); - $output = $parser->parse(); - $this->assertArrayHasKey('text', $output['rel-urls']['#a']); - $this->assertEquals($output['rel-urls']['#a']['text'], '0'); - $this->assertArrayNotHasKey('text', $output['rel-urls']['#b']); + $parser = new Parser($input); + $output = $parser->parse(); + $this->assertArrayHasKey('text', $output['rel-urls']['#a']); + $this->assertEquals($output['rel-urls']['#a']['text'], '0'); + $this->assertArrayNotHasKey('text', $output['rel-urls']['#b']); } } diff --git a/tests/Mf2/URLTest.php b/tests/Mf2/URLTest.php index 27cb3c1..2da4691 100644 --- a/tests/Mf2/URLTest.php +++ b/tests/Mf2/URLTest.php @@ -10,6 +10,7 @@ use Yoast\PHPUnitPolyfills\TestCases\TestCase; class URLTest extends TestCase { + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps protected function set_up() { date_default_timezone_set('Europe/London'); } @@ -152,9 +153,9 @@ public function testResolvesProtocolRelativeUrlsCorrectly() { * @dataProvider dataProvider */ public function testReturnsUrlIfAbsolute($assert, $base, $url, $expected) { - $actual = mf2\resolveUrl($base, $url); + $actual = mf2\resolveUrl($base, $url); - $this->assertEquals($expected, $actual, $assert); + $this->assertEquals($expected, $actual, $assert); } public function dataProvider() { @@ -265,29 +266,29 @@ public function dataProvider() { // http://tools.ietf.org/html/rfc3986#section-5.4 $rfcTests = array( - array("g:h", "g:h"), - array("g", "http://a/b/c/g"), - array("./g", "http://a/b/c/g"), - array("g/", "http://a/b/c/g/"), - array("/g", "http://a/g"), - array("//g", "http://g"), - array("?y", "http://a/b/c/d;p?y"), - array("g?y", "http://a/b/c/g?y"), - array("#s", "http://a/b/c/d;p?q#s"), - array("g#s", "http://a/b/c/g#s"), - array("g?y#s", "http://a/b/c/g?y#s"), - array(";x", "http://a/b/c/;x"), - array("g;x", "http://a/b/c/g;x"), - array("g;x?y#s", "http://a/b/c/g;x?y#s"), - array("", "http://a/b/c/d;p?q"), - array(".", "http://a/b/c/"), - array("./", "http://a/b/c/"), - array("..", "http://a/b/"), - array("../", "http://a/b/"), - array("../g", "http://a/b/g"), - array("../..", "http://a/"), - array("../../", "http://a/"), - array("../../g", "http://a/g") + array('g:h', 'g:h'), + array('g', 'http://a/b/c/g'), + array('./g', 'http://a/b/c/g'), + array('g/', 'http://a/b/c/g/'), + array('/g', 'http://a/g'), + array('//g', 'http://g'), + array('?y', 'http://a/b/c/d;p?y'), + array('g?y', 'http://a/b/c/g?y'), + array('#s', 'http://a/b/c/d;p?q#s'), + array('g#s', 'http://a/b/c/g#s'), + array('g?y#s', 'http://a/b/c/g?y#s'), + array(';x', 'http://a/b/c/;x'), + array('g;x', 'http://a/b/c/g;x'), + array('g;x?y#s', 'http://a/b/c/g;x?y#s'), + array('', 'http://a/b/c/d;p?q'), + array('.', 'http://a/b/c/'), + array('./', 'http://a/b/c/'), + array('..', 'http://a/b/'), + array('../', 'http://a/b/'), + array('../g', 'http://a/b/g'), + array('../..', 'http://a/'), + array('../../', 'http://a/'), + array('../../g', 'http://a/g') ); foreach($rfcTests as $i=>$test) {