/[drupal]/contributions/modules/timeline/tests/feed.test
ViewVC logotype

Contents of /contributions/modules/timeline/tests/feed.test

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sun Jul 6 01:29:46 2008 UTC (16 months, 2 weeks ago) by jmiccolis
Branch: MAIN
CVS Tags: DRUPAL-6--2-1, DRUPAL-6--2-0, DRUPAL-6--2-0-BETA1, DRUPAL-6--2-0-BETA2, DRUPAL-6--2-0-BETA3, DRUPAL-6--2-0-BETA4, HEAD
Branch point for: DRUPAL-6--1, DRUPAL-6--2
Changes since 1.1: +3 -3 lines
File MIME type: text/x-php
Bringing HEAD in sync with the DRUPAL-5 branch in prep for Drupal 6 development.
1 <?php
2 // $Id: feed.test,v 1.1 2006/10/21 20:34:21 arto Exp $
3
4 /**
5 * @file
6 * Unit tests for verifying the well-formedness of the data feeds provided by the timeline module.
7 */
8
9 class feed_test extends DrupalTestCase {
10
11 function get_info() {
12 return array(
13 'name' => t('Data feeds'),
14 'desc' => t('Verifies that the JSON and XML timeline data feeds provided by the module work as intended and output well-formed data.'),
15 'group' => 'Timeline',
16 );
17 }
18
19 function setup() { return parent::setup(); }
20
21 function teardown() { return parent::teardown(); }
22
23 function test_get_timezone() {
24 $timezone = timeline_get_timezone();
25 $this->assertIsA($timezone, 'integer');
26 }
27
28 function test_format_date() {
29 $date = timeline_format_iso8601_date(time());
30 $this->assertIsA($date, 'string');
31 $this->assertWantedPattern('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/', $date);
32 }
33
34 function test_data() {
35 $view_name = 'timeline_nodes';
36 $view = views_get_view($view_name);
37 $this->assertIsA($view, 'stdclass');
38
39 $events = timeline_data($view);
40 $this->assertIsA($events, 'array');
41
42 foreach ($events as $event) {
43 $this->assertIsA($event, 'array');
44 $this->assertTrue(!empty($event['title']), 'event->title is not empty');
45 $this->assertTrue(!empty($event['start']), 'event->start is not empty');
46 $this->assertTrue(!empty($event['link']), 'event->link is not empty');
47 $this->assertTrue(isset($event['description']), 'event->description is set');
48 }
49 }
50
51 function test_json_feed() {
52 $this->setMaximumRedirects(0);
53 $data = $this->get(url('timeline/json', 'view=timeline_nodes', NULL, TRUE));
54
55 $this->assertResponse(200);
56 $this->assertMime('application/json; charset=utf-8');
57 $this->assertTrue(!empty($data));
58
59 // TODO: parse JSON to ensure it is well-formed.
60 }
61
62 function test_xml_feed() {
63 $this->setMaximumRedirects(0);
64 $data = $this->get(url('timeline/xml', 'view=timeline_nodes', NULL, TRUE));
65
66 $this->assertResponse(200);
67 $this->assertMime('text/xml; charset=utf-8');
68 $this->assertTrue(!empty($data));
69
70 $xml_parser = drupal_xml_parser_create($data);
71 $this->assertIsA($xml_parser, 'resource');
72
73 // Simply test that it is possible to parse the XML; this could be improved.
74 $blackhole = create_function('', 'return;');
75 xml_set_element_handler($xml_parser, $blackhole, $blackhole);
76 xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1);
77
78 $result = xml_parse($xml_parser, $data, TRUE);
79 $this->assertTrue($result, 'parsing XML failed (' . xml_error_string(xml_get_error_code($xml_parser)) . ')');
80
81 xml_parser_free($xml_parser);
82 }
83
84 }

  ViewVC Help
Powered by ViewVC 1.1.2