bopoda / robots-txt-parser

PHP class for parse all directives from robots.txt files according to specifications
http://robots.jeka.by
MIT License
44 stars 17 forks source link

Get Url sitemaps: added getSitemaps method. Resolve #7 #8

Closed bopoda closed 7 years ago

bopoda commented 7 years ago

Resolve https://github.com/bopoda/robots-txt-parser/issues/7

LeMoussel commented 7 years ago

You can do Test like this

<?php
class SitemapsTest extends \PHPUnit_Framework_TestCase
{
    public static function setUpBeforeClass()
    {
        require_once(realpath(__DIR__.'/../RobotsTxtParser.php'));
    }

    /**
     * @dataProvider generateDataForTest
     */
    public function testRemoveComments($robotsTxtContent)
    {
        $parser = new RobotsTxtParser($robotsTxtContent);
        $this->assertInstanceOf('RobotsTxtParser', $parser);
        // Check if the number of sitemaps is 1
        $this->assertTrue(count($parser->getSitemaps()) == 1);
    }

    /**
     * Generate test case data
     *
     * @return array
     */
    public function generateDataForTest()
    {
        return array(
        array("
        Sitemap: http://example.com/sitemap.xml?year=2017
        Sitemap: http://example.com/sitemap.xml?year=2017
        Sitemap: http://example.com/sitemap.xml?year=2017
            ")
        );
    }
}
bopoda commented 7 years ago

ok, i will add this test soon. It should work as expected now because array_unique called in prepareRules before.

bopoda commented 7 years ago

@LeMoussel, test added in commit https://github.com/bopoda/robots-txt-parser/commit/c03c6567ec80c8b7ef21a499fe622c230529d02d, test passed.