Skip to content

Commit 65d7c0c

Browse files
committed
Bug fix and a new test
- Updated UserAgent string with correct version number. - Added test for stripping of XML comments - Enabled tests for PHP 7.4
1 parent 102939d commit 65d7c0c

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
sudo: false
22
language: php
33
php:
4+
- 7.4
45
- 7.3
56
- 7.2
67
- 7.1

src/SitemapParser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace vipnytt;
44

55
use GuzzleHttp;
6+
use Psr\Http\Message\StreamInterface;
67
use SimpleXMLElement;
78
use vipnytt\SitemapParser\Exceptions;
89
use vipnytt\SitemapParser\UrlParser;
@@ -23,7 +24,7 @@ class SitemapParser
2324
/**
2425
* Default User-Agent
2526
*/
26-
const DEFAULT_USER_AGENT = 'SitemapParser-VIPnytt/1.0 (+https://github.com/VIPnytt/SitemapParser/blob/master/README.md)';
27+
const DEFAULT_USER_AGENT = 'SitemapParser-VIPnytt/1.1 (+https://github.com/VIPnytt/SitemapParser/blob/master/README.md)';
2728

2829
/**
2930
* Default encoding
@@ -213,7 +214,7 @@ protected function clean()
213214
/**
214215
* Request the body content of an URL
215216
*
216-
* @return string Raw body content
217+
* @return StreamInterface Returns the body as a stream.
217218
* @throws Exceptions\TransferException
218219
* @throws Exceptions\SitemapParserException
219220
*/

tests/StripCommentsTest.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace vipnytt\SitemapParser\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use vipnytt\SitemapParser;
7+
8+
class StripCommentsTest extends TestCase
9+
{
10+
/**
11+
* @dataProvider generateDataForTest
12+
* @param string $url URL
13+
* @param string $body URL body content
14+
*/
15+
public function testStrict($url, $body)
16+
{
17+
$parser = new SitemapParser();
18+
$this->assertInstanceOf('vipnytt\SitemapParser', $parser);
19+
$parser->parse($url, $body);
20+
$this->assertEquals([
21+
'https://www.bellinghambaymarathon.org/post-sitemap.xml' => [
22+
'loc' => 'https://www.bellinghambaymarathon.org/post-sitemap.xml',
23+
'lastmod' => '2019-07-19T10:18:07-07:00'
24+
],
25+
'https://www.bellinghambaymarathon.org/page-sitemap.xml' => [
26+
'loc' => 'https://www.bellinghambaymarathon.org/page-sitemap.xml',
27+
'lastmod' => '2019-07-29T06:51:35-07:00'
28+
],
29+
'https://www.bellinghambaymarathon.org/category-sitemap.xml' => [
30+
'loc' => 'https://www.bellinghambaymarathon.org/category-sitemap.xml',
31+
'lastmod' => '2019-07-19T10:18:07-07:00'
32+
],
33+
'https://www.bellinghambaymarathon.org/post_tag-sitemap.xml' => [
34+
'loc' => 'https://www.bellinghambaymarathon.org/post_tag-sitemap.xml',
35+
'lastmod' => '2019-05-16T10:06:14-07:00'
36+
],
37+
'https://www.bellinghambaymarathon.org/author-sitemap.xml' => [
38+
'loc' => 'https://www.bellinghambaymarathon.org/author-sitemap.xml',
39+
'lastmod' => '2018-08-22T17:12:52-07:00'
40+
],
41+
], $parser->getSitemaps());
42+
$this->assertEquals([], $parser->getURLs());
43+
}
44+
45+
/**
46+
* Generate test data
47+
* @return array
48+
*/
49+
public function generateDataForTest()
50+
{
51+
return [
52+
[
53+
'https://www.bellinghambaymarathon.org/sitemap_index.xml',
54+
<<<TEXT
55+
<!-- This page is cached by the Hummingbird Performance plugin v2.0.1 - https://wordpress.org/plugins/hummingbird-performance/. -->
56+
<?xml version="1.0" encoding="UTF-8"?>
57+
<?xml-stylesheet type="text/xsl" href="//www.bellinghambaymarathon.org/main-sitemap.xsl"?>
58+
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
59+
<sitemap>
60+
<loc>https://www.bellinghambaymarathon.org/post-sitemap.xml</loc>
61+
<lastmod>2019-07-19T10:18:07-07:00</lastmod>
62+
</sitemap>
63+
<sitemap>
64+
<loc>https://www.bellinghambaymarathon.org/page-sitemap.xml</loc>
65+
<lastmod>2019-07-29T06:51:35-07:00</lastmod>
66+
</sitemap>
67+
<sitemap>
68+
<loc>https://www.bellinghambaymarathon.org/category-sitemap.xml</loc>
69+
<lastmod>2019-07-19T10:18:07-07:00</lastmod>
70+
</sitemap>
71+
<sitemap>
72+
<loc>https://www.bellinghambaymarathon.org/post_tag-sitemap.xml</loc>
73+
<lastmod>2019-05-16T10:06:14-07:00</lastmod>
74+
</sitemap>
75+
<sitemap>
76+
<loc>https://www.bellinghambaymarathon.org/author-sitemap.xml</loc>
77+
<lastmod>2018-08-22T17:12:52-07:00</lastmod>
78+
</sitemap>
79+
</sitemapindex>
80+
<!-- XML Sitemap generated by Yoast SEO --><!-- Hummingbird cache file was created in 1.061126947403 seconds, on 01-08-19 23:06:50 -->
81+
TEXT
82+
]
83+
];
84+
}
85+
}

0 commit comments

Comments
 (0)