-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor units tests to work in Moodle 3.11 and later.
Use filter_multilang as the basis for the refactoring. Obviously this means that this plugin version should only be used in Moodle 3.11 and later. Not because the plugin itself can't run in earlier versions (it should be able to run on anything since Moodle 3.5). But because the unit tests will fail on anything earlier than Moodle 3.11 (as the way unit tests are implemented changed in an incompatible way in that release). This is why we are bumping the plugin version to 2.0.0. To signal the breaking change. Also extract the data used for the actual unit test to a separate file, as the idea is to keep two separate branches for the Moodle 3.10 and earlier versions, and Moodle 3.11 and later versions. But to reuse the unit tests data across the two branches as easily as possible, without having to touch other parts of the code. Fixes: #32
- Loading branch information
Showing
3 changed files
with
312 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,261 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Actual test cases for the unit tests. | ||
* | ||
* @package filter_multilang2 | ||
* @category test | ||
* @copyright 2022 onwards Iñaki Arenaza | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
/** | ||
* Returns the actual test cases for the unit tests. | ||
* | ||
* @return array of test cases | ||
*/ | ||
function multilang2_actual_test_cases() { | ||
return [ | ||
[ | ||
'No multilang tags', | ||
'No multilang tags', | ||
'es', | ||
], | ||
[ | ||
'Todo el texto está en español', | ||
'{mlang es}Todo el texto está en español{mlang}', | ||
'es', | ||
], | ||
[ | ||
'Todo el texto está en español', | ||
'{MLANG es}Todo el texto está en español{MLANG}', | ||
'es', | ||
], | ||
[ | ||
'Todo el texto está en español', | ||
'{MLANG ES}Todo el texto está en español{MLANG}', | ||
'es', | ||
], | ||
[ | ||
'Todo el texto está en español', | ||
'{MlAnG Es}Todo el texto está en español{MlAnG}', | ||
'es', | ||
], | ||
[ | ||
'Some non-filtered content plus some content in Spanish (mejor dicho, en español)', | ||
'Some non-filtered content {mlang es}plus some content in Spanish (mejor dicho, en español){mlang}', | ||
'es', | ||
], | ||
[ | ||
'Zerbait euskeraz', | ||
'{mlang es}Algo en español{mlang}{mlang eu}Zerbait euskeraz{mlang}', | ||
'eu', | ||
], | ||
[ | ||
'Non-filtered {begin}EuskerazNon-filtered{end}', | ||
'Non-filtered {begin}{mlang es}En español{mlang}{mlang eu}Euskeraz{mlang}Non-filtered{end}', | ||
'eu', | ||
], | ||
[ | ||
'{mlang}Bad filter syntax{mlang}', | ||
'{mlang}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang-es}Bad filter syntax{mlang}', | ||
'{mlang-es}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang_es}Bad filter syntax{mlang}', | ||
'{mlang_es}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'', | ||
'{mlang _es}Este texto está en español{mlang}', | ||
'es', | ||
], | ||
[ | ||
'', | ||
'{mlang -es}Este texto está en español{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang}Bad filter syntax{mlang}Algo de español', | ||
'{mlang}Bad filter syntax{mlang}{mlang es}Algo de español{mlang}', | ||
'es', | ||
], | ||
[ | ||
'Before {mlang}Bad filter syntax{mlang}Algo de español After', | ||
'Before {mlang}Bad filter syntax{mlang}{mlang es}Algo de español{mlang} After', | ||
'es', | ||
], | ||
[ | ||
'Before After', | ||
'Before {mlang non-existent-language}Some content{mlang} After', | ||
'es', | ||
], | ||
[ | ||
'Before Some content After', | ||
'Before {mlang en_us}Some content{mlang} After', | ||
'en_us', ['en_us' => 'en'], | ||
], | ||
[ | ||
'Before Some content After', | ||
'Before {mlang en-us}Some content{mlang} After', | ||
'en_us', ['en_us' => 'en'], | ||
], | ||
[ | ||
'Before After', | ||
'Before {mlang fr}French{mlang}{mlang it}Italian{mlang}{mlang de}Deutsch{mlang} After', | ||
'en', | ||
], | ||
[ | ||
'Before България | ||
Middle България | ||
After', | ||
'Before {mlang fr}Français{mlang}{mlang it}Italiano{mlang}{mlang de}Deutsch{mlang}{mlang other}България{mlang} | ||
Middle {mlang other}България{mlang}{mlang it}Italiano{mlang}{mlang de}Deutsch{mlang}{mlang fr}Français{mlang} | ||
After', | ||
'en', | ||
], | ||
[ | ||
'no other language declared', | ||
'{mlang de}Deutsch {mlang}no other language declared', | ||
'en', | ||
], | ||
[ | ||
'Other language', | ||
'{mlang other}Other language{mlang}', | ||
'en', | ||
], | ||
[ | ||
'Other language Middle Other language', | ||
'{mlang other}Other language{mlang} Middle {mlang de}Deutsch{mlang}{mlang other}Other language{mlang}', | ||
'en', | ||
], | ||
[ | ||
'Hello! | ||
This text is common for all languages because it is outside of all lang blocks. | ||
Bye!', | ||
'{mlang other}Hello!{mlang}{mlang es,es_mx}¡Hola!{mlang} | ||
This text is common for all languages because it is outside of all lang blocks. | ||
{mlang other}Bye!{mlang}{mlang it}Ciao!{mlang}', | ||
'fr', | ||
], | ||
[ | ||
'¡Hola! | ||
This text is common for all languages because it is outside of all lang blocks. | ||
', | ||
'{mlang other}Hello!{mlang}{mlang es,es_mx}¡Hola!{mlang} | ||
This text is common for all languages because it is outside of all lang blocks. | ||
{mlang other}Bye!{mlang}{mlang it}Ciao!{mlang}', | ||
'es_mx', ['es_mx' => 'es'] | ||
], | ||
[ | ||
' | ||
This text is common for all languages because it is outside of all lang blocks. | ||
Ciao!', | ||
'{mlang other}Hello!{mlang}{mlang es,es_mx}¡Hola!{mlang} | ||
This text is common for all languages because it is outside of all lang blocks. | ||
{mlang other}Bye!{mlang}{mlang it}Ciao!{mlang}', | ||
'it', | ||
], | ||
[ | ||
'Todo el texto está en español', | ||
'{mlang en,fr,es}Todo el texto está en español{mlang}', | ||
'es', | ||
], | ||
[ | ||
'Todo el texto está en español', | ||
'{mlang en , fr,es }Todo el texto está en español{mlang}', | ||
'es', | ||
], | ||
[ | ||
'Todo el texto está en español', | ||
'{mLaNg eN , FR,Es }Todo el texto está en español{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en , , ,,, fr,es,, ,}Bad filter syntax{mlang}', | ||
'{mlang en , , ,,, fr,es,, ,}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en ,}Bad filter syntax{mlang}', | ||
'{mlang en ,}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en, }Bad filter syntax{mlang}', | ||
'{mlang en, }Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en , }Bad filter syntax{mlang}', | ||
'{mlang en , }Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en, , }Bad filter syntax{mlang}', | ||
'{mlang en, , }Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en,,es}Bad filter syntax{mlang}', | ||
'{mlang en,,es}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en ,, es }Bad filter syntax{mlang}', | ||
'{mlang en ,, es }Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en , , es}Bad filter syntax{mlang}', | ||
'{mlang en , , es}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en , , es , }Bad filter syntax{mlang}', | ||
'{mlang en , , es , }Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en,es,}Bad filter syntax{mlang}', | ||
'{mlang en,es,}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang en , es , }Bad filter syntax{mlang}', | ||
'{mlang en , es , }Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang,es}Bad filter syntax{mlang}', | ||
'{mlang,es}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
[ | ||
'{mlang ,es}Bad filter syntax{mlang}', | ||
'{mlang ,es}Bad filter syntax{mlang}', | ||
'es', | ||
], | ||
]; | ||
} | ||
|
Oops, something went wrong.