NOBUG explaining why textlib sorting fails
[moodle.git] / lib / simpletest / testtextlib.php
CommitLineData
878bcc7f
PS
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Functions to support installation process
20 *
21 * @package core
22 * @subpackage lib
23 * @copyright 2010 Petr Skoda (http://skodak.org)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27defined('MOODLE_INTERNAL') || die();
28
29
30/**
31 * Unit tests for our utf-8 aware text processing
32 *
33 * @package core
34 * @subpackage lib
35 * @copyright 2010 Petr Skoda (http://skodak.org)
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
38class textlib_test extends UnitTestCase {
39
40 public static $includecoverage = array('lib/textlib.class.php');
41
42 public function test_asort() {
43 global $SESSION;
44 $SESSION->lang = 'en'; // make sure we test en language to get consistent results, hopefully all systems have this locale
45
46 $arr = array('b'=>'ab', 1=>'aa', 0=>'cc');
3650b83d
PS
47 textlib_get_instance()->asort($arr);
48 $this->assertIdentical(array_keys($arr), array(1, 'b', 0));
49 $this->assertIdentical(array_values($arr), array('aa', 'ab', 'cc'));
878bcc7f 50
de542ff8
PS
51 if (extension_loaded('intl')) {
52 $error = 'Collation aware sorting not supported';
53 } else {
54 $error = 'Collation aware sorting not supported, PHP extension "intl" is not available.';
55 }
56
878bcc7f 57 $arr = array('a'=>'áb', 'b'=>'ab', 1=>'aa', 0=>'cc');
3650b83d 58 textlib_get_instance()->asort($arr);
de542ff8 59 $this->assertIdentical(array_keys($arr), array(1, 'b', 'a', 0), $error);
878bcc7f
PS
60
61 unset($SESSION->lang);
62 }
63
64}