From 57e002616fdbaea75a38525c664ab9a0438e281d Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Sun, 11 Feb 2018 18:58:11 +0100
Subject: [PATCH] Feature 5333 / Thumbnail: fixed unit tests

---
 extension/qfq/qfq/helper/OnString.php        |  6 +++-
 extension/qfq/tests/phpunit/OnArrayTest.php  |  1 +
 extension/qfq/tests/phpunit/OnStringTest.php | 31 ++++++++++++++++++++
 extension/qfq/tests/phpunit/StoreTest.php    |  4 +++
 extension/qfq/tests/phpunit/StringTest.php   | 29 ------------------
 5 files changed, 41 insertions(+), 30 deletions(-)
 create mode 100644 extension/qfq/tests/phpunit/OnStringTest.php
 delete mode 100644 extension/qfq/tests/phpunit/StringTest.php

diff --git a/extension/qfq/qfq/helper/OnString.php b/extension/qfq/qfq/helper/OnString.php
index 071c3ec86..9d0706a69 100644
--- a/extension/qfq/qfq/helper/OnString.php
+++ b/extension/qfq/qfq/helper/OnString.php
@@ -20,6 +20,10 @@ class OnString {
      * @return string
      */
     public static function strrstr($haystack, $needle) {
-        return substr($haystack, strpos($haystack, $needle) + 1);
+        if (empty($needle) || empty($haystack)) {
+            return '';
+        }
+
+        return substr($haystack, strrpos($haystack, $needle) + 1);
     }
 }
diff --git a/extension/qfq/tests/phpunit/OnArrayTest.php b/extension/qfq/tests/phpunit/OnArrayTest.php
index f8fa40680..06ba468fd 100644
--- a/extension/qfq/tests/phpunit/OnArrayTest.php
+++ b/extension/qfq/tests/phpunit/OnArrayTest.php
@@ -12,6 +12,7 @@ require_once(__DIR__ . '/../../qfq/helper/OnArray.php');
 
 
 class OnArrayTest extends \PHPUnit_Framework_TestCase {
+
     public function testSortByKey() {
         $unsorted = [
             'a' => 'z',
diff --git a/extension/qfq/tests/phpunit/OnStringTest.php b/extension/qfq/tests/phpunit/OnStringTest.php
new file mode 100644
index 000000000..f73edbc5b
--- /dev/null
+++ b/extension/qfq/tests/phpunit/OnStringTest.php
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: crose
+ * Date: 11/02/18
+ * Time: 9:16 PM
+ */
+
+namespace qfq;
+
+require_once(__DIR__ . '/../../qfq/helper/OnString.php');
+
+use qfq;
+
+//use qfq\exceptions\CodeException;
+
+//require_once(__DIR__ . '/../../qfq/store/Store.php');
+//require_once(__DIR__ . '/../../qfq/Constants.php');
+//require_once(__DIR__ . '/../../qfq/exceptions/CodeException.php');
+//
+
+class OnStringTest extends \PHPUnit_Framework_TestCase {
+
+    public function testStrrstr() {
+
+        $this->assertEquals('', OnString::strrstr('', ''));
+        $this->assertEquals('', OnString::strrstr('hello world to the limit', ''));
+        $this->assertEquals('limit', OnString::strrstr('hello world to the limit', ' '));
+        $this->assertEquals('', OnString::strrstr('', ' '));
+    }
+}
\ No newline at end of file
diff --git a/extension/qfq/tests/phpunit/StoreTest.php b/extension/qfq/tests/phpunit/StoreTest.php
index 1ae81431b..b5ef6959c 100644
--- a/extension/qfq/tests/phpunit/StoreTest.php
+++ b/extension/qfq/tests/phpunit/StoreTest.php
@@ -336,6 +336,10 @@ EOT;
 
             DOCUMENTATION_QFQ => DOCUMENTATION_QFQ_URL,
             SYSTEM_ENTER_AS_SUBMIT => 1,
+            SYSTEM_CMD_INKSCAPE => 'inkscape',
+            SYSTEM_CMD_CONVERT => 'convert',
+            SYSTEM_THUMBNAIL_DIR_PUBLIC => SYSTEM_THUMBNAIL_DIR_PUBLIC_DEFAULT,
+            SYSTEM_THUMBNAIL_DIR_SECURE => SYSTEM_THUMBNAIL_DIR_SECURE_DEFAULT,
         ];
 
         $fileName = $this->createFile($body);
diff --git a/extension/qfq/tests/phpunit/StringTest.php b/extension/qfq/tests/phpunit/StringTest.php
deleted file mode 100644
index 83bddef13..000000000
--- a/extension/qfq/tests/phpunit/StringTest.php
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: crose
- * Date: 11/02/18
- * Time: 9:16 PM
- */
-
-namespace qfq;
-
-use qfq;
-
-//use qfq\exceptions\CodeException;
-
-//require_once(__DIR__ . '/../../qfq/store/Store.php');
-//require_once(__DIR__ . '/../../qfq/Constants.php');
-//require_once(__DIR__ . '/../../qfq/exceptions/CodeException.php');
-//
-
-class StringTest extends \PHPUnit_Framework_TestCase {
-
-    public function testStrrstr() {
-
-        $this->assertEquals('', String::strrstr('', ''));
-        $this->assertEquals('', String::strrstr('hello world to the limit', ''));
-        $this->assertEquals('limit', String::strrstr('hello world to the limit', ' '));
-        $this->assertEquals('', String::strrstr('', ' '));
-    }
-}
\ No newline at end of file
-- 
GitLab