Skip to content

Commit

Permalink
Test: add some code coverage for the parentName property
Browse files Browse the repository at this point in the history
  • Loading branch information
macbre committed Jan 7, 2024
1 parent 3d14693 commit 1ffcd75
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/XMLParserCDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ public function testCDataIsProperlyParsed(): void

$this->assertInstanceOf(XMLNodeContent::class, $node);
$this->assertStringStartsWith("<p>\n <a href=\"/mylink/article1\">", trim($node->content));
$this->assertEquals('item', $node->parentName);
}
}
1 change: 1 addition & 0 deletions tests/XMLParserLargeFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testIterateByNodeContent()
foreach($this->getParser()->iterateByNodeContent(name: 'loc') as $node) {
$this->assertInstanceOf(XMLNodeContent::class, $node);
$this->assertEquals('loc', $node->name);
$this->assertEquals('url', $node->parentName);
$this->assertStringStartsWith('http', $node->content);

$cnt++;
Expand Down
3 changes: 3 additions & 0 deletions tests/XMLParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function testParsesTheOpeningTags(): void

$this->assertInstanceOf(XMLNodeOpen::class, $sitemapIndex);
$this->assertEquals('sitemapindex', $sitemapIndex->name);
$this->assertNull($sitemapIndex->parentName, 'Root nodes will get null as their parent');
$this->assertEquals('http://www.sitemaps.org/schemas/sitemap/0.9', $sitemapIndex->attributes['xmlns'] ?? null);
}

Expand All @@ -39,6 +40,7 @@ public function testParsesTheClosingTags(): void

$this->assertInstanceOf(XMLNodeClose::class, $closingTag);
$this->assertEquals('sitemapindex', $closingTag->name);
$this->assertNull($closingTag->parentName);
}

public function testParsesTheLocNodes(): void
Expand All @@ -48,6 +50,7 @@ public function testParsesTheLocNodes(): void
foreach($this->getParser() as $item) {
if ($item instanceof XMLNodeContent && $item->name === 'loc') {
$locations[] = $item->content;
$this->assertEquals('sitemap', $item->parentName);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/XMLParserWhitespacesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ public function testProperlyReportWhitespacesBetweenClosingTags(): void

$this->assertCount(1, $locNodesContent);
$this->assertEquals('https://elecena.pl/sitemap-001-search.xml.gz', $locNodesContent[0]->content);
$this->assertEquals('sitemap', $locNodesContent[0]->parentName);
}
}

0 comments on commit 1ffcd75

Please sign in to comment.