Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/simpletest/testfilelib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 
00027 if (!defined('MOODLE_INTERNAL')) {
00028     die('Direct access to this script is forbidden.');    
00029 }
00030 require_once($CFG->libdir . '/filelib.php');
00031 
00032 class filelib_test extends UnitTestCase {
00033     public function test_format_postdata_for_curlcall() {
00034 
00035         //POST params with just simple types
00036         $postdatatoconvert =array( 'userid' => 1, 'roleid' => 22, 'name' => 'john');
00037         $expectedresult = "userid=1&roleid=22&name=john";
00038         $postdata = format_postdata_for_curlcall($postdatatoconvert);
00039         $this->assertEqual($postdata, $expectedresult);
00040 
00041         //POST params with a string containing & character
00042         $postdatatoconvert =array( 'name' => 'john&emilie', 'roleid' => 22);
00043         $expectedresult = "name=john%26emilie&roleid=22"; //urlencode: '%26' => '&'
00044         $postdata = format_postdata_for_curlcall($postdatatoconvert);
00045         $this->assertEqual($postdata, $expectedresult);
00046 
00047         //POST params with an empty value
00048         $postdatatoconvert =array( 'name' => null, 'roleid' => 22);
00049         $expectedresult = "name=&roleid=22"; 
00050         $postdata = format_postdata_for_curlcall($postdatatoconvert);
00051         $this->assertEqual($postdata, $expectedresult);
00052 
00053         //POST params with complex types
00054         $postdatatoconvert =array( 'users' => array(
00055                         array(
00056                                 'id' => 2,
00057                                 'customfields' => array(
00058                                         array
00059                                         (
00060                                                 'type' => 'Color',
00061                                                 'value' => 'violet'
00062                                         )
00063                                 )
00064                         )
00065                 )
00066         );
00067         $expectedresult = "users[0][id]=2&users[0][customfields][0][type]=Color&users[0][customfields][0][value]=violet";
00068         $postdata = format_postdata_for_curlcall($postdatatoconvert);
00069         $this->assertEqual($postdata, $expectedresult);
00070 
00071         //POST params with other complex types
00072         $postdatatoconvert = array ('members' =>
00073             array(
00074             array('groupid' => 1, 'userid' => 1)
00075             , array('groupid' => 1, 'userid' => 2)
00076                 )
00077             );
00078         $expectedresult = "members[0][groupid]=1&members[0][userid]=1&members[1][groupid]=1&members[1][userid]=2";
00079         $postdata = format_postdata_for_curlcall($postdatatoconvert);
00080         $this->assertEqual($postdata, $expectedresult);
00081     }
00082 
00083     public function test_download_file_content() {
00084         $testhtml = "http://download.moodle.org/unittest/test.html";
00085         $contents = download_file_content($testhtml);
00086         $this->assertEqual('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
00087     }
00088 }
 All Data Structures Namespaces Files Functions Variables Enumerations