Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/simpletest/testrss.php
Go to the documentation of this file.
00001 <?php
00002 
00003 if (!defined('MOODLE_INTERNAL')) {
00004     die('Direct access to this script is forbidden.');    
00005 }
00006 
00007 /*
00008  * These tests rely on the rsstest.xml file on download.moodle.org,
00009  * from eloys listing:
00010  *   rsstest.xml: One valid rss feed.
00011  *   md5:  8fd047914863bf9b3a4b1514ec51c32c
00012  *   size: 32188
00013  *
00014  * If networking/proxy configuration is wrong these tests will fail..
00015  */
00016 
00017 require_once($CFG->libdir.'/simplepie/moodle_simplepie.php');
00018 
00019 class moodlesimplepie_test extends UnitTestCase {
00020 
00021     public static $includecoverage = array('lib/simplepie/moodle_simplepie.php');
00022 
00023     # A url we know exists and is valid
00024     const VALIDURL = 'http://download.moodle.org/unittest/rsstest.xml';
00025     # A url which we know doesn't exist
00026     const INVALIDURL = 'http://download.moodle.org/unittest/rsstest-which-doesnt-exist.xml';
00027     # This tinyurl redirects to th rsstest.xml file
00028     const REDIRECTURL = 'http://tinyurl.com/lvyslv';
00029 
00030     function setUp() {
00031         moodle_simplepie::reset_cache();
00032     }
00033 
00034     function test_getfeed() {
00035         $feed = new moodle_simplepie(moodlesimplepie_test::VALIDURL);
00036 
00037         $this->assertIsA($feed, 'moodle_simplepie');
00038 
00039         $this->assertFalse($feed->error(), "Failed to load the sample RSS file. Please check your proxy settings in Moodle. %s");
00040         if ($feed->error()) {
00041             return;
00042         }
00043 
00044         $this->assertEqual($feed->get_title(), 'Moodle News');
00045 
00046         $this->assertEqual($feed->get_link(), 'http://moodle.org/mod/forum/view.php?f=1');
00047         $this->assertEqual($feed->get_description(), "General news about Moodle.\n\nMoodle is a leading open-source course management system (CMS) - a software package designed to help educators create quality online courses. Such e-learning systems are sometimes also called Learning Management Systems (LMS) or Virtual Learning Environments (VLE). One of the main advantages of Moodle over other systems is a strong grounding in social constructionist pedagogy.");
00048 
00049         $this->assertEqual($feed->get_copyright(), '&amp;#169; 2007 moodle');
00050         $this->assertEqual($feed->get_image_url(), 'http://moodle.org/pix/i/rsssitelogo.gif');
00051         $this->assertEqual($feed->get_image_title(), 'moodle');
00052         $this->assertEqual($feed->get_image_link(), 'http://moodle.org');
00053         $this->assertEqual($feed->get_image_width(), '140');
00054         $this->assertEqual($feed->get_image_height(), '35');
00055 
00056         $this->assertTrue($items = $feed->get_items());
00057         $this->assertEqual(count($items), 15);
00058 
00059         $this->assertTrue($itemone = $feed->get_item(0));
00060         if (!$itemone) {
00061             return;
00062         }
00063 
00064         $this->assertEqual($itemone->get_title(), 'Google HOP contest encourages pre-University students to work on Moodle');
00065         $this->assertEqual($itemone->get_link(), 'http://moodle.org/mod/forum/discuss.php?d=85629');
00066         $this->assertEqual($itemone->get_id(), 'http://moodle.org/mod/forum/discuss.php?d=85629');
00067         $description = <<<EOD
00068 by Martin Dougiamas. &nbsp;<p><p><img src="http://code.google.com/opensource/ghop/2007-8/images/ghoplogosm.jpg" align="right" style="margin:10px" />After their very successful <a href="http://code.google.com/soc/2007/">Summer of Code</a> program for University students, Google just announced their new <a href="http://code.google.com/opensource/ghop/2007-8/">Highly Open Participation contest</a>, designed to encourage pre-University students to get involved with open source projects via much smaller and diverse contributions.<br />
00069 <br />
00070 I'm very proud that Moodle has been selected as one of only <a href="http://code.google.com/opensource/ghop/2007-8/projects.html">ten open source projects</a> to take part in the inaugural year of this new contest.<br />
00071 <br />
00072 We have a <a href="http://code.google.com/p/google-highly-open-participation-moodle/issues/list">long list of small tasks</a> prepared already for students, but we would definitely like to see the Moodle community come up with more - so if you have any ideas for things you want to see done, please <a href="http://code.google.com/p/google-highly-open-participation-moodle/">send them to us</a>!  Just remember they can't take more than five days.<br />
00073 <br />
00074 Google will pay students US$100 for every three tasks they successfully complete, plus send a cool T-shirt.  There are also grand prizes including an all-expenses-paid trip to Google HQ in Mountain View, California.  If you are (or know) a young student with an interest in Moodle then give it a go! <br />
00075 <br />
00076 You can find out all the details on the <a href="http://code.google.com/p/google-highly-open-participation-moodle/">Moodle/GHOP contest site</a>.</p></p>
00077 EOD;
00078         $this->assertEqual($itemone->get_description(), $description);
00079 
00080 
00081         // TODO fix this so it uses $CFG by default
00082         $this->assertEqual($itemone->get_date('U'), 1196412453);
00083 
00084         // last item
00085         $this->assertTrue($feed->get_item(14));
00086         // Past last item
00087         $this->assertFalse($feed->get_item(15));
00088     }
00089 
00090     /*
00091      * Test retrieving a url which doesn't exist
00092      */
00093     function test_failurl() {
00094         $feed = @new moodle_simplepie(moodlesimplepie_test::INVALIDURL); // we do not want this in php error log
00095 
00096         $this->assertTrue($feed->error());
00097     }
00098 
00099     /*
00100      * Test retrieving a url with broken proxy configuration
00101      */
00102     function test_failproxy() {
00103         global $CFG;
00104 
00105         $oldproxy = $CFG->proxyhost;
00106         $CFG->proxyhost = 'xxxxxxxxxxxxxxx.moodle.org';
00107 
00108         $feed = new moodle_simplepie(moodlesimplepie_test::VALIDURL);
00109 
00110         $this->assertTrue($feed->error());
00111         $this->assertFalse($feed->get_title());
00112         $CFG->proxyhost = $oldproxy;
00113     }
00114 
00115     /*
00116      * Test retrieving a url which sends a redirect to another valid feed
00117      */
00118     function test_redirect() {
00119         global $CFG;
00120 
00121         $feed = new moodle_simplepie(moodlesimplepie_test::REDIRECTURL);
00122 
00123         $this->assertFalse($feed->error());
00124         $this->assertEqual($feed->get_title(), 'Moodle News');
00125         $this->assertEqual($feed->get_link(), 'http://moodle.org/mod/forum/view.php?f=1');
00126     }
00127 
00128 }
 All Data Structures Namespaces Files Functions Variables Enumerations