RSSMapTest::testChannelDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace Fwk\Xml;
4
5
/**
6
 * Test class for XmlFile.
7
 * Generated by PHPUnit on 2012-07-25 at 22:30:05.
8
 */
9
class RSSMapTest extends \PHPUnit_Framework_TestCase {
10
11
    /**
12
     * @var XmlFile
13
     */
14
    protected $object;
15
16
    /**
17
     * Sets up the fixture, for example, opens a network connection.
18
     * This method is called before a test is executed.
19
     */
20
    protected function setUp() {
21
        $this->object = new XmlFile(__DIR__.'/rss-techcrunch.xml');
22
    }
23
24
    /**
25
     */
26
    public function testExists() {
27
        $this->assertTrue($this->object->exists());
28
    }
29
30
    public function testChannelDescription()
31
    {
32
        $map = new Maps\Rss();
33
        $result = $map->execute($this->object);
34
        
35
        $this->assertTrue(is_array($result));
36
        $this->assertArrayHasKey('channel', $result);
37
        $this->assertTrue(is_array($result['channel']));
38
        
39
        $chan = $result['channel'];
40
        $this->assertArrayHasKey('title', $chan);
41
        $this->assertEquals('TechCrunch', $chan['title']);
42
        
43
        $this->assertTrue(is_array($chan['image']));
44
        $this->assertArrayHasKey('link', $chan['image']);
45
        $this->assertArrayHasKey('url', $chan['image']);
46
        $this->assertArrayHasKey('title', $chan['image']);
47
    }
48
    
49
    public function testChannelItems()
50
    {
51
        $map = new Maps\Rss();
52
        $result = $map->execute($this->object);
53
        
54
        $this->assertTrue(is_array($result));
55
        $this->assertArrayHasKey('items', $result);
56
        $this->assertTrue(is_array($result['items']));
57
        $this->assertEquals(20, count($result['items']));
58
        $this->assertArrayHasKey('title', $result['items'][0]);
59
        $this->assertArrayHasKey('link', $result['items'][0]);
60
        $this->assertArrayHasKey('pubDate', $result['items'][0]);
61
        $this->assertArrayHasKey('categories', $result['items'][0]);
62
        $this->assertTrue(is_array($result['items'][0]['categories']));
63
    }
64
    
65
    public function testWithRegisteredNamespaces()
66
    {
67
        $map = new Maps\Rss();
68
        $result = $map->execute($this->object);
69
        $map->add(Path::factory('/rss/channel/feedburner:feedFlare', 'feedFlare')->loop(true));
70
        
71
        $this->assertTrue(is_array($result));
72
        $this->assertFalse(array_key_exists('feedFlare', $result));
73
        
74
        $map->registerNamespace('feedburner', "http://rssnamespace.org/feedburner/ext/1.0");
75
        $result2 = $map->execute($this->object);
76
        $this->assertArrayHasKey('feedFlare', $result2);
77
    }
78
}
79