-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for local files with file:// schema. (#22)
Using local file vs content of a file ( for parse method ) allows one to use recursive parsing or queue parsing approach and just replace url with local file. Easier for dev time and testing. I also added a test that creates local file in temp. Co-authored-by: Grzegorz Drozd <[email protected]>
- Loading branch information
1 parent
4d144ba
commit 151bcee
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace vipnytt\SitemapParser\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use vipnytt\SitemapParser; | ||
|
||
class RecursiveTest extends TestCase { | ||
|
||
public function testLocalFileXMLFile() | ||
{ | ||
$parser = new SitemapParser('SitemapParser'); | ||
$this->assertInstanceOf('vipnytt\SitemapParser', $parser); | ||
|
||
$tmpfname = tempnam(sys_get_temp_dir(), "sitemap_parser_test_file"); | ||
$fileContent = <<<XMLSITEMAP | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
<sitemap> | ||
<loc>http://www.example.com/sitemap.xml</loc> | ||
<lastmod>2004-10-01T18:23:17+00:00</lastmod> | ||
</sitemap> | ||
</sitemapindex> | ||
XMLSITEMAP; | ||
file_put_contents($tmpfname, $fileContent); | ||
$parser->parse('file:///'.$tmpfname); | ||
$this->assertEquals([ | ||
'http://www.example.com/sitemap.xml' => [ | ||
'loc' => 'http://www.example.com/sitemap.xml', | ||
'lastmod' => '2004-10-01T18:23:17+00:00', | ||
'namespaces' => [], | ||
], | ||
], $parser->getSitemaps()); | ||
} | ||
|
||
} |