MDL-46210 langimport: behat tests
authorDan Poltawski <dan@moodle.com>
Sun, 28 Sep 2014 14:43:50 +0000 (15:43 +0100)
committerDan Poltawski <dan@moodle.com>
Sun, 5 Oct 2014 13:40:47 +0000 (14:40 +0100)
Behat tests for lang import. To run these tests you must define the
TOOL_LANGIMPORT_REMOTE_TESTS constant - because they rely on the
download.moodle.org infrastructure.

admin/tool/langimport/tests/behat/behat_tool_langimport.php [new file with mode: 0644]
admin/tool/langimport/tests/behat/manage_langpacks.feature [new file with mode: 0644]
admin/tool/langimport/version.php

diff --git a/admin/tool/langimport/tests/behat/behat_tool_langimport.php b/admin/tool/langimport/tests/behat/behat_tool_langimport.php
new file mode 100644 (file)
index 0000000..f2b5729
--- /dev/null
@@ -0,0 +1,81 @@
+<?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/>.
+
+/**
+ * Behat steps definitions for Language import tool
+ *
+ * @package   tool_langimport
+ * @category  test
+ * @copyright 2014 Dan Poltawski <dan@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
+
+require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
+
+use Moodle\BehatExtension\Exception\SkippedException;
+
+/**
+ * Steps definitions related with the Language import tool
+ *
+ * @package   tool_langimport
+ * @category  test
+ * @copyright 2014 Dan Poltawski <dan@moodle.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class behat_tool_langimport extends behat_base {
+
+    /**
+     * This step looks to see if the remote language import tests should be run (indicated by
+     * setting TOOL_LANGIMPORT_REMOTE_TESTS in config.php.
+     *
+     * @Given /^remote langimport tests are enabled$/
+     */
+    public function remote_langimport_tests_are_enabled() {
+        if (!defined('TOOL_LANGIMPORT_REMOTE_TESTS')) {
+            throw new SkippedException('To run the remote langimport tests you must '.
+                'define TOOL_LANGIMPORT_REMOTE_TESTS in config.php');
+        }
+    }
+
+    /**
+     * Downloads a langpack and fakes it being outdated
+     *
+     * @param string $langcode The language code (e.g. en)
+     * @Given /^outdated langpack \'([^\']*)\' is installed$/
+     */
+    public function outdated_langpack_is_installed($langcode) {
+        global $CFG;
+        require_once($CFG->libdir.'/componentlib.class.php');
+
+        // Download the langpack.
+        $dir = make_upload_directory('lang');
+        $installer = new lang_installer($langcode);
+        $result = $installer->run();
+
+        if ($result[$langcode] !== lang_installer::RESULT_INSTALLED) {
+            throw new coding_exception("Failed to install langpack '$langcode'");
+        }
+
+        $path = "$dir/$langcode/$langcode.md5";
+
+        if (!file_exists($path)) {
+            throw new coding_exception("Failed to find '$langcode' checksum");
+        }
+        file_put_contents($path, '000000');
+    }
+}
diff --git a/admin/tool/langimport/tests/behat/manage_langpacks.feature b/admin/tool/langimport/tests/behat/manage_langpacks.feature
new file mode 100644 (file)
index 0000000..ff21c8e
--- /dev/null
@@ -0,0 +1,59 @@
+@tool @tool_langimport
+Feature: Manage language packs
+  In order to support different languages
+  As an administrator
+  I need to be able to add, update and remove language packs
+
+
+  Background:
+    Given remote langimport tests are enabled
+
+  # The pirate language pack is used for testing because its small to download.
+
+  Scenario: Install language pack
+    Given I log in as "admin"
+    And I navigate to "Language packs" node in "Site administration > Language"
+    When I set the field "Available language packs" to "English - Pirate (en_ar)"
+    And I press "Install selected language pack(s)"
+    Then I should see "Language pack 'en_ar' was successfully installed"
+    And the "Installed language packs" select box should contain "English - Pirate (en_ar)"
+    And I navigate to "Live logs" node in "Site administration > Reports"
+    And I should see "The language pack 'en_ar' was installed."
+    And I log out
+
+  Scenario: Update language pack
+    Given outdated langpack 'en_ar' is installed
+    And I log in as "admin"
+    And I navigate to "Language packs" node in "Site administration > Language"
+    When I press "Update all installed language packs"
+    Then I should see "Language pack 'en_ar' was successfully updated"
+    And I should see "Language pack update completed"
+    And I navigate to "Live logs" node in "Site administration > Reports"
+    And I should see "The language pack 'en_ar' was updated."
+    And I log out
+
+  Scenario: Try to uninstall language pack
+    Given I log in as "admin"
+    And I navigate to "Language packs" node in "Site administration > Language"
+    And I set the field "Available language packs" to "English - Pirate (en_ar)"
+    And I press "Install selected language pack(s)"
+    When I set the field "Installed language packs" to "English - Pirate (en_ar)"
+    And I press "Uninstall selected language pack"
+    And I press "Continue"
+    Then I should see "Language pack 'en_ar' was uninstalled"
+    And the "Installed language packs" select box should not contain "English - Pirate (en_ar)"
+    And the "Available language packs" select box should contain "English - Pirate (en_ar)"
+    And I navigate to "Live logs" node in "Site administration > Reports"
+    And I should see "The language pack 'en_ar' was removed."
+    And I should see "Language pack uninstalled"
+    And I log out
+
+  Scenario: Try to uninstall English language pack
+    Given I log in as "admin"
+    And I navigate to "Language packs" node in "Site administration > Language"
+    When I set the field "Installed language packs" to "English (en)"
+    And I press "Uninstall selected language pack"
+    Then I should see "English language pack can not be uninstalled"
+    And I navigate to "Live logs" node in "Site administration > Reports"
+    And I should not see "Language pack uninstalled"
+    And I log out
index cb3f44b..7050367 100644 (file)
@@ -25,6 +25,6 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version   = 2014092800; // The current plugin version (Date: YYYYMMDDXX)
+$plugin->version   = 2014092801; // The current plugin version (Date: YYYYMMDDXX)
 $plugin->requires  = 2014050800; // Requires this Moodle version
 $plugin->component = 'tool_langimport'; // Full name of the plugin (used for diagnostics)