From 3de63f56fd2901bf7bd5ba71de19069c6b898df1 Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Tue, 17 Jan 2017 10:25:41 +0100
Subject: [PATCH] status report: do not send data for digital connectors with
 no album and disabled

---
 library/Class/Systeme/Report.php              |  2 +-
 .../ZendAfi/View/Helper/Status/JsonTest.php   | 32 +++++++------------
 .../ZendAfi/View/Helper/Status/TestCase.php   |  4 +++
 3 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/library/Class/Systeme/Report.php b/library/Class/Systeme/Report.php
index 2a7ed1b5478..cc1781a8e09 100644
--- a/library/Class/Systeme/Report.php
+++ b/library/Class/Systeme/Report.php
@@ -205,7 +205,7 @@ class Class_Systeme_Report_DigitalConnectors extends Class_Systeme_Report_Abstra
     if ($description['doctype_id'] && in_array('HARVEST', $description['features']))
       $record['album_count'] = Class_Album::countBy(['type_doc_id' => $description['doctype_id']]);
 
-    if ($description['enabled'] || isset($record['album_count']))
+    if ($description['enabled'] || (isset($record['album_count']) && $record['album_count']))
       $visitor->visitRecordValues($record);
   }
 }
diff --git a/tests/library/ZendAfi/View/Helper/Status/JsonTest.php b/tests/library/ZendAfi/View/Helper/Status/JsonTest.php
index 79353089187..bd2804986c9 100644
--- a/tests/library/ZendAfi/View/Helper/Status/JsonTest.php
+++ b/tests/library/ZendAfi/View/Helper/Status/JsonTest.php
@@ -284,27 +284,17 @@ class ZendAfi_View_Helper_Status_JsonTest extends ZendAfi_View_Helper_Status_Tes
 
 
   /** @test */
-  public function OrpheaShouldEnabled() {
-    $this->assertContains(["code" => "ORPHEA",
-                         "label"  =>  "Orphea",
-                         "enabled" => true,
-                           "features" => ["HARVEST", "SSO"],
-                         "album_count" => 0
-                         ],
-                        $this->_report['digital_connectors']);
+  public function OrpheaShouldNotBePresent() {
+    $this->assertNotContains(["code" => "ORPHEA",
+                              "label"  =>  "Orphea",
+                              "enabled" => false,
+                              "features" => ["HARVEST", "SSO"],
+                              "album_count" => 0
+                              ],
+                             $this->_report['digital_connectors']);
   }
 
 
-  /** @test */
-  public function MyCowShouldEnabled() {
-    $this->assertContains(["code" => "MYCOW",
-                           "label"  =>  "MyCoW",
-                           "enabled" => true,
-                           "features" => ["SSO"],
-                           ],
-                          $this->_report['digital_connectors']);
-  }
-
   /** @test */
   public function PlanetNemoShouldEnabled() {
     $this->assertContains(["code" => "PLANETNEMO",
@@ -373,7 +363,7 @@ class ZendAfi_View_Helper_Status_JsonTest extends ZendAfi_View_Helper_Status_Tes
 
 
   /** @test */
-  public function CiteDeLaMusiqueShouldEnabled() {
+  public function CiteDeLaMusiqueShouldBeEnabled() {
     $this->assertContains(["code" => "CITEDELAMUSIQUE",
                            "label"  =>  "Cité de la musique",
                            "enabled" => true,
@@ -386,12 +376,12 @@ class ZendAfi_View_Helper_Status_JsonTest extends ZendAfi_View_Helper_Status_Tes
 
 
   /** @test */
-  public function SoundCloudShouldDisabled() {
+  public function SoundCloudShouldDisabledButPresent() {
     $this->assertContains(["code" => "SoundCloud",
                            "label"  =>  "SoundCloud",
                            "enabled" => false,
                            "features" => ["HARVEST"],
-                           "album_count" => 0
+                           "album_count" => 1
                          ],
                         $this->_report['digital_connectors']);
   }
diff --git a/tests/library/ZendAfi/View/Helper/Status/TestCase.php b/tests/library/ZendAfi/View/Helper/Status/TestCase.php
index eb1f5ab1ce3..d9cd2d931d7 100644
--- a/tests/library/ZendAfi/View/Helper/Status/TestCase.php
+++ b/tests/library/ZendAfi/View/Helper/Status/TestCase.php
@@ -105,6 +105,10 @@ abstract class ZendAfi_View_Helper_Status_TestCase extends ViewHelperTestCase {
 
   protected function _setupDigitalResources() {
     RessourcesNumeriquesFixtures::activate();
+    RessourcesNumeriquesFixtures::deactivateOrphea();
+    $this->fixture('Class_Album',
+                   ['id' => 1,
+                    'type_doc_id' => Class_TypeDoc::SOUNDCLOUD]);
     return $this;
 
   }
-- 
GitLab