Merge branch 'MDL-55320-fix' of https://github.com/lameze/moodle
authorDan Poltawski <dan@moodle.com>
Wed, 24 Aug 2016 07:20:57 +0000 (08:20 +0100)
committerDan Poltawski <dan@moodle.com>
Wed, 24 Aug 2016 07:20:57 +0000 (08:20 +0100)
admin/tool/behat/tests/manager_util_test.php
lib/behat/classes/behat_config_util.php
lib/tests/behat/behat_hooks.php
mod/data/classes/search/entry.php

index 9bc67fb..f4d26bf 100644 (file)
@@ -107,7 +107,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
         $this->behatconfigutil->expects($this->any())
             ->method('get_behat_contexts_for_theme')
             ->with($this->equalTo('testtheme'))
-            ->will($this->returnValue(array_keys($this->themecontexts)));
+            ->will($this->returnValue(array(array_keys($this->themecontexts), $this->themecontexts)));
 
     }
 
@@ -233,7 +233,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
         $behatconfigutil->expects($this->once())
             ->method('get_behat_contexts_for_theme')
             ->with($this->equalTo('testtheme'))
-            ->will($this->returnValue(array_keys($this->themecontexts)));
+            ->will($this->returnValue(array(array_keys($this->themecontexts), $this->themecontexts)));
 
         $behatconfigutil->expects($this->once())
             ->method('get_overridden_theme_contexts')
@@ -311,7 +311,7 @@ class tool_behat_manager_util_testcase extends advanced_testcase {
         $behatconfigutil->expects($this->atLeastOnce())
             ->method('get_behat_contexts_for_theme')
             ->with($this->equalTo('testtheme'))
-            ->will($this->returnValue(array_keys($this->themecontexts)));
+            ->will($this->returnValue(array(array_keys($this->themecontexts), $this->themecontexts)));
 
         $CFG->behat_wwwroot = 'http://example.com/behat';
 
index 37cef52..6c2b80f 100644 (file)
@@ -463,6 +463,15 @@ class behat_config_util {
             $allcontexts = $this->contexts;
         }
 
+        // Remove selectors from step definitions.
+        $themes = $this->get_list_of_themes();
+        foreach ($themes as $theme) {
+            $selectorclass = self::get_behat_theme_selector_override_classname($theme);
+            if (isset($allcontexts[$selectorclass])) {
+                unset($allcontexts[$selectorclass]);
+            }
+        }
+
         // Comments use black color, so failure path is not visible. Using color other then black/white is safer.
         // https://github.com/Behat/Behat/pull/628.
         $config = array(
@@ -922,6 +931,7 @@ class behat_config_util {
 
         $blacklistedfeatures = array();
         $themefeatures = array();
+        $themesuitecontexts = array();
         $themecontexts = array();
 
         $themes = $this->get_list_of_themes();
@@ -931,7 +941,7 @@ class behat_config_util {
             // Get theme features.
             list($blacklistedfeatures[$theme], $themefeatures[$theme]) = $this->get_behat_features_for_theme($theme);
 
-            $themecontexts[$theme] = $this->get_behat_contexts_for_theme($theme);
+            list($themecontexts[$theme], $themesuitecontexts[$theme]) = $this->get_behat_contexts_for_theme($theme);
         }
 
         // Remove list of theme features for default suite, as default suite should not run theme specific features.
@@ -939,6 +949,23 @@ class behat_config_util {
             $features = $this->remove_blacklisted_features_from_list($features, $removethemefeatures);
         }
 
+        // Remove list of theme features for default suite, as default suite should not run theme specific features.
+        foreach ($themecontexts as $theme => $themeblacklistcontexts) {
+            if ($themeblacklistcontexts) {
+                foreach ($themeblacklistcontexts as $c) {
+                    // Remove theme specific contexts from default contexts.
+                    unset($contexts[$c]);
+
+                    // Remove theme specific contexts from other themes.
+                    foreach ($themes as $currenttheme) {
+                        if (($currenttheme != $theme) && isset($themesuitecontexts[$currenttheme][$c])) {
+                            unset($themesuitecontexts[$currenttheme][$c]);
+                        }
+                    }
+                }
+            }
+        }
+
         // Return sub-set of features if parallel run.
         $featuresforrun = $this->get_features_for_the_run($features, $parallelruns, $currentrun);
 
@@ -976,7 +1003,7 @@ class behat_config_util {
             $suites = array_merge($suites, array(
                 $theme => array(
                     'paths'    => array_values($themesuitefeatures),
-                    'contexts' => array_values($themecontexts[$theme]),
+                    'contexts' => array_keys($themesuitecontexts[$theme]),
                 )
             ));
         }
@@ -1170,7 +1197,7 @@ class behat_config_util {
      * Return list of behat contexts for theme and update $this->stepdefinitions list.
      *
      * @param string $theme theme name.
-     * @return array list($features, $contexts)
+     * @return array list($themecontexts, $themesuitecontexts)
      */
     protected function get_behat_contexts_for_theme($theme) {
 
@@ -1186,12 +1213,13 @@ class behat_config_util {
         $contexts = $this->get_components_contexts();
 
         // Create list of contexts used by theme suite.
-        $overriddencontexts = $this->get_tests_for_theme($theme, 'contexts');
+        $themecontexts = $this->get_tests_for_theme($theme, 'contexts');
         $blacklistedcontexts = $this->get_blacklisted_tests_for_theme($theme, 'contexts');
 
         // Theme suite will use all core contexts, except the one overridden by theme.
         $themesuitecontexts = $contexts;
-        foreach ($overriddencontexts as $context => $path) {
+
+        foreach ($themecontexts as $context => $path) {
 
             // If a context in theme starts with behat_theme_{themename}_behat_* then it's overriding core context.
             if (preg_match('/^behat_theme_'.$theme.'_(\w+)$/', $context, $match)) {
@@ -1206,6 +1234,8 @@ class behat_config_util {
 
             // Don't include behat_selectors.
             if ($context === self::get_behat_theme_selector_override_classname($theme)) {
+                unset($this->contexts[$context]);
+                unset($themesuitecontexts[$context]);
                 continue;
             }
 
@@ -1221,8 +1251,8 @@ class behat_config_util {
         }
 
         // We are only interested in the class name of context.
-        $this->themecontexts[$theme] = array_keys($themesuitecontexts);
+        $this->themecontexts[$theme] = $themesuitecontexts;
 
-        return $this->themecontexts[$theme];
+        return array(array_keys($themecontexts), $themesuitecontexts);
     }
 }
\ No newline at end of file
index 90600cb..017e342 100644 (file)
@@ -148,6 +148,7 @@ class behat_hooks extends behat_base {
 
         // Now that we are MOODLE_INTERNAL.
         require_once(__DIR__ . '/../../behat/classes/behat_command.php');
+        require_once(__DIR__ . '/../../behat/classes/behat_selectors.php');
         require_once(__DIR__ . '/../../behat/classes/behat_context_helper.php');
         require_once(__DIR__ . '/../../behat/classes/util.php');
         require_once(__DIR__ . '/../../testing/classes/test_lock.php');
@@ -308,7 +309,10 @@ class behat_hooks extends behat_base {
             behat_context_helper::set_environment($scope->getEnvironment());
 
             // We need the Mink session to do it and we do it only before the first scenario.
-            $behatselectorclass = behat_config_util::get_behat_theme_selector_override_classname($suitename, true);
+            $behatselectorclass = 'behat_selectors';
+            if ($suitename !== 'default') {
+                $behatselectorclass = behat_config_util::get_behat_theme_selector_override_classname($suitename, true);
+            }
             if (class_exists($behatselectorclass)) {
                 $behatselectorclass = new $behatselectorclass();
                 $behatselectorclass::register_moodle_selectors($session);
index 0a2e8ce..ee5c1eb 100644 (file)
@@ -283,7 +283,7 @@ class entry extends \core_search\base_mod {
         }
 
         foreach ($filteredcontents as $content) {
-            $classname = 'data_field_' . trim($content->fieldtype);
+            $classname = $this->get_field_class_name($content->fieldtype);
             $content->priority = $classname::get_priority();
             $content->addtemplateposition = strpos($template, '[['.$content->fldname.']]');
         }
@@ -319,7 +319,7 @@ class entry extends \core_search\base_mod {
         while ($contentqueue->valid()) {
 
             $content = $contentqueue->extract();
-            $classname = 'data_field_' . trim($content->fieldtype);
+            $classname = $this->get_field_class_name($content->fieldtype);
 
             $indexfields[] = $classname::get_content_value($content->content);
         }
@@ -327,4 +327,17 @@ class entry extends \core_search\base_mod {
         return $indexfields;
     }
 
-}
\ No newline at end of file
+    /**
+     * Returns the class name for that field type and includes it.
+     *
+     * @param string $fieldtype
+     * @return string
+     */
+    protected function get_field_class_name($fieldtype) {
+        global $CFG;
+
+        $fieldtype = trim($fieldtype);
+        require_once($CFG->dirroot . '/mod/data/field/' . $fieldtype . '/field.class.php');
+        return 'data_field_' . $fieldtype;
+    }
+}