From 16f3355ce9b940edd5047d75424885ed9cc2734b Mon Sep 17 00:00:00 2001
From: diosmosis <benaka@piwik.pro>
Date: Tue, 26 May 2015 13:18:21 -0700
Subject: [PATCH] Move TestingEnvironment::arrayMergeRecursiveDistinct() to
 TestConfig since that's where it is used.

---
 config/environment/test.php                   | 10 ++++++++--
 tests/PHPUnit/Framework/Mock/TestConfig.php   | 19 ++++++++++++++++++-
 .../PHPUnit/Framework/TestingEnvironment.php  | 17 -----------------
 .../support/test-environment.js               |  1 +
 4 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/config/environment/test.php b/config/environment/test.php
index 6ff1e10982..205945db67 100644
--- a/config/environment/test.php
+++ b/config/environment/test.php
@@ -19,8 +19,14 @@ return array(
     'cache.eager.cache_id' => 'eagercache-test-',
 
     // Disable loading core translations
-    'Piwik\Translation\Translator' => DI\object()
-        ->constructorParameter('directories', array()),
+    'Piwik\Translation\Translator' => DI\decorate(function ($previous, ContainerInterface $c) {
+        $testingEnvironment = $c->get('Piwik\Tests\Framework\TestingEnvironment');
+        if (!$testingEnvironment->loadRealTranslations) {
+            return new \Piwik\Translation\Translator($c->get('Piwik\Translation\Loader\LoaderInterface'), $directories = array());
+        } else {
+            return $previous;
+        }
+    }),
 
     'Piwik\Config' => DI\decorate(function ($previous, ContainerInterface $c) {
         $testingEnvironment = $c->get('Piwik\Tests\Framework\TestingEnvironment');
diff --git a/tests/PHPUnit/Framework/Mock/TestConfig.php b/tests/PHPUnit/Framework/Mock/TestConfig.php
index 49e252dedc..7509100c55 100644
--- a/tests/PHPUnit/Framework/Mock/TestConfig.php
+++ b/tests/PHPUnit/Framework/Mock/TestConfig.php
@@ -108,7 +108,24 @@ class TestConfig extends Config
 
         if ($testingEnvironment->configOverride) {
             $cache =& $chain->getAll();
-            $cache = $testingEnvironment->arrayMergeRecursiveDistinct($cache, $testingEnvironment->configOverride);
+            $cache = $this->arrayMergeRecursiveDistinct($cache, $testingEnvironment->configOverride);
         }
     }
+
+    private function arrayMergeRecursiveDistinct(array $array1, array $array2)
+    {
+        $result = $array1;
+
+        foreach ($array2 as $key => $value) {
+            if (is_array($value)) {
+                $result[$key] = isset($result[$key]) && is_array($result[$key])
+                    ? $this->arrayMergeRecursiveDistinct($result[$key], $value)
+                    : $value;
+            } else {
+                $result[$key] = $value;
+            }
+        }
+
+        return $result;
+    }
 }
\ No newline at end of file
diff --git a/tests/PHPUnit/Framework/TestingEnvironment.php b/tests/PHPUnit/Framework/TestingEnvironment.php
index c176d49607..ff4a3b8842 100644
--- a/tests/PHPUnit/Framework/TestingEnvironment.php
+++ b/tests/PHPUnit/Framework/TestingEnvironment.php
@@ -184,23 +184,6 @@ class TestingEnvironment
         StaticContainer::addDefinitions($diConfig);
     }
 
-    public function arrayMergeRecursiveDistinct(array $array1, array $array2)
-    {
-        $result = $array1;
-
-        foreach ($array2 as $key => $value) {
-            if (is_array($value)) {
-                $result[$key] = isset($result[$key]) && is_array($result[$key])
-                    ? $this->arrayMergeRecursiveDistinct($result[$key], $value)
-                    : $value;
-            } else {
-                $result[$key] = $value;
-            }
-        }
-
-        return $result;
-    }
-
     /**
      * for plugins that need to inject special testing logic
      */
diff --git a/tests/lib/screenshot-testing/support/test-environment.js b/tests/lib/screenshot-testing/support/test-environment.js
index 4eb8319fc9..2753db3cbe 100644
--- a/tests/lib/screenshot-testing/support/test-environment.js
+++ b/tests/lib/screenshot-testing/support/test-environment.js
@@ -21,6 +21,7 @@ TestingEnvironment.prototype.reload = function () {
 
     this['useOverrideCss'] = true;
     this['useOverrideJs'] = true;
+    this['loadRealTranslations'] = true; // UI tests should test w/ real translations, not translation keys
 
     if (fs.exists(testingEnvironmentOverridePath)) {
         var data = JSON.parse(fs.read(testingEnvironmentOverridePath));
-- 
GitLab