1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46:
47: class AlphaFeed_Test extends PHPUnit_Framework_TestCase {
48: 49: 50: 51: 52:
53: private $BO;
54:
55: 56: 57: 58: 59: 60: 61:
62: protected function setUp() {
63: $denum = new DEnum();
64: $denum->rebuildTable();
65:
66: $item = new DEnumItem();
67: $item->rebuildTable();
68:
69: $this->BO = new ArticleObject();
70: $this->BO->set('title', 'Test Article Title');
71: $this->BO->set('description', 'Test Article Description');
72: $this->BO->set('created_ts', '2011-01-01 00:00:00');
73: }
74:
75: 76: 77: 78: 79: 80: 81:
82: protected function tearDown() {
83: unset($this->BO);
84:
85: $denum = new DEnum();
86: $denum->dropTable();
87:
88: $item = new DEnumItem();
89: $item->dropTable();
90: }
91:
92: public function testAddItemToRSSandParse() {
93: $feed = new RSS('ArticleObject', 'Test Feed Title', 'http://www.alphaframework.org/', 'Test Feed Description');
94: $feed->setFieldMappings('title', 'URL', 'description', 'created_ts', 'OID');
95: $feed->addBO($this->BO);
96: $xml = $feed->render();
97:
98: $reader = new XMLReader();
99: $validXML = $reader->XML($xml);
100:
101: $this->assertTrue($validXML, 'Confirming that the generated XML can be parsed correctly');
102:
103: $simpleXML = new SimpleXMLElement($xml);
104: $simpleXML->registerXPathNamespace('rss', 'http://purl.org/rss/1.0/');
105:
106: $channels = $simpleXML->xpath('//rss:channel');
107: $this->assertEquals('Test Feed Title', (string)$channels[0]->title, 'Testing that the feed title is present');
108: $this->assertEquals('http://www.alphaframework.org/', (string)$channels[0]->link, 'Testing that the feed URL is present');
109:
110: $items = $simpleXML->xpath('//rss:item');
111: $this->assertEquals('Test Article Title', (string)$items[0]->title, 'Testing that the feed item title is present');
112: $this->assertEquals('Test Article Description', (string)$items[0]->description, 'Testing that the feed item description is present');
113: $this->assertEquals('2011-01-01T00:00:00+00:00', (string)$items[0]->updated, 'Testing that the feed item publish time is present');
114: }
115:
116: public function testAddItemToRSS2andParse() {
117: $feed = new RSS2('ArticleObject', 'Test Feed Title', 'http://www.alphaframework.org/', 'Test Feed Description');
118: $feed->setFieldMappings('title', 'URL', 'description', 'created_ts', 'OID');
119: $feed->addBO($this->BO);
120: $xml = $feed->render();
121:
122: $reader = new XMLReader();
123: $validXML = $reader->XML($xml);
124:
125: $this->assertTrue($validXML, 'Confirming that the generated XML can be parsed correctly');
126:
127: $simpleXML = new SimpleXMLElement($xml);
128:
129: $channels = $simpleXML->xpath('channel');
130: $this->assertEquals('Test Feed Title', (string)$channels[0]->title, 'Testing that the feed title is present');
131: $this->assertEquals('http://www.alphaframework.org/', (string)$channels[0]->link, 'Testing that the feed URL is present');
132:
133: $items = $simpleXML->xpath('channel/item');
134: $this->assertEquals('Test Article Title', (string)$items[0]->title, 'Testing that the feed item title is present');
135: $this->assertEquals('Test Article Description', (string)$items[0]->description, 'Testing that the feed item description is present');
136: $this->assertEquals('2011-01-01T00:00:00+00:00', (string)$items[0]->updated, 'Testing that the feed item publish time is present');
137: }
138:
139: public function testAddItemToAtomandParse() {
140: $feed = new Atom('ArticleObject', 'Test Feed Title', 'http://www.alphaframework.org/', 'Test Feed Description');
141: $feed->setFieldMappings('title', 'URL', 'description', 'created_ts', 'OID');
142: $feed->addBO($this->BO);
143: $xml = $feed->render();
144:
145: $reader = new XMLReader();
146: $validXML = $reader->XML($xml);
147:
148: $this->assertTrue($validXML, 'Confirming that the generated XML can be parsed correctly');
149:
150: $simpleXML = new SimpleXMLElement($xml);
151: $simpleXML->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
152:
153: $feeds = $simpleXML->xpath('//atom:feed');
154: $this->assertEquals('Test Feed Title', (string)$feeds[0]->title, 'Testing that the feed title is present');
155: $this->assertEquals('http://www.alphaframework.org/', (string)$feeds[0]->link->attributes()->href, 'Testing that the feed URL is present');
156:
157: $items = $simpleXML->xpath('//atom:entry');
158: $this->assertEquals('Test Article Title', (string)$items[0]->title, 'Testing that the feed item title is present');
159: $this->assertEquals('Test Article Description', (string)$items[0]->summary, 'Testing that the feed item description is present');
160: $this->assertEquals('2011-01-01T00:00:00+00:00', (string)$items[0]->updated, 'Testing that the feed item publish time is present');
161: }
162: }
163:
164: ?>