From 07c43ada743ca2de4537f3cff30b11d01e3d290b Mon Sep 17 00:00:00 2001
From: Chris Hallberg <crhallberg@gmail.com>
Date: Fri, 5 Sep 2014 13:15:08 -0400
Subject: [PATCH] More LESS testing.

---
 .../src/VuFindTheme/LessCompiler.php          | 36 ++++++++++---------
 .../VuFindTest/ThemeResourceContainerTest.php | 18 ++++++++++
 2 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/module/VuFindTheme/src/VuFindTheme/LessCompiler.php b/module/VuFindTheme/src/VuFindTheme/LessCompiler.php
index f46eab0527e..815ea475760 100644
--- a/module/VuFindTheme/src/VuFindTheme/LessCompiler.php
+++ b/module/VuFindTheme/src/VuFindTheme/LessCompiler.php
@@ -112,14 +112,11 @@ class LessCompiler
     {
         $lessFiles = $this->getAllLessFiles($theme);
         if (empty($lessFiles)) {
-            if ($this->verbose) {
-                Console::writeLine("No LESS in " . $theme);
-            }
+            $this->logMessage("No LESS in " . $theme);
             return;
         }
-        if ($this->verbose) {
-            Console::writeLine("Processing " . $theme);
-        }
+        $this->logMessage("Processing " . $theme);
+        $this->logMessage("Processing " . $theme);
         foreach ($lessFiles as $less) {
             if (is_string($less)) {
                 $this->compileFile($theme, $less);
@@ -165,9 +162,7 @@ class LessCompiler
         list($fileName, ) = explode('.', $less);
         $finalFile = $finalOutDir . $fileName . '.css';
 
-        if ($this->verbose) {
-            Console::writeLine("\tcompiling '" . $less .  "' into '" . $finalFile . "'");
-        }
+        $this->logMessage("\tcompiling '" . $less .  "' into '" . $finalFile . "'");
         $start = microtime(true);
 
         $directories = array();
@@ -178,11 +173,7 @@ class LessCompiler
         }
         $lessDir = $this->basePath . '/themes/' . $theme . '/less/';
         if (!file_exists($lessDir . $less)) {
-            if ($this->verbose) {
-                Console::writeLine(
-                    "\t\t" . $lessDir . $less . ' does not exist; skipping.'
-                );
-            }
+            $this->logMessage("\t\t" . $lessDir . $less . ' does not exist; skipping.');
             return;
         }
         $outDir = sys_get_temp_dir();
@@ -201,9 +192,7 @@ class LessCompiler
         }
         file_put_contents($finalFile, $this->makeRelative($css, $less));
 
-        if ($this->verbose) {
-            Console::writeLine("\t\t" . (microtime(true)-$start) . ' sec');
-        }
+        $this->logMessage("\t\t" . (microtime(true)-$start) . ' sec');
     }
 
     /**
@@ -249,4 +238,17 @@ class LessCompiler
         closedir($dir);
         return $list;
     }
+
+    /**
+     * Log a message to the console
+     *
+     * @param string $str message string
+     *
+     * @return void
+     */
+    protected function logMessage($str) {
+        if ($this->verbose) {
+            Console::writeLine($str);
+        }
+    }
 }
\ No newline at end of file
diff --git a/module/VuFindTheme/tests/unit-tests/src/VuFindTest/ThemeResourceContainerTest.php b/module/VuFindTheme/tests/unit-tests/src/VuFindTest/ThemeResourceContainerTest.php
index 2a362340b6e..1d7f7a3b68e 100644
--- a/module/VuFindTheme/tests/unit-tests/src/VuFindTest/ThemeResourceContainerTest.php
+++ b/module/VuFindTheme/tests/unit-tests/src/VuFindTest/ThemeResourceContainerTest.php
@@ -50,9 +50,27 @@ class ThemeResourceContainerTest extends Unit\TestCase
         $container->addCss(array('a', 'b', 'c'));
         $container->addCss('c');
         $container->addCss('d');
+        $container->addLessCss('e.less');
+        $container->addCss('e');
         $this->assertEquals(array(), array_diff(array('a', 'b', 'c', 'd'), $container->getCss()));
     }
 
+    /**
+     * Test LESS add/remove.
+     *
+     * @return void
+     */
+    public function testLess()
+    {
+        $container = new ResourceContainer();
+        $container->addCss(array('c', 'd.css'));
+        $container->addLessCss(array('active'=>true, 'a', 'b', 'c'));
+        $container->addLessCss('c');
+        $container->addLessCss('d');
+        $this->assertEquals(array(), array_diff(array('a', 'b', 'c', 'd'), $container->getLessCss()));
+        $this->assertEquals(array('c'), $container->getCss());
+    }
+
     /**
      * Test Javascript add/remove.
      *
-- 
GitLab