Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/scorm/simpletest/test_formatduration.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 if (!defined('MOODLE_INTERNAL')) {
00018     die('Direct access to this script is forbidden.'); //  It must be included from a Moodle page
00019 }
00020 
00021 // Unit tests for scorm_formatduration function from locallib.php
00022 
00023 // Make sure the code being tested is accessible.
00024 require_once($CFG->dirroot . '/mod/scorm/locallib.php'); // Include the code to test
00025 
00026 class scorm_formatduration_test extends UnitTestCase {
00027     function test_scorm2004_format() {
00028         $stryears = get_string('years');
00029         $strmonths = trim(get_string('nummonths'));
00030         $strdays = get_string('days');
00031         $strhours = get_string('hours');
00032         $strminutes = get_string('minutes');
00033         $strseconds = get_string('seconds');
00034 
00035         $SUTs = array(1=>'PT001H012M0043.12S', 2=>'PT15.3S', 3=>'P01Y02M5DT0H7M', 4=>'P0Y0M0DT0H1M00.00S',
00036                       5=>'P1YT15M00.01S', 6=>'P0Y0M0DT0H0M0.0S', 7=>'P1MT4M0.30S', 8=>'PT', 9=>'P1DT2H3S', 10=>'P4M');
00037         $validates = array(1=>"1 $strhours 12 $strminutes 43.12 $strseconds", 2=>"15.3 $strseconds", 3=>"1 $stryears 2 $strmonths 5 $strdays 7 $strminutes ",
00038                            4=>"1 $strminutes ", 5=>"1 $stryears 15 $strminutes 0.01 $strseconds", 6=>'', 7=>"1 $strmonths 4 $strminutes 0.30 $strseconds",
00039                            8=>'', 9=>"1 $strdays 2 $strhours 3 $strseconds", 10=>"4 $strmonths ");
00040         foreach ($SUTs as $key => $SUT) {
00041             $formatted = scorm_format_duration($SUT);
00042             $this->assertEqual($formatted, $validates[$key]);
00043         }
00044     }
00045 
00046     function test_scorm12_format() {
00047         $stryears = get_string('years');
00048         $strmonths =  trim(get_string('nummonths'));
00049         $strdays = get_string('days');
00050         $strhours = get_string('hours');
00051         $strminutes = get_string('minutes');
00052         $strseconds = get_string('seconds');
00053 
00054         $SUTs = array(1=>'00:00:00', 2=>'1:2:3', 3=>'12:34:56.78', 4=>'00:12:00.03', 5=>'01:00:23', 6=>'00:12:34.00',
00055                       7=>'00:01:02.03', 8=>'00:00:00.1', 9=>'1:23:00', 10=>'2:00:00');
00056         $validates = array(1=>'', 2=>"1 $strhours 2 $strminutes 3 $strseconds", 3=>"12 $strhours 34 $strminutes 56.78 $strseconds",
00057                            4=>"12 $strminutes 0.03 $strseconds", 5=>"1 $strhours 23 $strseconds", 6=>"12 $strminutes 34 $strseconds",
00058                            7=>"1 $strminutes 2.03 $strseconds", 8=>"0.1 $strseconds", 9=>"1 $strhours 23 $strminutes ", 10=>"2 $strhours ");
00059         foreach ($SUTs as $key => $SUT) {
00060             $formatted = scorm_format_duration($SUT);
00061             $this->assertEqual($formatted, $validates[$key]);
00062         }
00063     }
00064 
00065     function test_non_datetime() {
00066     }
00067 }
 All Data Structures Namespaces Files Functions Variables Enumerations