From 357317fec9f9f69bb6f132548fb4c8b3fe16d406 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?ANDRE=20s=C3=A9bastien?= <sandre@afi-sa.fr>
Date: Fri, 20 Aug 2021 09:04:09 +0200
Subject: [PATCH] hotline: #131892: treeselect asynchrone with regex

---
 VERSIONS_HOTLINE/131892                  |   1 +
 public/admin/js/treeselect/test.js       | 160 +++++++++++++++++++++++
 public/admin/js/treeselect/tests.html    |  42 ++++++
 public/admin/js/treeselect/treeselect.js |  29 ++--
 tests/bootstrap.php                      |   1 +
 tests/js/AuthorityPickerTest.php         |  12 +-
 tests/js/CustomFieldsReportTest.php      |  13 +-
 tests/js/MultiInputTest.php              |  13 +-
 tests/js/MultiSelectionTest.php          |  13 +-
 tests/js/PhantomJsTest.php               |  52 ++++++++
 tests/js/SearchAutocompleteTest.php      |  15 +--
 tests/js/SearchInputTest.php             |  12 +-
 tests/js/SliderNavigationTest.php        |  28 +---
 tests/js/TreeSelectTest.php              |  25 ++++
 tests/js/UserSelectionTest.php           |  12 +-
 15 files changed, 326 insertions(+), 102 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/131892
 create mode 100644 public/admin/js/treeselect/test.js
 create mode 100644 public/admin/js/treeselect/tests.html
 create mode 100644 tests/js/PhantomJsTest.php
 create mode 100644 tests/js/TreeSelectTest.php

diff --git a/VERSIONS_HOTLINE/131892 b/VERSIONS_HOTLINE/131892
new file mode 100644
index 00000000000..5412652da6f
--- /dev/null
+++ b/VERSIONS_HOTLINE/131892
@@ -0,0 +1 @@
+ - ticket #131892 : Administration : Correction du composant de recherche de paniers dans les configurations de boites
\ No newline at end of file
diff --git a/public/admin/js/treeselect/test.js b/public/admin/js/treeselect/test.js
new file mode 100644
index 00000000000..5438b63b59d
--- /dev/null
+++ b/public/admin/js/treeselect/test.js
@@ -0,0 +1,160 @@
+/**
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+
+QUnit.module('treeselect');
+
+var datas = [{
+  "id": "paniers_by_users",
+  "label": "Paniers",
+  "categories": {
+    "1020": {
+      "id": "cart-owner-id-1020",
+      "label": "Administrateur",
+      "categories": [],
+      "items": [
+        {
+          "id": 111,
+          "label": "201111-jeunesse",
+          "options": {
+            "ico": "/public/admin/images/picto/paniers_16.png"
+          }
+        },
+        {
+          "id": 112,
+          "label": "201111-ados",
+          "options": {
+            "ico": "/public/admin/images/picto/paniers_16.png"
+          }
+        },
+        {
+          "id": 113,
+          "label": "201111-adultes",
+          "options": {
+            "ico": "/public/admin/images/picto/paniers_16.png"
+          }
+        },
+        {
+          "id": 114,
+          "label": "201222-jeunesse",
+          "options": {
+            "ico": "/public/admin/images/picto/paniers_16.png"
+          }
+        },
+        {
+          "id": 115,
+          "label": "201222-ados",
+          "options": {
+            "ico": "/public/admin/images/picto/paniers_16.png"
+          }
+        },
+        {
+          "id": 116,
+          "label": "201222-adultes",
+          "options": {
+            "ico": "/public/admin/images/picto/paniers_16.png"
+          }
+        },
+        {
+          "id": 117,
+          "label": "201222-cdc",
+          "options": {
+            "ico": "/public/admin/images/picto/paniers_16.png"
+          }
+        }
+      ],
+      "options": {
+        "ico": "/public/admin/images/picto/abonnes.gif",
+        "removeCheckbox": true
+      }
+    }
+  },
+  "items": [],
+  "options": {
+    "multipleSelection": false
+  }
+}];
+
+function pack_ids(ids) {
+  return $.map(ids, function(d) { return d.id; }).join('-');
+};
+
+function call_treeselect() {
+  $('.treeselect.id_catalogue')
+    .treeselect({ datas: datas })
+    .treeselect('selectItems', [])
+    .treeselect('selectCategories', [])
+    .treeselect('toggleVisibility', true)
+    .treeselect('disableMultipleSelection');
+
+  $("form").submit(function() {
+    $(".treeselect").each(function(index) {
+      var node = $(this);
+      node.treeselect("readSelection",
+                      function(items, categories) {
+                        node.siblings("input:hidden:nth-child(2)").val(pack_ids(categories));
+                        node.siblings("input:hidden:nth-child(3)").val(pack_ids(items));
+                      });
+    });
+  });
+};
+
+function init_and_search(value) {
+  call_treeselect();
+  $('.ui-treeselect-search').find('input[type=textfield]').val(value);
+  $('.ui-treeselect-search').find('input[type=textfield]').trigger($.Event('keyup', { keyCode: 0 }));
+  return $('.ui-treeselect-category').find('li:visible');
+}
+
+
+test('Search "biq" will display no item', function() {
+  var visibles = init_and_search('biq');
+  equal(visibles.length, 0);
+});
+
+test('Search "2011" will display 3 items', function() {
+  var visibles = init_and_search('2011');
+  equal(visibles.length, 3);
+  equal(visibles[0].textContent, '201111-jeunesse');
+  equal(visibles[1].textContent, '201111-ados');
+  equal(visibles[2].textContent, '201111-adultes');
+});
+
+test('Search "2012" will display 4 items', function() {
+  var visibles = init_and_search('2012');
+  equal(visibles.length, 4);
+  equal(visibles[0].textContent, '201222-jeunesse');
+  equal(visibles[1].textContent, '201222-ados');
+  equal(visibles[2].textContent, '201222-adultes');
+  equal(visibles[3].textContent, '201222-cdc');
+});
+
+test('Search "ados" will display 2 items', function() {
+  var visibles = init_and_search('ados');
+  equal(visibles.length, 2);
+  equal(visibles[0].textContent, '201111-ados');
+  equal(visibles[1].textContent, '201222-ados');
+});
+
+test('Search"cdc" will display 1 item', function() {
+  var visibles = init_and_search('cdc');
+  equal(visibles.length, 1);
+  equal(visibles[0].textContent, '201222-cdc');
+});
diff --git a/public/admin/js/treeselect/tests.html b/public/admin/js/treeselect/tests.html
new file mode 100644
index 00000000000..211cc287df9
--- /dev/null
+++ b/public/admin/js/treeselect/tests.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<!--
+/**
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+  -->
+
+<html>
+<head>
+  <meta charset="utf-8">
+  <title>QUnit tests</title>
+  <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css">
+</head>
+<body>
+  <div id="qunit"></div>
+  <div id="qunit-fixture"></div>
+  <script type="text/javascript" src="../jquery-3.2.1.min.js"></script>
+  <script type="text/javascript" src="../jquery-ui-1.12.1/jquery-ui.min.js"></script>
+  <script src="treeselect.js"></script>
+  <script src="http://code.jquery.com/qunit/qunit-1.13.0.js"></script>
+  <script src="test.js"></script>
+  <form>
+    <div class="treeselect id_catalogue ui-widget ui-helper-reset"></div>
+  </form>
+</body>
+</html>
diff --git a/public/admin/js/treeselect/treeselect.js b/public/admin/js/treeselect/treeselect.js
index 0c88d923e45..dea80b5d5b0 100644
--- a/public/admin/js/treeselect/treeselect.js
+++ b/public/admin/js/treeselect/treeselect.js
@@ -467,27 +467,26 @@
 	return;
       }
 
-      accentsTidy = function(s){
-        var r=s.toLowerCase();
-        r = r.replace(new RegExp("[àáâãäå]", 'g'),"a");
-        r = r.replace(new RegExp("æ", 'g'),"ae");
-        r = r.replace(new RegExp("ç", 'g'),"c");
-        r = r.replace(new RegExp("[èéêë]", 'g'),"e");
-        r = r.replace(new RegExp("[ìíîï]", 'g'),"i");
-        r = r.replace(new RegExp("ñ", 'g'),"n");
-        r = r.replace(new RegExp("[òóôõö]", 'g'),"o");
-        r = r.replace(new RegExp("Å“", 'g'),"oe");
-        r = r.replace(new RegExp("[ùúûü]", 'g'),"u");
-        r = r.replace(new RegExp("[ýÿ]", 'g'),"y");
-        return r;
+      accentsTidy = function (s) {
+        var r = s.toLowerCase();
+        r = r.replace(new RegExp("[àáâãäå]", 'g'), "a");
+        r = r.replace(new RegExp("æ", 'g'), "ae");
+        r = r.replace(new RegExp("ç", 'g'), "c");
+        r = r.replace(new RegExp("[èéêë]", 'g'), "e");
+        r = r.replace(new RegExp("[ìíîï]", 'g'), "i");
+        r = r.replace(new RegExp("ñ", 'g'), "n");
+        r = r.replace(new RegExp("[òóôõö]", 'g'), "o");
+        r = r.replace(new RegExp("Å“", 'g'), "oe");
+        r = r.replace(new RegExp("[ùúûü]", 'g'), "u");
+        return r.replace(new RegExp("[ýÿ]", 'g'), "y");
       };
 
       searchText = accentsTidy(searchText);
 
-      var re = new RegExp('\\b' + searchText, 'gi');
       var matches = this.itemsTree.find('li, h3').filter(function() {
-	return re.test(accentsTidy($(this).text()));
+        return accentsTidy($(this).text()).indexOf(searchText) > -1;
       });
+
       this._highlightItems(matches);
       matches.parents(".ui-accordion-content").show();
     },
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 0dc28b4a65b..407f3f5c349 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -96,6 +96,7 @@ require_once 'tests/library/Class/WebService/SIGB/TestingService.php';
 require_once 'tests/fixtures/RessourcesNumeriquesFixtures.php';
 require_once 'tests/fixtures/MockedClasses.php';
 require_once 'tests/application/modules/telephone/controllers/TelephoneAbstractControllerTestCase.php';
+require_once 'tests/js/PhantomJsTest.php';
 
 register_shutdown_function(function(){
   TestSpeedTrap::printSpeedTrappedTests();
diff --git a/tests/js/AuthorityPickerTest.php b/tests/js/AuthorityPickerTest.php
index dd04f7b4099..cc25800058e 100644
--- a/tests/js/AuthorityPickerTest.php
+++ b/tests/js/AuthorityPickerTest.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
  *
  * BOKEH is free software; you can redistribute it and/or modify
  * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
@@ -20,12 +20,6 @@
  */
 
 
-class AuthorityPickerTest extends PHPUnit_Framework_TestCase {
-
-  /** @test */
-  public function searchInputJStestShouldSuccess() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/js/authority_picker/tests.html', $output, $result);
-  $this->assertEquals(0, $result, implode("\n", $output));
-  }
+class AuthorityPickerTest extends PhantomJsTest {
+  protected $_test_path = 'public/opac/js/authority_picker/tests.html';
 }
-?>
\ No newline at end of file
diff --git a/tests/js/CustomFieldsReportTest.php b/tests/js/CustomFieldsReportTest.php
index a4ccd327ec9..3fa7a9c0fc1 100644
--- a/tests/js/CustomFieldsReportTest.php
+++ b/tests/js/CustomFieldsReportTest.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
  *
  * BOKEH is free software; you can redistribute it and/or modify
  * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
@@ -16,15 +16,10 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with BOKEH; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
-class CustomFieldsReportTest extends PHPUnit_Framework_TestCase {
-  /** @test */
-  public function customFieldsReportMethodsJStestShouldSuccess() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/admin/js/custom-fields/tests/custom_fields.html', $output, $result);
-  $this->assertEquals(0, $result, implode("\n", $output));
-  }
+class CustomFieldsReportTest extends PhantomJsTest {
+  protected $_test_path = 'public/admin/js/custom-fields/tests/custom_fields.html';
 }
-?>
\ No newline at end of file
diff --git a/tests/js/MultiInputTest.php b/tests/js/MultiInputTest.php
index c8e31d7df2e..266f248414a 100644
--- a/tests/js/MultiInputTest.php
+++ b/tests/js/MultiInputTest.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
  *
  * BOKEH is free software; you can redistribute it and/or modify
  * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
@@ -20,11 +20,6 @@
  */
 
 
-class MultiInputTest extends PHPUnit_Framework_TestCase {
-
-  /** @test */
-  public function multiInputJstestShouldSuccess() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/admin/js/multi_inputs/tests.html', $output, $result);
-    $this->assertEquals(0, $result, implode("\n", $output));
-  }
-}
\ No newline at end of file
+class MultiInputTest extends PhantomJsTest {
+  protected $_test_path = 'public/admin/js/multi_inputs/tests.html';
+}
diff --git a/tests/js/MultiSelectionTest.php b/tests/js/MultiSelectionTest.php
index cff8067164a..a6f29fa1075 100644
--- a/tests/js/MultiSelectionTest.php
+++ b/tests/js/MultiSelectionTest.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
  *
  * BOKEH is free software; you can redistribute it and/or modify
  * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
@@ -20,11 +20,6 @@
  */
 
 
-class MultiSelectionTest extends PHPUnit_Framework_TestCase {
-
-  /** @test */
-  public function multiSelectJstestShouldSuccess() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/admin/js/multi_selection/tests.html', $output, $result);
-    $this->assertEquals(0, $result, implode("\n", $output));
-  }
-}
\ No newline at end of file
+class MultiSelectionTest extends PhantomJsTest {
+  protected $_test_path = 'public/admin/js/multi_selection/tests.html';
+}
diff --git a/tests/js/PhantomJsTest.php b/tests/js/PhantomJsTest.php
new file mode 100644
index 00000000000..0e2d3aa4928
--- /dev/null
+++ b/tests/js/PhantomJsTest.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+abstract class PhantomJsTest extends PHPUnit_Framework_TestCase {
+  /** array or string */
+  protected $_test_path;
+
+
+  public function testPaths() {
+    if (!$this->_test_path)
+      return [];
+
+    if (!is_array($this->_test_path))
+      $this->_test_path = [$this->_test_path];
+
+    return array_map(function($path) { return [$path]; },
+                     $this->_test_path);
+  }
+
+
+  /**
+   * @test
+   * @dataProvider testPaths
+   **/
+  public function jsTestShouldSucceed($path) {
+    exec('phantomjs '
+         . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js '
+         . escapeshellarg(ROOT_PATH . $path),
+         $output,
+         $result);
+
+    $this->assertEquals(0, $result, implode("\n", $output));
+  }
+}
diff --git a/tests/js/SearchAutocompleteTest.php b/tests/js/SearchAutocompleteTest.php
index 3266e81964e..9d0e69a1a95 100644
--- a/tests/js/SearchAutocompleteTest.php
+++ b/tests/js/SearchAutocompleteTest.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
  *
  * BOKEH is free software; you can redistribute it and/or modify
  * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
@@ -16,17 +16,10 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with BOKEH; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 
 
-class SearchAutocomplete extends PHPUnit_Framework_TestCase {
-
-
-  /** @test */
-  public function searchAutocompleteJStestShouldSuccess() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/search_autocomplete/tests/search_autocomplete.html', $output, $result);
-    $this->assertEquals(0, $result, implode("\n", $output));
-  }
+class SearchAutocomplete extends PhantomJsTest {
+  protected $_test_path = 'public/opac/java/search_autocomplete/tests/search_autocomplete.html';
 }
-?>
\ No newline at end of file
diff --git a/tests/js/SearchInputTest.php b/tests/js/SearchInputTest.php
index d843ee3f83b..45046b64b8a 100644
--- a/tests/js/SearchInputTest.php
+++ b/tests/js/SearchInputTest.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
  *
  * BOKEH is free software; you can redistribute it and/or modify
  * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
@@ -20,12 +20,6 @@
  */
 
 
-class SearchInputTest extends PHPUnit_Framework_TestCase {
-
-  /** @test */
-  public function searchInputJStestShouldSuccess() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/search_input/tests/search_input.html', $output, $result);
-  $this->assertEquals(0, $result, implode("\n", $output));
-  }
+class SearchInputTest extends PhantomJsTest {
+  protected $_test_path = 'public/opac/java/search_input/tests/search_input.html';
 }
-?>
\ No newline at end of file
diff --git a/tests/js/SliderNavigationTest.php b/tests/js/SliderNavigationTest.php
index 1abb79c512e..624bfb5f931 100644
--- a/tests/js/SliderNavigationTest.php
+++ b/tests/js/SliderNavigationTest.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
  *
  * BOKEH is free software; you can redistribute it and/or modify
  * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
@@ -20,26 +20,8 @@
  */
 
 
-class SliderNavigationTest extends PHPUnit_Framework_TestCase {
-
-  /** @test */
-  public function newsSliderJStestShouldSuccess() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/slider_navigation/tests/news_slider.html', $output, $result);
-    $this->assertEquals(0, $result, implode("\n", $output));
-  }
-
-
-  /** @test */
-  public function agendaSliderJStestShouldSuccess() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/slider_navigation/tests/agenda_slider.html', $output, $result);
-    $this->assertEquals(0, $result, implode("\n", $output));
-  }
-
-
-  /** @test */
-  public function sliderWithPreviewJSTestShouldSucced() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/opac/java/slider_navigation/tests/preview_slider.html', $output, $result);
-    $this->assertEquals(0, $result, implode("\n", $output));
-  }
+class SliderNavigationTest extends PhantomJsTest {
+  protected $_test_path = ['public/opac/java/slider_navigation/tests/news_slider.html',
+                           'public/opac/java/slider_navigation/tests/agenda_slider.html',
+                           'public/opac/java/slider_navigation/tests/preview_slider.html'];
 }
-?>
\ No newline at end of file
diff --git a/tests/js/TreeSelectTest.php b/tests/js/TreeSelectTest.php
new file mode 100644
index 00000000000..849c3c58732
--- /dev/null
+++ b/tests/js/TreeSelectTest.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+
+class TreeSelectTest extends PhantomJsTest {
+  protected $_test_path = 'public/admin/js/treeselect/tests.html';
+}
diff --git a/tests/js/UserSelectionTest.php b/tests/js/UserSelectionTest.php
index fcf8d79a4db..35a7fabd011 100644
--- a/tests/js/UserSelectionTest.php
+++ b/tests/js/UserSelectionTest.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
+ * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved.
  *
  * BOKEH is free software; you can redistribute it and/or modify
  * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
@@ -20,10 +20,6 @@
  */
 
 
-class UserSelectionTest extends PHPUnit_Framework_TestCase {
-  /** @test */
-  public function userSelectionTestShouldSuccess() {
-    exec('phantomjs ' . ROOT_PATH . 'tests_js/lib/qunit-phantomjs-runner/runner.js ' . ROOT_PATH . 'public/admin/js/user_selection/tests.html', $output, $result);
-    $this->assertEquals(0, $result, implode("\n", $output));
-  }
-}
\ No newline at end of file
+class UserSelectionTest extends PhantomJsTest {
+  protected $_test_path = 'public/admin/js/user_selection/tests.html';
+}
-- 
GitLab