From 3e51d1f6e7fc98e095904c30ea0feee44b3bd6ed Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Thu, 6 Oct 2016 16:03:57 +0200
Subject: [PATCH] dev #47780 : refacto digital ressource batch

---
 library/Class/DigitalResource/Batch.php       | 42 +++++++++++++++++++
 library/Class/DigitalResource/Config.php      |  4 +-
 library/digital_resources/Assimil/Batch.php   | 11 +----
 .../Assimil/tests/AssimilTest.php             |  8 ++++
 4 files changed, 53 insertions(+), 12 deletions(-)
 create mode 100644 library/Class/DigitalResource/Batch.php

diff --git a/library/Class/DigitalResource/Batch.php b/library/Class/DigitalResource/Batch.php
new file mode 100644
index 00000000000..a28357b3b93
--- /dev/null
+++ b/library/Class/DigitalResource/Batch.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Copyright (c) 2012-2014, 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 Class_DigitalResource_Batch extends Class_Batch_RessourceNumerique{
+
+  public static function getName() {
+    $path = array_reverse(explode('/', dirname((new ReflectionClass(static::class))->getFileName())));
+    return array_shift($path);
+  }
+
+
+  protected function _getService() {
+    $config = Class_DigitalResource_Config::getInstance(static::getName());
+    $service = $config->getService();
+    return new $service;
+  }
+
+
+  public function isEnabled() {
+    $config = Class_DigitalResource_Config::getInstance(static::getName());
+    return $config->isEnabled();
+  }
+}
diff --git a/library/Class/DigitalResource/Config.php b/library/Class/DigitalResource/Config.php
index e8b967af36c..59e3aac680a 100644
--- a/library/Class/DigitalResource/Config.php
+++ b/library/Class/DigitalResource/Config.php
@@ -32,10 +32,10 @@ class Class_DigitalResource_Config extends Class_Entity {
   }
 
 
-  public static function getInstance() {
+  public static function getInstance($plugin = '') {
     return static::$_instance = static::$_instance
       ? static::$_instance
-      : (new Class_DigitalResource())->configFor(static::getName());
+      : (new Class_DigitalResource())->configFor($plugin ? $plugin : static::getName());
   }
 
 
diff --git a/library/digital_resources/Assimil/Batch.php b/library/digital_resources/Assimil/Batch.php
index 80f871cee63..d212dd6d618 100644
--- a/library/digital_resources/Assimil/Batch.php
+++ b/library/digital_resources/Assimil/Batch.php
@@ -20,13 +20,4 @@
  */
 
 
-class Assimil_Batch extends Class_Batch_RessourceNumerique{
-  protected function _getService() {
-    return new Assimil_Service();
-  }
-
-
-  public function isEnabled() {
-    return Assimil_Config::getInstance()->isEnabled();
-  }
-}
+class Assimil_Batch extends Class_DigitalResource_Batch {}
diff --git a/library/digital_resources/Assimil/tests/AssimilTest.php b/library/digital_resources/Assimil/tests/AssimilTest.php
index e4803ba9648..e4ed9493b92 100644
--- a/library/digital_resources/Assimil/tests/AssimilTest.php
+++ b/library/digital_resources/Assimil/tests/AssimilTest.php
@@ -136,6 +136,14 @@ class AssimilActivatedAdminTest extends Admin_AbstractControllerTestCase {
   }
 
 
+  /** @test */
+  public function batchAssimilShouldBePresent() {
+    $this->dispatch('/admin/batch', true);
+    $this->assertXPathContentContains('//tbody//tr//td',
+                                      Class_Batch::getBatchLibelle('Assimil_Batch'));
+  }
+
+
   /** @test */
   public function userGroupPermissionsShouldContainsAssimil() {
     $this->dispatch('admin/usergroup/edit/id/1', true);
-- 
GitLab