Completed
Push — master ( 6dd3a0...ec39b9 )
by Níckolas Daniel
05:32
created

GenerateRobotsTxtFileTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 25
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecuteShouldNotModifyBuilder() 0 9 1
A testExecuteShouldContainTheSitemapString() 0 7 1
A testExecuteShouldContainAnEmptyLineBetweenUserAgentDeclarationAndMultipleAllowsPerUserAgent() 0 26 1
1
<?php
2
3
namespace PODEntender\Application\Service\FileProcessing;
4
5
use PHPUnit\Framework\TestCase;
6
use PODEntender\Domain\Model\FileProcessing\RobotsTxt\RobotsTxt;
7
use PODEntender\Domain\Model\FileProcessing\RobotsTxt\RobotsTxtStringBuilder;
8
use PODEntender\Domain\Model\FileProcessing\RobotsTxt\RulesSetCollection;
9
use PODEntender\Domain\Model\FileProcessing\RobotsTxt\RulesSet;
10
11
class GenerateRobotsTxtFileTest extends TestCase
12
{
13
    public function testExecuteShouldNotModifyBuilder()
14
    {
15
        $robotsTxt = $this->prophesize(RobotsTxt::class);
16
        $builder = $this->prophesize(RobotsTxtStringBuilder::class);
17
        $builder->build($robotsTxt->reveal())
18
            ->willReturn('Built');
19
        $robotsTxtGenerator = new GenerateRobotsTxtFile($builder->reveal());
20
        
21
        $this->assertEquals('Built', $robotsTxtGenerator->execute($robotsTxt->reveal(), '')->content());
22
    }
23
24
    public function testExecuteShouldContainTheSitemapString()
25
    {
26
        $robotsTxt = new RobotsTxt('https://podentender.com/sitemap.xml', new RulesSetCollection());
27
        $builder = new RobotsTxtStringBuilder();
28
        $robotsTxtGenerator = new GenerateRobotsTxtFile($builder);
29
30
        $this->assertEquals('Sitemap: https://podentender.com/sitemap.xml', $robotsTxtGenerator->execute($robotsTxt, '')->content());
31
    }
32
33
    public function testExecuteShouldContainAnEmptyLineBetweenUserAgentDeclarationAndMultipleAllowsPerUserAgent()
34
    {
35
        $firstRuleSet = new RulesSet('*');
36
        $firstRuleSet->addAllowRules(['/home', '/blog']);
37
        $firstRuleSet->addDisallowRules(['/about']);
38
        $secondRuleSet = new RulesSet('AdsBot-Google');
39
        $secondRuleSet->addAllowRules(['/home', '/blog']);
40
        $secondRuleSet->addDisallowRules(['/about']);
41
        $robotsTxt = new RobotsTxt('https://podentender.com/sitemap.xml', new RulesSetCollection([$firstRuleSet, $secondRuleSet]));
42
        $builder = new RobotsTxtStringBuilder();
43
        $robotsTxtGenerator = new GenerateRobotsTxtFile($builder);
44
        $expected = 
45
<<<EOF
46
Sitemap: https://podentender.com/sitemap.xml
47
48
User-Agent: *
49
Allow: /home
50
Allow: /blog
51
Disallow: /about
52
53
User-Agent: AdsBot-Google
54
Allow: /home
55
Allow: /blog
56
Disallow: /about
57
EOF;
58
        $this->assertEquals($expected, $robotsTxtGenerator->execute($robotsTxt, '')->content());
59
    }
60
}
61