コード例 #1
0
$item2Params = array('title' => 'foobaritem', 'pubDate' => '123456', 'link' => 'http://www.example.com');
$image_params = array('title' => 'symfony project', 'link' => 'http://www.symfony-project.org', 'favicon' => 'http://www.symfony-project.org/favicon.ico', 'image' => 'http://www.symfony-project.org/images/symfony_logo.gif', 'faviconX' => '16', 'faviconY' => '16', 'imageX' => '176', 'imageY' => '37');
$feed = new sfAtom1Feed();
$feed->initialize($feedParams);
$feedItem = new sfFeedItem();
$feedItem->initialize($itemParams);
$feed->addItem($feedItem);
$feedItem2 = new sfFeedItem();
$feedItem2->initialize($item2Params);
$feed->addItem($feedItem2);
$feedImage = new sfFeedImage();
$feedImage->initialize($image_params);
$feed->setImage($feedImage);
$t = new lime_test(57, new lime_output_color());
$t->diag('toXML() - generated feed');
$feedString = $feed->toXml();
$feedXml = simplexml_load_string($feedString);
$namespaces = $feedXml->getNamespaces();
$t->ok(in_array('http://www.w3.org/2005/Atom', $namespaces), '<feed> is declared with the proper Atom namespace');
$attributes = $feedXml->attributes('http://www.w3.org/XML/1998/namespace');
preg_match('/^<\\?xml\\s*version="1\\.0"\\s*encoding="(.*?)".*?\\?>$/mi', $feedString, $matches);
$t->is($matches[1], $feed->getEncoding(), 'The encoding is set with the proper feed encoding');
$t->is((string) $attributes['lang'], $feedParams['language'], '<feed> is declared with the proper language');
$t->is((string) $feedXml->title, $feedParams['title'], '<title> contains the proper title');
$t->is((string) $feedXml->link[0]['href'], $feedParams['link'], '<link ref="alternate"> contains the proper link');
$t->is((string) $feedXml->link[1]['href'], $feedParams['feedUrl'], '<link ref="self"> contains the proper link');
$t->is((string) $feedXml->id, $feedParams['link'], '<id> contains the proper id');
$t->is((string) $feedXml->updated, gmstrftime('%Y-%m-%dT%H:%M:%SZ', $item2Params['pubDate']), '<updated> contains the latest publication date of all feed items');
$t->is((string) $feedXml->author->name, $feedParams['authorName'], '<author><name> contains the author name');
$t->is((string) $feedXml->author->email, $feedParams['authorEmail'], '<author><author_email> contains the author email');
$t->is((string) $feedXml->author->uri, $feedParams['authorLink'], '<author><author_link> contains the author link');