From d55abf502f1a37ce7fd68e8a14c8fd18193422cc Mon Sep 17 00:00:00 2001
From: Vinciane <vinciane.bizet@maarch.org>
Date: Wed, 16 Jan 2019 13:55:11 +0100
Subject: [PATCH] FEAT # 9304 Last tag in update

---
 .../controllers/VersionUpdateController.php   | 14 +++++++++-----
 ...sions-update-administration.component.html |  8 ++++----
 .../VersionUpdateControllerTest.php           | 19 +++++++++++++++----
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/src/app/versionUpdate/controllers/VersionUpdateController.php b/src/app/versionUpdate/controllers/VersionUpdateController.php
index 801e9d59123..94fe0cb590b 100755
--- a/src/app/versionUpdate/controllers/VersionUpdateController.php
+++ b/src/app/versionUpdate/controllers/VersionUpdateController.php
@@ -42,7 +42,7 @@ class VersionUpdateController
         $currentVersionBranchMonth = substr($parameter['param_value_string'], 3, 2);
         $currentVersionTag = substr($parameter['param_value_string'], 6);
 
-        $currentMinorVersions = [];
+        $availableMinorVersions = [];
         $availableMajorVersions = [];
 
         foreach ($tags as $value) {
@@ -59,15 +59,19 @@ class VersionUpdateController
                 }
             } else {
                 if ($tag > $currentVersionTag) {
-                    $currentMinorVersions[] = $value['name'];
+                    $availableMinorVersions[] = $value['name'];
                 }
             }
         }
 
+        //Sort array using a case insensitive "natural order" algorithm
+        natcasesort($availableMinorVersions);
+        natcasesort($availableMajorVersions);
+
         return $response->withJson([
-            'currentMinorVersions'      => $currentMinorVersions,
-            'availableMajorVersions'    => $availableMajorVersions,
-            'currentVersion'            => $parameter['param_value_string']
+            'lastAvailableMinorVersion'   => $availableMinorVersions[0],
+            'lastAvailableMajorVersion'    => $availableMajorVersions[0],
+            'currentVersion'           => $parameter['param_value_string']
         ]);
     }
 }
diff --git a/src/frontend/app/administration/versionUpdate/versions-update-administration.component.html b/src/frontend/app/administration/versionUpdate/versions-update-administration.component.html
index f33a9831514..ff5597d5da2 100755
--- a/src/frontend/app/administration/versionUpdate/versions-update-administration.component.html
+++ b/src/frontend/app/administration/versionUpdate/versions-update-administration.component.html
@@ -40,19 +40,19 @@
                 <mat-spinner style="margin:auto;"></mat-spinner>
             </div>
             <mat-card *ngIf="!loading" class="card-app-content">
-                <div class="alert alert-info" *ngIf="versions.currentMinorVersions.length == 0" style="display: flex;">
+                <div class="alert alert-info" *ngIf="versions.lastAvailableMinorVersion==null" style="display: flex;">
                     <mat-icon class="fa fa-check fa-2x" style="flex: 1;text-align: left;"></mat-icon> 
                     <span style="flex: 1;text-align: center;">{{lang.appUpToDate}} !</span>
                     <mat-icon class="fa fa-check fa-2x" style="flex: 1;text-align: right;"></mat-icon>
                 </div>
-                <div class="alert alert-success" *ngIf="versions.currentMinorVersions.length > 0" style="display: flex;">
+                <div class="alert alert-success" *ngIf="versions.lastAvailableMinorVersion!=null" style="display: flex;">
                     <mat-icon class="fa fa-info-circle fa-2x" style="flex: 1;text-align: left;"></mat-icon> 
                     <span style="flex: 1;text-align: center;">
-                        {{lang.newVersionAvailable}} ! <a style="font-weight: bold;" href="https://labs.maarch.org/maarch/MaarchCourrier/tags/{{versions.currentMinorVersions[versions.currentMinorVersions.length-1]}}" target="_blank">{{versions.currentMinorVersions[versions.currentMinorVersions.length-1]}}</a>
+                        {{lang.newVersionAvailable}} ! <a style="font-weight: bold;" href="https://labs.maarch.org/maarch/MaarchCourrier/tags/{{versions.lastAvailableMinorVersion}}" target="_blank">{{versions.lastAvailableMinorVersion}}</a>
                     </span>
                     <mat-icon class="fa fa-info-circle fa-2x" style="flex: 1;text-align: right;"></mat-icon>
                 </div>
-                <div class="col-sm-12" style="text-align:center;" *ngIf="versions.currentMinorVersions.length > 0">
+                <div class="col-sm-12" style="text-align:center;" *ngIf="versions.lastAvailableMinorVersion!=null">
                     <button mat-raised-button color="primary" (click)="updateVersionAccess();">{{lang.accessUpdateWizard}}</button>
                 </div>
             </mat-card>
diff --git a/test/unitTests/app/versionUpdate/VersionUpdateControllerTest.php b/test/unitTests/app/versionUpdate/VersionUpdateControllerTest.php
index c691e07c74d..29fb809bba1 100755
--- a/test/unitTests/app/versionUpdate/VersionUpdateControllerTest.php
+++ b/test/unitTests/app/versionUpdate/VersionUpdateControllerTest.php
@@ -21,10 +21,21 @@ class VersionUpdateControllerTest extends TestCase
         $response       = $versionUpdateController->get($request, new \Slim\Http\Response());
         $responseBody   = json_decode((string)$response->getBody());
 
-        $this->assertInternalType('array', $responseBody->currentMinorVersions);
-        $this->assertNotNull($responseBody->currentMinorVersions);
-        $this->assertInternalType('array', $responseBody->availableMajorVersions);
         $this->assertInternalType('string', $responseBody->currentVersion);
         $this->assertNotNull($responseBody->currentVersion);
+        $this->assertRegExp('/^[0-9]{2}.[0-9]{2}.[0-9]{1,2}$/', $responseBody->currentVersion, 'Invalid current version');
+
+        if( $responseBody->lastAvailableMinorVersion != null ) {
+            $this->assertInternalType('string', $responseBody->lastAvailableMinorVersion);
+            $this->assertRegExp('/^[0-9]{2}.[0-9]{2}.[0-9]{1,2}$/', $responseBody->lastAvailableMinorVersion, 'Invalid available minor version');
+        }
+
+        if( $responseBody->lastAvailableMajorVersion != null ) {
+            $this->assertInternalType('string', $responseBody->lastAvailableMajorVersion);
+            $this->assertRegExp('/^[0-9]{2}.[0-9]{2}.[0-9]{1,2}$/', $responseBody->lastAvailableMajorVersion, 'Invalid available major version');
+        }
+
+        $this->assertNotNull($responseBody->lastAvailableMinorVersion);
+        
     }
-}
+}
\ No newline at end of file
-- 
GitLab