bolt/Sitemap — pull request #2 by LeonB (2014-11-28 17:19:18+00:00)
Title: Added support for regex ignores

> LBo: I just looked at the sitemap extension
> LBo: Is it true that you can't ignore entry pages at the moment?
> LBo: I have for example /blogs but I don't have /blogs/blog1
> LBo: But the sitemap extension generates a url for each blog item
> LBo: What would be a good way to make the sitemap ignore those?
> LBo: I thought about extending the 'ignore' yml config option with a glob or regex
> Bopp: hi, lbo
> LBo: So you could do something like ignore: [ '/blogs/*']
> Bopp: Sounds good to me.
> LBo: A preference for globs or regex?
> Bopp: regex :-)
> LBo: Ok, great

I tried creating a unit test but I didn't know how to create the tests structure for an extension and I couldn't find an example. I wanted to test it like this:

``` php
public function testIgnoreLinks()
{
$tests = array(
array(
'link' => '/',
'ignore' => '',
'ignored' => false,
),
array(
'link' => '/',
'ignore' => '/',
'ignored' => true,
),
array(
'link' => '/pages',
'ignore' => '/',
'ignored' => false,
),
array(
'link' => '/pages',
'ignore' => '/pages',
'ignored' => true,
),
array(
'link' => '/pages',
'ignore' => '/pages/',
'ignored' => false,
),
array(
'link' => '/pages/test-1',
'ignore' => '/pages/',
'ignored' => false,
),
array(
'link' => '/pages/test-1',
'ignore' => '/pages/.*',
'ignored' => true,
),
array(
'link' => '/pages/test-1',
'ignore' => '/pages/\.*',
'ignored' => false,
),
array(
'link' => '/pages/test-1',
'ignore' => '/pages/test-[2-9]*',
'ignored' => false,
),
array(
'link' => '/pages/test-1',
'ignore' => '/pages/test-[1-9]*',
'ignored' => true,
),
);

foreach ($tests as $test) {
$this->config = array(
'ignore' => array($test['ignore'])
);

$this->assertSame($this->linkIsIgnored($test), $test['ignored']);
}
}
```