1 | <?php |
---|
2 | |
---|
3 | require_once 'XML_Feed_Parser_TestCase.php'; |
---|
4 | |
---|
5 | class XML_Feed_Parser_Atom_valueValidity_TestCase extends XML_Feed_Parser_TestCase |
---|
6 | { |
---|
7 | function __construct($name) |
---|
8 | { |
---|
9 | $this->PHPUnit_TestCase($name); |
---|
10 | $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); |
---|
11 | $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'atom10-example2.xml'); |
---|
12 | $this->feed = new XML_Feed_Parser($this->file); |
---|
13 | $this->entry = $this->feed->getEntryByOffset(0); |
---|
14 | } |
---|
15 | |
---|
16 | function test_feedNumberItems() |
---|
17 | { |
---|
18 | $value = 1; |
---|
19 | $this->assertEquals($value, $this->feed->numberEntries); |
---|
20 | } |
---|
21 | |
---|
22 | function test_FeedTitle() |
---|
23 | { |
---|
24 | $value = 'dive into mark'; |
---|
25 | $this->assertEquals($value, $this->feed->title); |
---|
26 | } |
---|
27 | |
---|
28 | function test_feedSubtitle() |
---|
29 | { |
---|
30 | $value = 'A <em>lot</em> of effort |
---|
31 | went into making this effortless'; |
---|
32 | $content = trim($this->feed->subtitle); |
---|
33 | $content = preg_replace('/\t/', ' ', $content); |
---|
34 | $content = preg_replace('/( )+/', ' ', $content); |
---|
35 | $this->assertEquals($content, $value); |
---|
36 | } |
---|
37 | |
---|
38 | function test_feedUpdated() |
---|
39 | { |
---|
40 | $value = strtotime('2005-07-31T12:29:29Z'); |
---|
41 | $this->assertEquals($this->feed->updated, $value); |
---|
42 | } |
---|
43 | |
---|
44 | function test_feedId() |
---|
45 | { |
---|
46 | $value = 'tag:example.org,2003:3'; |
---|
47 | $this->assertEquals($this->feed->id, $value); |
---|
48 | } |
---|
49 | |
---|
50 | function test_feedRights() |
---|
51 | { |
---|
52 | $value = 'Copyright (c) 2003, Mark Pilgrim'; |
---|
53 | $this->assertEquals($this->feed->rights, $value); |
---|
54 | } |
---|
55 | |
---|
56 | function test_feedLinkPlain() |
---|
57 | { |
---|
58 | $value = 'http://example.org/'; |
---|
59 | $this->assertEquals($this->feed->link, $value); |
---|
60 | } |
---|
61 | |
---|
62 | function test_feedLinkAttributes() |
---|
63 | { |
---|
64 | $value = 'self'; |
---|
65 | $link = $this->feed->link(0, 'rel', array('type' => 'application/atom+xml')); |
---|
66 | $this->assertEquals($link, $value); |
---|
67 | } |
---|
68 | |
---|
69 | function test_feedGenerator() |
---|
70 | { |
---|
71 | $value = 'Example Toolkit'; |
---|
72 | $this->assertEquals($value, trim($this->feed->generator)); |
---|
73 | } |
---|
74 | |
---|
75 | function test_entryTitle() |
---|
76 | { |
---|
77 | $value = 'Atom draft-07 snapshot'; |
---|
78 | $this->assertEquals($value, trim($this->entry->title)); |
---|
79 | } |
---|
80 | |
---|
81 | function test_entryLink() |
---|
82 | { |
---|
83 | $value = 'http://example.org/2005/04/02/atom'; |
---|
84 | $this->assertEquals($value, trim($this->entry->link)); |
---|
85 | } |
---|
86 | |
---|
87 | function test_entryId() |
---|
88 | { |
---|
89 | $value = 'tag:example.org,2003:3.2397'; |
---|
90 | $this->assertEquals($value, trim($this->entry->id)); |
---|
91 | } |
---|
92 | function test_entryUpdated() |
---|
93 | { |
---|
94 | $value = strtotime('2005-07-31T12:29:29Z'); |
---|
95 | $this->assertEquals($value, $this->entry->updated); |
---|
96 | } |
---|
97 | |
---|
98 | function test_entryPublished() |
---|
99 | { |
---|
100 | $value = strtotime('2003-12-13T08:29:29-04:00'); |
---|
101 | $this->assertEquals($value, $this->entry->published); |
---|
102 | } |
---|
103 | |
---|
104 | function test_entryContent() |
---|
105 | { |
---|
106 | $value = '<p><i>[Update: The Atom draft is finished.]</i></p>'; |
---|
107 | $content = trim($this->entry->content); |
---|
108 | $content = preg_replace('/\t/', ' ', $content); |
---|
109 | $content = preg_replace('/( )+/', ' ', $content); |
---|
110 | $this->assertEquals($value, $content); |
---|
111 | } |
---|
112 | |
---|
113 | function test_entryAuthorURL() |
---|
114 | { |
---|
115 | $value = 'http://example.org/'; |
---|
116 | $name = $this->entry->author(false, array('param' => 'uri')); |
---|
117 | $this->assertEquals($value, $name); |
---|
118 | } |
---|
119 | |
---|
120 | function test_entryAuthorName() |
---|
121 | { |
---|
122 | $value = 'Mark Pilgrim'; |
---|
123 | $this->assertEquals($value, $this->entry->author); |
---|
124 | } |
---|
125 | |
---|
126 | function test_entryContributor() |
---|
127 | { |
---|
128 | $value = 'Sam Ruby'; |
---|
129 | $this->assertEquals($value, $this->entry->contributor); |
---|
130 | } |
---|
131 | |
---|
132 | function test_entryContributorOffset() |
---|
133 | { |
---|
134 | $value = 'Joe Gregorio'; |
---|
135 | $this->assertEquals($value, $this->entry->contributor(1)); |
---|
136 | } |
---|
137 | |
---|
138 | # According to RFC4287 section 4.2.7.2: |
---|
139 | # [..]If the 'rel' attribute is not present, the link element MUST be |
---|
140 | # interpreted as if the link relation type is "alternate". |
---|
141 | function test_getsLinkWithoutRel() |
---|
142 | { |
---|
143 | $source = '<?xml version="1.0" ?> |
---|
144 | <entry xmlns="http://www.w3.org/2005/Atom"> |
---|
145 | <link href="http://example.org/2005/04/02/atom" /> |
---|
146 | </entry> |
---|
147 | '; |
---|
148 | $feed = new XML_Feed_Parser($source); |
---|
149 | $entry = $feed->getEntryByOffset(0); |
---|
150 | |
---|
151 | // Output |
---|
152 | $this->assertEquals( "http://example.org/2005/04/02/atom", |
---|
153 | $entry->link(0, 'href', array('rel'=>'alternate'))); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | $suite = new PHPUnit_TestSuite('XML_Feed_Parser_Atom_valueValidity_TestCase'); |
---|
158 | $result = PHPUnit::run($suite, '123'); |
---|
159 | echo $result->toString(); |
---|
160 | |
---|
161 | ?> |
---|