|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package framework |
|
4
|
|
|
* @subpackage tests |
|
5
|
|
|
*/ |
|
6
|
|
|
class AtomFeedTest extends SapphireTest { |
|
7
|
|
|
|
|
8
|
|
|
protected static $original_host; |
|
9
|
|
|
|
|
10
|
|
|
public function testAtomFeed() { |
|
11
|
|
|
$list = new ArrayList(); |
|
12
|
|
|
$list->push(new AtomFeedTest_ItemA()); |
|
13
|
|
|
$list->push(new AtomFeedTest_ItemB()); |
|
14
|
|
|
$list->push(new AtomFeedTest_ItemC()); |
|
15
|
|
|
|
|
16
|
|
|
$atomFeed = new CwpAtomFeed($list, "http://www.example.com", |
|
17
|
|
|
"Test Atom Feed", "Test Atom Feed Description"); |
|
18
|
|
|
$content = $atomFeed->outputToBrowser(); |
|
19
|
|
|
|
|
20
|
|
|
//Debug::message($content); |
|
21
|
|
|
$this->assertContains('<link href="http://www.example.org/item-a/" />', $content); |
|
22
|
|
|
$this->assertContains('<link href="http://www.example.com/item-b.html" />', $content); |
|
23
|
|
|
$this->assertContains('<link href="http://www.example.com/item-c.html" />', $content); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertContains('<title type="html">ItemA</title>', $content); |
|
26
|
|
|
$this->assertContains('<title type="html">ItemB</title>', $content); |
|
27
|
|
|
$this->assertContains('<title type="html">ItemC</title>', $content); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertContains("\tItemA Content\n", $content); |
|
30
|
|
|
$this->assertContains("\tItemB Content\n", $content); |
|
31
|
|
|
$this->assertContains("\tItemC Content\n", $content); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testRenderWithTemplate() { |
|
35
|
|
|
$atomFeed = new CwpAtomFeed(new ArrayList(), "", "", ""); |
|
36
|
|
|
$content = $atomFeed->outputToBrowser(); |
|
37
|
|
|
// test we have switched from a RSS feed test template tot he AtomFeed template |
|
38
|
|
|
$this->assertNotContains('<title>Test Custom Template</title>', $content); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testLinkToFeed() { |
|
42
|
|
|
$link = AtomTags_Test::linkToFeed('atomLinkUrl', 'Atom feed of this blog'); |
|
43
|
|
|
$this->assertContains('atomLinkUrl', $link); |
|
44
|
|
|
$this->assertContains('Atom feed of this blog', $link); |
|
45
|
|
|
$this->assertContains('application/atom+xml', $link); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function setUp() { |
|
49
|
|
|
parent::setUp(); |
|
50
|
|
|
Config::inst()->update('Director', 'alternate_base_url', '/'); |
|
51
|
|
|
if(!self::$original_host) self::$original_host = $_SERVER['HTTP_HOST']; |
|
52
|
|
|
$_SERVER['HTTP_HOST'] = 'www.example.org'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function tearDown() { |
|
56
|
|
|
parent::tearDown(); |
|
57
|
|
|
Config::inst()->update('Director', 'alternate_base_url', null); |
|
58
|
|
|
$_SERVER['HTTP_HOST'] = self::$original_host; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
class AtomFeedTest_ItemA extends ViewableData { |
|
63
|
|
|
// Atom-feed items must have $casting/$db information. |
|
64
|
|
|
private static $casting = array( |
|
|
|
|
|
|
65
|
|
|
'Title' => 'Varchar', |
|
66
|
|
|
'Content' => 'Text', |
|
67
|
|
|
'AltContent' => 'Text', |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
public $Title = 'ItemA'; |
|
71
|
|
|
|
|
72
|
|
|
public function Title() { |
|
73
|
|
|
return "ItemA"; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function Content() { |
|
77
|
|
|
return "ItemA Content"; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function AltContent() { |
|
81
|
|
|
return "ItemA AltContent"; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function Link($action = null) { |
|
85
|
|
|
return Controller::join_links("item-a/", $action); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
class AtomFeedTest_ItemB extends ViewableData { |
|
90
|
|
|
// ItemB tests without $casting |
|
91
|
|
|
|
|
92
|
|
|
public $Title = 'ItemB'; |
|
93
|
|
|
|
|
94
|
|
|
public function Title() { |
|
95
|
|
|
return "ItemB"; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function AbsoluteLink() { |
|
99
|
|
|
return "http://www.example.com/item-b.html"; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function Content() { |
|
103
|
|
|
return "ItemB Content"; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function AltContent() { |
|
107
|
|
|
return "ItemB AltContent"; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
class AtomFeedTest_ItemC extends ViewableData { |
|
112
|
|
|
// ItemC tests fields - Title has casting, Content doesn't. |
|
113
|
|
|
private static $casting = array( |
|
114
|
|
|
'Title' => 'Varchar', |
|
115
|
|
|
'AltContent' => 'Text', |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
public $Title = 'ItemC'; |
|
119
|
|
|
|
|
120
|
|
|
public function Title() { |
|
121
|
|
|
return "ItemC"; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function Content() { |
|
125
|
|
|
return "ItemC Content"; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public $AltContent = "ItemC AltContent"; |
|
129
|
|
|
|
|
130
|
|
|
public function Link() { |
|
131
|
|
|
return "item-c.html"; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function AbsoluteLink() { |
|
135
|
|
|
return "http://www.example.com/item-c.html"; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Class to wrap cwpAtomFeed::linkToFeed so it can be tested |
|
141
|
|
|
* would be better if we could return the tags directly from Requirements |
|
142
|
|
|
* @subpackage tests |
|
143
|
|
|
*/ |
|
144
|
|
|
class AtomTags_Test { |
|
145
|
|
|
public static function linkToFeed($url, $title = null) { |
|
146
|
|
|
$link = '<link rel="alternate" type="application/atom+xml" title="' . $title . |
|
147
|
|
|
'" href="' . $url . '" />'; |
|
148
|
|
|
CwpAtomFeed::linkToFeed($url, $title); |
|
149
|
|
|
return $link; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|