AtomFeedTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
c 1
b 0
f 0
dl 0
loc 64
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testRenderWithTemplate() 0 6 1
A testAtomFeed() 0 27 1
A tearDown() 0 5 1
A testLinkToFeed() 0 6 1
A setUp() 0 8 2
1
<?php
2
3
namespace CWP\Core\Tests;
4
5
use CWP\Core\Feed\CwpAtomFeed;
6
use CWP\Core\Tests\AtomFeedTest\AtomTagsStub;
7
use CWP\Core\Tests\AtomFeedTest\ItemA;
8
use CWP\Core\Tests\AtomFeedTest\ItemB;
9
use CWP\Core\Tests\AtomFeedTest\ItemC;
10
use SilverStripe\Control\Director;
11
use SilverStripe\Core\Config\Config;
12
use SilverStripe\Dev\SapphireTest;
13
use SilverStripe\ORM\ArrayList;
14
15
class AtomFeedTest extends SapphireTest
16
{
17
    protected static $original_host;
18
19
    public function testAtomFeed()
20
    {
21
        $list = new ArrayList();
22
        $list->push(new ItemA());
23
        $list->push(new ItemB());
24
        $list->push(new ItemC());
25
26
        $atomFeed = new CwpAtomFeed(
27
            $list,
28
            "http://www.example.com",
29
            "Test Atom Feed",
30
            "Test Atom Feed Description"
31
        );
32
        $content = $atomFeed->outputToBrowser();
33
34
        //Debug::message($content);
35
        $this->assertContains('<link href="http://www.example.org/item-a/" />', $content);
36
        $this->assertContains('<link href="http://www.example.com/item-b.html" />', $content);
37
        $this->assertContains('<link href="http://www.example.com/item-c.html" />', $content);
38
39
        $this->assertContains('<title type="html">ItemA</title>', $content);
40
        $this->assertContains('<title type="html">ItemB</title>', $content);
41
        $this->assertContains('<title type="html">ItemC</title>', $content);
42
43
        $this->assertContains("\tItemA Content\n", $content);
44
        $this->assertContains("\tItemB Content\n", $content);
45
        $this->assertContains("\tItemC Content\n", $content);
46
    }
47
48
    public function testRenderWithTemplate()
49
    {
50
        $atomFeed = new CwpAtomFeed(new ArrayList(), "", "", "");
51
        $content = $atomFeed->outputToBrowser();
52
        // test we have switched from a RSS feed test template tot he AtomFeed template
53
        $this->assertNotContains('<title>Test Custom Template</title>', $content);
54
    }
55
56
    public function testLinkToFeed()
57
    {
58
        $link = AtomTagsStub::linkToFeed('atomLinkUrl', 'Atom feed of this blog');
59
        $this->assertContains('atomLinkUrl', $link);
60
        $this->assertContains('Atom feed of this blog', $link);
61
        $this->assertContains('application/atom+xml', $link);
62
    }
63
64
    protected function setUp()
65
    {
66
        parent::setUp();
67
        Config::modify()->set(Director::class, 'alternate_base_url', '/');
68
        if (!self::$original_host) {
69
            self::$original_host = $_SERVER['HTTP_HOST'];
70
        }
71
        $_SERVER['HTTP_HOST'] = 'www.example.org';
72
    }
73
74
    protected function tearDown()
75
    {
76
        parent::tearDown();
77
        Config::modify()->set(Director::class, 'alternate_base_url', null);
78
        $_SERVER['HTTP_HOST'] = self::$original_host;
79
    }
80
}
81