Commit 43d37f57 authored by Tomas Norre Mikkelsen's avatar Tomas Norre Mikkelsen

[TASK] Add LTSVersionService

parent 751c4d72
Pipeline #3283 passed with stages
in 3 minutes and 18 seconds
This diff is collapsed.
<?php
namespace T3o\TerFe2\Service;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
/**
* Class LTSVersionService
*/
class LTSVersionService
{
/**
* @var string
*/
public $coreData = '';
public function __construct()
{
// Will be automatically update with UpdateCurrentVersionListTask see T3o\Ter\Task\UpdateCurrentVersionListTask
$sourceFile = PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'currentcoredata.json';
$json = file_get_contents($sourceFile);
$this->coreData = json_decode($json, true);
}
/**
* Get the current stable versions
*
* @return array
*/
public function getCurrentStableVersions()
{
return [
$this->getLatestOldLTS(),
$this->getLatestLTS()
];
}
/**
* Returns all maintained versions.
*
* @return array
*/
public function getAllMaintainedVersions()
{
$versions = $this->getCurrentStableVersions();
array_push($versions, $this->getLatestDevelopmentVersion());
return $versions;
}
/**
* Get latest version within a specific release
*
* @param int $release
* @return string
*/
public function getLatestVersionOfRelease($release)
{
$versions = [];
foreach($this->coreData[$release]['releases'] as $release) {
$versions[] = VersionNumberUtility::convertVersionNumberToInteger($release['version']);
}
sort($versions);
return VersionNumberUtility::convertIntegerToVersionNumber(array_pop($versions));
}
/**
* Get latest development version
*
* @return string
*/
public function getLatestDevelopmentVersion()
{
return substr($this->coreData['latest_stable'], 0, 3);
}
/**
* Get latest LTS Version
*
* @return int
*/
private function getLatestLTS()
{
return (int) substr($this->coreData['latest_lts'], 0, 1);
}
/**
* Get latest "old" LTS Version
*
* @return int
*/
private function getLatestOldLTS()
{
return (int) substr($this->coreData['latest_old_lts'], 0, 1);
}
}
\ No newline at end of file
<?php
namespace T3o\TerFe2\Tests\Service;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use Nimut\TestingFramework\TestCase\UnitTestCase;
use T3o\TerFe2\Service\LTSVersionService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class LTSVersionService
* @package T3o\TerFe2\Tests\Service
*/
class LTSVersionServiceTest extends UnitTestCase
{
/**
* @var LTSVersionService
*/
protected $subject;
protected function setUp()
{
$this->subject = GeneralUtility::makeInstance(LTSVersionService::class);
$this->subject->coreData = $this->getSampleData();
}
/**
* @test
*/
public function getCurrentStableVersions()
{
$this->assertSame([7, 8], $this->subject->getCurrentStableVersions());
}
/**
* @test
*/
public function getAllMaintainedVersions()
{
$this->assertSame([7, 8, '9.0'], $this->subject->getAllMaintainedVersions());
}
/**
* @test
*/
public function getLatestVersionOfRelease()
{
$this->assertSame('7.6.21', $this->subject->getLatestVersionOfRelease(7));
}
/**
* @test
*/
public function getLatestDevelopmentVersion()
{
$this->assertSame('9.0', $this->subject->getLatestDevelopmentVersion());
}
/**
* Return Sample Json Data for testing purpose
*
* @return array
*/
private function getSampleData()
{
$versions = [
'7' => [
'releases' => [
'7.6.23' => [
'version' => '7.6.21'
],
'7.6.22' => [
'version' => '7.6.20'
],
'7.6.21' => [
'version' => '7.6.19'
],
]
],
'latest_stable' => '9.0.0',
'latest_old_stable' => '8.7.9',
'latest_lts' => '8.7.9',
'latest_old_lts' => '7.6.21'
];
return $versions;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment