Browse Source

Basic XML parser tests

master
J. King 4 years ago
parent
commit
91e2832a34
  1. 2
      lib/Parser/XML/Feed.php
  2. 30
      tests/cases/XML/XMLTest.php
  3. 6
      tests/cases/XML/feed-atom.yaml
  4. 8
      tests/cases/XML/feed-rss0.yaml
  5. 8
      tests/cases/XML/feed-rss1.yaml
  6. 6
      tests/cases/XML/feed-rss2.yaml
  7. 3
      tests/phpunit.dist.xml

2
lib/Parser/XML/Feed.php

@ -30,7 +30,7 @@ class Feed implements \MensBeam\Lax\Parser\Feed {
protected $xpath;
/** Constructs a parsed feed */
public function __construct(string $data, string $contentType = "", string $url = "") {
public function __construct(string $data, string $contentType = null, string $url = null) {
$this->data = $data;
$this->contentType = $contentType;
if (strlen($url ?? "")) {

30
tests/cases/XML/XMLTest.php

@ -0,0 +1,30 @@
<?php
/** @license MIT
* Copyright 2018 J. King
* See LICENSE and AUTHORS files for details */
declare(strict_types=1);
namespace MensBeam\Lax\TestCase\XML;
/**
* @covers MensBeam\Lax\Parser\Construct<extended>
* @covers MensBeam\Lax\Parser\XML\Feed<extended>
* @covers MensBeam\Lax\Parser\XML\Entry<extended>
*/
class XMLTest extends \MensBeam\Lax\TestCase\AbstractParserTestCase {
/** @dataProvider provideXML */
public function testParseAnXmlFeed(string $input, string $type, ?string $url, $exp): void {
$p = new \MensBeam\Lax\Parser\XML\Feed($input, $type, $url);
if ($exp instanceof \Exception) {
$this->expectExceptionObject($exp);
$p->parse();
} else {
$act = $p->parse();
$this->assertEquals($exp, $act);
}
}
public function provideXML(): iterable {
return $this->provideParserTests(__DIR__."/*.yaml");
}
}

6
tests/cases/XML/feed-atom.yaml

@ -0,0 +1,6 @@
Minimal Atom feed:
input: >
<feed xmlns="http://www.w3.org/2005/Atom"/>
output:
format: atom
version: '1.0'

8
tests/cases/XML/feed-rss0.yaml

@ -0,0 +1,8 @@
Minimal RSS 0.90 feed:
input : >
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://channel.netscape.com/rdf/simple/0.9/">
<channel/>
</rdf:RDF>
output:
format: rdf
version: '0.90'

8
tests/cases/XML/feed-rss1.yaml

@ -0,0 +1,8 @@
Minimal RSS 1.0 feed:
input : >
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/">
<channel/>
</rdf:RDF>
output:
format: rdf
version: '1.0'

6
tests/cases/XML/feed-rss2.yaml

@ -0,0 +1,6 @@
Minimal RSS 1.0 feed:
input : >
<rss version="2.0"/>
output:
format: rss
version: '2.0'

3
tests/phpunit.dist.xml

@ -22,6 +22,9 @@
<testsuite name="JSON">
<directory>cases/JSON</directory>
</testsuite>
<testsuite name="XML">
<directory>cases/XML</directory>
</testsuite>
<testsuite name="Util">
<directory>cases/Util</directory>
</testsuite>

Loading…
Cancel
Save