Moodle

Errors in unit tests when language is not English (EN)

Details

Description

Many errors when running unit tests with other languages than English (EN)

Issue Links

Activity

Hide
Michael de Raadt added a comment -

I'm not sure if these errors are caused by the way the unit tests are written or because of the collation used in your DB. Eloy might be able to comment on this.

Your suggested improvements are worth looking at.

Show
Michael de Raadt added a comment - I'm not sure if these errors are caused by the way the unit tests are written or because of the collation used in your DB. Eloy might be able to comment on this. Your suggested improvements are worth looking at.
Hide
Jean-Philippe Gaudreau added a comment - - edited

Nevermind the first 3 errors about collations. My fix is for the others about the "." (EN) versus "," (FR) and other strings in unit tests that should be taken from the language packages instead of hardcoded in english.

Show
Jean-Philippe Gaudreau added a comment - - edited Nevermind the first 3 errors about collations. My fix is for the others about the "." (EN) versus "," (FR) and other strings in unit tests that should be taken from the language packages instead of hardcoded in english.
Hide
Eloy Lafuente (stronk7) added a comment -

I've requested comments from Tim Hunt (@ HQ chat) about this patch and here there are them:

<timhunt> I don't like using grade_edit_tree::format_number for the expected value. It makes the test largely pointless.
<timhunt> I would test against str_repace('.', get_string('decsep', 'langconfig'), $numoutput[$i])
<timhunt> Which is ugly, but makes the test stricter.
<timhunt> But the changes elsewhere where you have done format_float(2.0000000, 7) are good, I think.

So I think it would be worth changing the way grade_edit_tree ones are doing, then run them under a few languages and apply this both to 2.1 and master (2.2 in weeks).

Thanks and ciao

Show
Eloy Lafuente (stronk7) added a comment - I've requested comments from Tim Hunt (@ HQ chat) about this patch and here there are them:
<timhunt> I don't like using grade_edit_tree::format_number for the expected value. It makes the test largely pointless. <timhunt> I would test against str_repace('.', get_string('decsep', 'langconfig'), $numoutput[$i]) <timhunt> Which is ugly, but makes the test stricter. <timhunt> But the changes elsewhere where you have done format_float(2.0000000, 7) are good, I think.
So I think it would be worth changing the way grade_edit_tree ones are doing, then run them under a few languages and apply this both to 2.1 and master (2.2 in weeks). Thanks and ciao
Hide
Jean-Philippe Gaudreau added a comment -

I think the fix in grade/simpletest/testedittree.php must also be done in MOODLE_20_STABLE.

Thanks for the feedback!

Show
Jean-Philippe Gaudreau added a comment - I think the fix in grade/simpletest/testedittree.php must also be done in MOODLE_20_STABLE. Thanks for the feedback!
Hide
Jean-Philippe Gaudreau added a comment -

sorry for the delay...

I've fix the unit tests on grade_edit_tree::format_number. It works fine but shows there's a bug in the grade_edit_tree::format_number method :S. Same thing as in the unit tests, the decimal point is hardcoded as a '.', so in French (other language) the function returns '1,' instead of '1'.

function format_number($number) {
        $formatted = rtrim(format_float($number, 4),'0');
        if (substr($formatted, -1)=='.') { //if last char is the decimal point
            $formatted .= '0';
        }
        return $formatted;
    }

Should be :

function format_number($number) {
        $formatted = rtrim(format_float($number, 4),'0');
        if (substr($formatted, -1)==get_string('decsep', 'langconfig')) { //if last char is the decimal point
            $formatted .= '0';
        }
        return $formatted;
    }

2 Questions for you :

  • Should I create another task to fix the bug? If so, how can I test this function in Moodle (testing intructions)?
  • Do you still want me to apply the fixes of this task in 2.2 and 2.3dev (master)?
Show
Jean-Philippe Gaudreau added a comment - sorry for the delay... I've fix the unit tests on grade_edit_tree::format_number. It works fine but shows there's a bug in the grade_edit_tree::format_number method :S. Same thing as in the unit tests, the decimal point is hardcoded as a '.', so in French (other language) the function returns '1,' instead of '1'.
function format_number($number) {
        $formatted = rtrim(format_float($number, 4),'0');
        if (substr($formatted, -1)=='.') { //if last char is the decimal point
            $formatted .= '0';
        }
        return $formatted;
    }
Should be :
function format_number($number) {
        $formatted = rtrim(format_float($number, 4),'0');
        if (substr($formatted, -1)==get_string('decsep', 'langconfig')) { //if last char is the decimal point
            $formatted .= '0';
        }
        return $formatted;
    }
2 Questions for you :
  • Should I create another task to fix the bug? If so, how can I test this function in Moodle (testing intructions)?
  • Do you still want me to apply the fixes of this task in 2.2 and 2.3dev (master)?
Hide
Jean-Philippe Gaudreau added a comment -

Fixes integrated and tested in 2.2 stable and 2.3dev (master).

Note : grade_edit_tree::format_number bug is still in 2.3dev. I'll create an issue to fix it.

Show
Jean-Philippe Gaudreau added a comment - Fixes integrated and tested in 2.2 stable and 2.3dev (master). Note : grade_edit_tree::format_number bug is still in 2.3dev. I'll create an issue to fix it.

Dates

  • Created:
    Updated: