first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,33 @@
@tool @tool_customlang
Feature: Within a moodle instance, an administrator should be able to modify langstrings for the entire Moodle installation.
In order to change langstrings in the adminsettings of the instance,
As an admin
I need to be able to access and change values in the the language customisation of the language pack.
Background:
# This is a very slow running test and on slow databases can take minutes to complete.
Given I mark this test as slow setting a timeout factor of 4
And I log in as "admin"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
And I press "Open language pack for editing"
And I press "Continue"
And I set the field "Show strings of these components" to "moodle.php"
And I set the field "String identifier" to "moodledocslink"
And I press "Show strings"
And I set the field "core/moodledocslink" to "moodle documents"
@javascript
Scenario: Edit an string but don't save it to lang pack.
When I press "Apply changes and continue editing"
Then I should not see "moodle documents" in the "page-footer" "region"
And I should see "Documentation for this page" in the "page-footer" "region"
@javascript
Scenario: Customize an string as admin and save it to lang pack.
Given I press "Save changes to the language pack"
And I should see "There are 1 modified strings."
When I click on "Continue" "button"
Then I should not see "Documentation for this page" in the "page-footer" "region"
And I should see "moodle documents" in the "page-footer" "region"
@@ -0,0 +1,53 @@
@tool @tool_customlang
Feature: Within a moodle instance, an administrator should be able to export modified langstrings.
In order to export modified langstrings in the adminsettings of the instance,
As an admin
I need to be able to export the php-files of the language customisation of a language.
Background:
# This is a very slow running feature and on slow databases can take minutes to complete.
Given I mark this test as slow setting a timeout factor of 4
@javascript
Scenario: Export button should not appear if no customization is made
Given I log in as "admin"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
Then I should see "Open language pack for editing"
And I should not see "Export custom strings"
@javascript
Scenario: Export button should not appear if no customization is saved into langpack
Given I log in as "admin"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
And I press "Open language pack for editing"
And I press "Continue"
And I set the field "Show strings of these components" to "moodle.php"
And I set the field "String identifier" to "accept"
And I press "Show strings"
And I set the field "core/accept" to "Accept-custom_export"
When I press "Apply changes and continue editing"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
Then I should see "Open language pack for editing"
And I should see "There are 1 modified strings."
And I should not see "Export custom strings"
@javascript
Scenario: Export the php-file including a customised langstring.
Given I log in as "admin"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
And I press "Open language pack for editing"
And I press "Continue"
And I set the field "Show strings of these components" to "moodle.php"
And I set the field "String identifier" to "accept"
And I press "Show strings"
And I set the field "core/accept" to "Accept-custom_export"
When I press "Save changes to the language pack"
And I should see "There are 1 modified strings."
And I click on "Continue" "button"
Then I set the field "lng" to "en"
And I click on "Export custom strings" "button"
And I set the field "Select component(s) to export" to "moodle.php"
@@ -0,0 +1,51 @@
@tool @tool_customlang @_file_upload
Feature: Within a moodle instance, an administrator should be able to import modified langstrings.
In order to import modified langstrings in the adminsettings from one to another instance,
As an admin
I need to be able to import the zips and php files of the language customisation of a language.
Background:
# This is a very slow running test and on slow databases can take minutes to complete.
Given I mark this test as slow setting a timeout factor of 4
And I log in as "admin"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
And I click on "Import custom strings" "button"
And I press "Continue"
@javascript
Scenario: Import a PHP file to add a new core lang customization
When I upload "admin/tool/customlang/tests/fixtures/tool_customlang.php" file to "Language component(s)" filemanager
And I press "Import file"
Then I should see "String tool_customlang/pluginname updated successfully."
And I should see "String tool_customlang/nonexistentinvetedstring not found."
And I click on "Continue" "button"
And I should see "There are 1 modified strings."
And I click on "Save strings to language pack" "button"
And I click on "Continue" "button"
And I should see "An amazing import feature"
@javascript
Scenario: Try to import a PHP file from a non existent component
When I upload "admin/tool/customlang/tests/fixtures/mod_fakecomponent.php" file to "Language component(s)" filemanager
And I press "Import file"
Then I should see "Missing component mod_fakecomponent."
@javascript
Scenario: Import a zip file with some PHP files in it.
When I upload "admin/tool/customlang/tests/fixtures/customlang.zip" file to "Language component(s)" filemanager
And I press "Import file"
Then I should see "String core/administrationsite updated successfully."
And I should see "String core/language updated successfully."
And I should see "String core/nonexistentinvetedstring not found."
And I should see "String tool_customlang/pluginname updated successfully."
And I should see "String tool_customlang/nonexistentinvetedstring not found."
And I should see "Missing component mod_fakecomponent."
And I click on "Continue" "button"
And I should see "There are 3 modified strings."
And I click on "Save strings to language pack" "button"
And I click on "Continue" "button"
And I should see "Uploaded custom string"
And I should see "Another Uploaded string"
And I should see "An amazing import feature"
@@ -0,0 +1,84 @@
@tool @tool_customlang @_file_upload
Feature: Within a moodle instance, an administrator should be able to import langstrings with several modes.
In order to import modified langstrings in the adminsettings from one to another instance,
As an admin
I need to be able to import only some language customisation strings depending on some conditions.
Background:
# This is a very slow running feature and on slow databases can take minutes to complete.
Given I mark this test as slow setting a timeout factor of 4
# Add one customization.
And I log in as "admin"
And I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
And I press "Open language pack for editing"
And I press "Continue"
And I set the field "Show strings of these components" to "moodle.php"
And I set the field "String identifier" to "administrationsite"
And I press "Show strings"
And I set the field "core/administrationsite" to "Custom string example"
And I press "Save changes to the language pack"
And I should see "There are 1 modified strings."
And I click on "Continue" "button"
And I should see "Custom string example"
@javascript
Scenario: Update only customized strings
When I set the field "lng" to "en"
And I click on "Import custom strings" "button"
And I press "Continue"
And I upload "admin/tool/customlang/tests/fixtures/moodle.php" file to "Language component(s)" filemanager
And I set the field "Import mode" to "Update only strings with local customisation"
And I press "Import file"
Then I should see "String core/administrationsite updated successfully."
And I should see "Ignoring string core/language because it is not customised."
And I should see "String core/nonexistentinvetedstring not found."
And I click on "Continue" "button"
And I should see "There are 1 modified strings."
And I should not see "Uploaded custom string"
And I click on "Save strings to language pack" "button"
And I click on "Continue" "button"
And I should not see "Custom string example"
And I should see "Uploaded custom string"
And I should not see "Another Uploaded string"
@javascript
Scenario: Create only new strings
When I set the field "lng" to "en"
And I click on "Import custom strings" "button"
And I press "Continue"
And I upload "admin/tool/customlang/tests/fixtures/moodle.php" file to "Language component(s)" filemanager
And I set the field "Import mode" to "Create only strings without local customisation"
And I press "Import file"
Then I should see "Ignoring string core/administrationsite because it is already defined."
And I should see "String core/language updated successfully."
And I should see "String core/nonexistentinvetedstring not found."
And I click on "Continue" "button"
And I should see "There are 1 modified strings."
And I should not see "Uploaded custom string"
And I click on "Save strings to language pack" "button"
And I click on "Continue" "button"
And I should see "Custom string example"
And I should not see "Uploaded custom string"
And I should see "Another Uploaded string"
@javascript
Scenario: Import all strings
When I set the field "lng" to "en"
And I click on "Import custom strings" "button"
And I press "Continue"
And I upload "admin/tool/customlang/tests/fixtures/moodle.php" file to "Language component(s)" filemanager
And I set the field "Import mode" to "Create or update all strings from the component(s)"
And I press "Import file"
Then I should see "String core/administrationsite updated successfully."
And I should see "String core/language updated successfully."
And I should see "String core/nonexistentinvetedstring not found."
And I click on "Continue" "button"
And I should see "There are 2 modified strings."
And I should not see "Uploaded custom string"
And I click on "Save strings to language pack" "button"
And I click on "Continue" "button"
And I should not see "Custom string example"
And I should see "Uploaded custom string"
And I should see "Another Uploaded string"
@@ -0,0 +1,21 @@
@tool @tool_customlang @javascript
Feature: Verify the breadcrumbs in language customisation site administration pages
Whenever I navigate to language customisation page in site administration
As an admin
The breadcrumbs should be visible
Background:
Given I log in as "admin"
Scenario: Verify the breadcrumbs in language customisation page by visiting open language pack for editing and import custom strings pages
Given I navigate to "Language > Language customisation" in site administration
And I set the field "lng" to "en"
When I click on "Open language pack for editing" "button"
And I wait until the page is ready
And "Language customisation" "text" should exist in the ".breadcrumb" "css_element"
And "Language" "link" should exist in the ".breadcrumb" "css_element"
And I press the "back" button in the browser
And I click on "Import custom strings" "button"
And I wait until the page is ready
And "Language customisation" "text" should exist in the ".breadcrumb" "css_element"
And "Language" "link" should exist in the ".breadcrumb" "css_element"
Binary file not shown.
@@ -0,0 +1,29 @@
<?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/>.
/**
* Local language pack.
*
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['administrationsite'] = 'Uploaded custom string';
$string['language'] = 'Another Uploaded string';
$string['nonexistentinvetedstring'] = 'This should not be imported';
+28
View File
@@ -0,0 +1,28 @@
<?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/>.
/**
* Local language pack.
*
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['administrationsite'] = 'Uploaded custom string';
$string['language'] = 'Another Uploaded string';
$string['nonexistentinvetedstring'] = 'This should not be imported';
@@ -0,0 +1,28 @@
<?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/>.
/**
* Local language pack from http://localhost/m/MDL-69583
*
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'An amazing import feature';
$string['nonexistentinvetedstring'] = 'This string should not be imported';
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,207 @@
<?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/>.
/**
* PHP lang parser test.
*
* @package tool_customlang
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_customlang\local\mlang;
use advanced_testcase;
use moodle_exception;
/**
* PHP lang parser test class.
*
* @package tool_customlang
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class phpparser_test extends advanced_testcase {
/**
* Test get instance static method.
*
*/
public function test_get_instance(): void {
$instance = phpparser::get_instance();
$this->assertInstanceOf('tool_customlang\local\mlang\phpparser', $instance);
$this->assertEquals($instance, phpparser::get_instance());
}
/**
* Test get instance parse method.
*
* @dataProvider parse_provider
* @param string $phpcode PHP code to test
* @param array $expected Expected result
* @param bool $exception if an exception is expected
*/
public function test_parse(string $phpcode, array $expected, bool $exception): void {
$instance = phpparser::get_instance();
if ($exception) {
$this->expectException(moodle_exception::class);
}
$strings = $instance->parse($phpcode);
$this->assertEquals(count($expected), count($strings));
foreach ($strings as $key => $langstring) {
$this->assertEquals($expected[$key][0], $langstring->id);
$this->assertEquals($expected[$key][1], $langstring->text);
}
}
/**
* Data provider for the test_parse.
*
* @return array
*/
public function parse_provider(): array {
return [
'Invalid PHP code' => [
'No PHP code', [], false
],
'No PHP open tag' => [
"\$string['example'] = 'text';\n", [], false
],
'One string code' => [
"<?php \$string['example'] = 'text';\n", [['example', 'text']], false
],
'Extra spaces' => [
"<?php \$string['example'] = 'text';\n", [['example', 'text']], false
],
'Extra tabs' => [
"<?php \$string['example']\t=\t'text';\n", [['example', 'text']], false
],
'Double quote string' => [
"<?php
\$string['example'] = \"text\";
\$string[\"example2\"] = 'text2';
\$string[\"example3\"] = \"text3\";
", [
['example', 'text'],
['example2', 'text2'],
['example3', 'text3'],
], false
],
'Multiple lines strings' => [
"<?php
\$string['example'] = 'First line\nsecondline';
\$string['example2'] = \"First line\nsecondline2\";
", [
['example', "First line\nsecondline"],
['example2', "First line\nsecondline2"],
], false
],
'Two strings code' => [
"<?php
\$string['example'] = 'text';
\$string['example2'] = 'text2';
", [
['example', 'text'],
['example2', 'text2'],
], false
],
'Scaped characters' => [
"<?php
\$string['example'] = 'Thos are \\' quotes \" 1';
\$string['example2'] = \"Thos are ' quotes \\\" 2\";
", [
['example', "Thos are ' quotes \" 1"],
['example2', "Thos are ' quotes \" 2"],
], false
],
'PHP with single line comments' => [
"<?php
// This is a comment.
\$string['example'] = 'text';
// This is another commment.
", [
['example', 'text'],
], false
],
'PHP with block comments' => [
"<?php
/* This is a block comment. */
\$string['example'] = 'text';
/* This is another
block comment. */
", [
['example', 'text'],
], false
],
'Wrong variable name' => [
"<?php
\$stringwrong['example'] = 'text';
\$wringstring['example'] = 'text';
", [], false
],
'Single line commented valid line' => [
"<?php
// \$string['example'] = 'text';
", [], false
],
'Block commented valid line' => [
"<?php
/*
\$string['example'] = 'text';
*/
", [], false
],
'Syntax error 1 (double assignation)' => [
"<?php
\$string['example'] = 'text' = 'wrong';
", [], true
],
'Syntax error 2 (no closing string)' => [
"<?php
\$string['example'] = 'wrong;
", [], true
],
'Syntax error 3 (Array without key)' => [
"<?php
\$string[] = 'wrong';
", [], true
],
'Syntax error 4 (Array not open)' => [
"<?php
\$string'example'] = 'wrong';
", [], true
],
'Syntax error 5 (Array not closed)' => [
"<?php
\$string['example' = 'wrong';
", [], true
],
'Syntax error 6 (Missing assignment)' => [
"<?php
\$string['example'] 'wrong';
", [], true
],
];
}
}