Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// +------------------------------------------------------------------------+
3
// | PEAR :: XML_RSS                                                        |
4
// +------------------------------------------------------------------------+
5
// | Copyright (c) 2004 Martin Jansen                                       |
6
// +------------------------------------------------------------------------+
7
// | This source file is subject to version 3.00 of the PHP License,        |
8
// | that is available at http://www.php.net/license/3_0.txt.               |
9
// | If you did not receive a copy of the PHP license and are unable to     |
10
// | obtain it through the world-wide-web, please send a note to            |
11
// | license@php.net so we can mail you a copy immediately.                 |
12
// +------------------------------------------------------------------------+
13
//
14
// $Id: XML_RSS_Parsing_Test.php 310689 2011-05-01 17:54:48Z kguest $
15
//
16
 
17
if (!defined('PHPUnit_MAIN_METHOD')) {
18
    define('PHPUnit_MAIN_METHOD', 'XML_RSS_Parsing_Test::main');
19
}
20
 
21
require_once "PHPUnit/Framework.php";
22
require_once "XML/RSS.php";
23
 
24
/**
25
 * Unit test suite for the XML_RSS package
26
 *
27
 * @author  Martin Jansen <mj@php.net>
28
 * @extends PHPUnit_TestCase
29
 * @version $Id: XML_RSS_Parsing_Test.php 310689 2011-05-01 17:54:48Z kguest $
30
 */
31
class XML_RSS_Parsing_Test extends PHPUnit_Framework_TestCase
32
{
33
    public static function main()
34
    {
35
        require_once 'PHPUnit/TextUI/TestRunner.php';
36
        PHPUnit_TextUI_TestRunner::run(
37
            new PHPUnit_Framework_TestSuite('XML_RSS_Parsing_Test')
38
        );
39
    }
40
 
41
 
42
    function testParseLocalFile() {
43
        $result = array("PHP homepage" => "http://php.net/",
44
                        "PEAR homepage" => "http://pear.php.net/",
45
                        "PHP-GTK homepage" => "http://gtk.php.net/",
46
                        "PHP QA homepage" => "http://qa.php.net/");
47
        $values = array_values($result);
48
        $keys = array_keys($result);
49
        $i = 0;
50
 
51
        $r =& new XML_RSS(dirname(__FILE__) . '/test.rss');
52
        $r->parse();
53
 
54
        $this->assertEquals(count($r->getItems()), 4);
55
 
56
        foreach ($r->getItems() as $value) {
57
            $this->assertEquals($value['title'], $keys[$i]);
58
            $this->assertEquals($value['link'], $values[$i]);
59
            $i++;
60
        }
61
    }
62
 
63
    function testGetStructure()
64
    {
65
        $r =& new XML_RSS(dirname(__FILE__) . '/test.rss');
66
        $r->parse();
67
 
68
		$expected = 'a:7:{i:0;a:4:{s:4:"type";s:7:"channel";s:5:"title";s:4:"Test";s:4:"link";s:20:"http://pear.php.net/";s:11:"description";s:34:"This is a test channel for XML_RSS";}i:1;a:4:{s:4:"type";s:5:"image";s:5:"title";s:4:"PEAR";s:3:"url";s:38:"http://pear.php.net/gifs/pearsmall.gif";s:4:"link";s:20:"http://pear.php.net/";}i:2;a:4:{s:4:"type";s:4:"item";s:5:"title";s:12:"PHP homepage";s:4:"link";s:15:"http://php.net/";s:8:"category";a:1:{i:0;s:3:"php";}}i:3;a:4:{s:4:"type";s:4:"item";s:5:"title";s:13:"PEAR homepage";s:4:"link";s:20:"http://pear.php.net/";s:8:"category";a:2:{i:0;s:3:"php";i:1;s:4:"pear";}}i:4;a:4:{s:4:"type";s:4:"item";s:5:"title";s:16:"PHP-GTK homepage";s:4:"link";s:19:"http://gtk.php.net/";s:8:"category";a:2:{i:0;s:3:"php";i:1;s:3:"gtk";}}i:5;a:4:{s:4:"type";s:4:"item";s:5:"title";s:15:"PHP QA homepage";s:4:"link";s:18:"http://qa.php.net/";s:8:"category";a:2:{i:0;s:3:"php";i:1;s:2:"qa";}}i:6;a:5:{s:4:"type";s:9:"textinput";s:5:"title";s:15:"Search Slashdot";s:11:"description";s:23:"Search Slashdot stories";s:4:"name";s:5:"query";s:4:"link";s:29:"http://slashdot.org/search.pl";}}';
69
        $actual = serialize($r->getStructure());
70
 
71
        $this->assertEquals($expected, $actual);
72
    }
73
 
74
    function testGetStructureFromString()
75
    {
76
        $rss = file_get_contents(dirname(__FILE__) . '/test.rss');
77
        $r =& new XML_RSS($rss);
78
        $r->parse();
79
 
80
		$expected = 'a:7:{i:0;a:4:{s:4:"type";s:7:"channel";s:5:"title";s:4:"Test";s:4:"link";s:20:"http://pear.php.net/";s:11:"description";s:34:"This is a test channel for XML_RSS";}i:1;a:4:{s:4:"type";s:5:"image";s:5:"title";s:4:"PEAR";s:3:"url";s:38:"http://pear.php.net/gifs/pearsmall.gif";s:4:"link";s:20:"http://pear.php.net/";}i:2;a:4:{s:4:"type";s:4:"item";s:5:"title";s:12:"PHP homepage";s:4:"link";s:15:"http://php.net/";s:8:"category";a:1:{i:0;s:3:"php";}}i:3;a:4:{s:4:"type";s:4:"item";s:5:"title";s:13:"PEAR homepage";s:4:"link";s:20:"http://pear.php.net/";s:8:"category";a:2:{i:0;s:3:"php";i:1;s:4:"pear";}}i:4;a:4:{s:4:"type";s:4:"item";s:5:"title";s:16:"PHP-GTK homepage";s:4:"link";s:19:"http://gtk.php.net/";s:8:"category";a:2:{i:0;s:3:"php";i:1;s:3:"gtk";}}i:5;a:4:{s:4:"type";s:4:"item";s:5:"title";s:15:"PHP QA homepage";s:4:"link";s:18:"http://qa.php.net/";s:8:"category";a:2:{i:0;s:3:"php";i:1;s:2:"qa";}}i:6;a:5:{s:4:"type";s:9:"textinput";s:5:"title";s:15:"Search Slashdot";s:11:"description";s:23:"Search Slashdot stories";s:4:"name";s:5:"query";s:4:"link";s:29:"http://slashdot.org/search.pl";}}';
81
        $actual = serialize($r->getStructure());
82
 
83
        $this->assertEquals($expected, $actual);
84
    }
85
 
86
    function testGetChannelInfo()
87
    {
88
        $r =& new XML_RSS(dirname(__FILE__) . '/test.rss');
89
        $r->parse();
90
 
91
        $expected = array(
92
            'title'         => 'Test',
93
            'link'          => 'http://pear.php.net/',
94
            'description'   => 'This is a test channel for XML_RSS'
95
        );
96
 
97
        $actual = $r->getChannelInfo();
98
 
99
        $this->assertEquals($expected, $actual);
100
    }
101
 
102
    function testGetItems()
103
    {
104
        $r =& new XML_RSS(dirname(__FILE__) . '/test.rss');
105
        $r->parse();
106
 
107
        $expected = array();
108
        $expected[] = array(
109
			'title' => 'PHP homepage',
110
			'link' => 'http://php.net/',
111
			'category' => array('php')
112
			);
113
        $expected[] = array(
114
			'title' => 'PEAR homepage',
115
			'link' => 'http://pear.php.net/',
116
			'category' => array('php', 'pear')
117
			);
118
        $expected[] = array(
119
			'title' => 'PHP-GTK homepage',
120
			'link' => 'http://gtk.php.net/',
121
			'category' => array('php', 'gtk')
122
			);
123
        $expected[] = array(
124
			'title' => 'PHP QA homepage',
125
			'link' => 'http://qa.php.net/',
126
			'category' => array('php', 'qa')
127
			);
128
 
129
        $actual = $r->getItems();
130
 
131
        $this->assertEquals($expected, $actual);
132
    }
133
 
134
    function testGetImages()
135
    {
136
        $r =& new XML_RSS(dirname(__FILE__) . '/test.rss');
137
        $r->parse();
138
 
139
        $expected = array();
140
        $expected[] = array(
141
            'title' => 'PEAR',
142
            'url'   => 'http://pear.php.net/gifs/pearsmall.gif',
143
            'link'  => 'http://pear.php.net/'
144
        );
145
 
146
        $actual = $r->getImages();
147
 
148
        $this->assertEquals($expected, $actual);
149
    }
150
 
151
    function testGetTextinputs()
152
    {
153
        $r =& new XML_RSS(dirname(__FILE__) . '/test.rss');
154
        $r->parse();
155
 
156
        $expected = array(
157
            'title'         => 'Search Slashdot',
158
            'description'   => 'Search Slashdot stories',
159
            'name'          => 'query',
160
            'link'          => 'http://slashdot.org/search.pl'
161
        );
162
 
163
        $actual = $r->getTextinputs();
164
 
165
        $this->assertEquals($expected, $actual);
166
    }
167
 
168
}
169
 
170
 
171
if (PHPUnit_MAIN_METHOD == 'XML_RSS_Parsing_Test::main') {
172
    XML_RSS_Parsing_Test::main();
173
}
174
?>