Browse Source

display futures versions (fixes #8)

merge-requests/10/merge
JamesRezo 2 years ago
parent
commit
96ed5bb95a
  1. 8
      CHANGELOG
  2. 36
      modeles/supportedversions_calendar.html
  3. 6
      modeles/supportedversions_latest.html
  4. 189
      supportedversions_fonctions.php
  5. 2
      tests/FunctionsTest.php
  6. 2
      tests/SupportedVersions.php
  7. 277
      tests/SupportedVersionsTest.php
  8. 2
      tests/TestCase.php
  9. 51
      tests/releases/init.json

8
CHANGELOG

@ -15,6 +15,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `<supportedversions|latest>` model
- `<supportedversions|eol>` model
- Unit Tests with PHPUnit
- Filter `|SupportedVersions::stateOrGradient`
- Filter `|SupportedVersions::rectWidth`
- Ability to display future versions if a release date is planned
### Removed
- Filter `|SupportedVersions::stableOrGradient`
- Filter `|SupportedVersions::securityOrGradient`
## [0.2.4] - 2020-10-02
### Changed

36
modeles/supportedversions_calendar.html

@ -3,6 +3,13 @@
width="[(#SUPPORTED_VERSIONS{svg/margin_left}|SupportedVersions::width)]"
height="[(#SUPPORTED_VERSIONS{svg/header_height}|SupportedVersions::height)]"
>
<defs>
<linearGradient id="gradient-future"
x1="0" y1="0" x2="100%" y2="0">
<stop offset="0%" stop-color="[(#SUPPORTED_VERSIONS{colors/future/background})]" />
<stop offset="100%" stop-color="#fff" />
</linearGradient>
</defs>
<defs>
<linearGradient id="gradient-stable"
x1="0" y1="0" x2="100%" y2="0">
@ -56,6 +63,10 @@
fill: [(#SUPPORTED_VERSIONS{colors/future/background})];
}
.supver_branches rect.supver_future-gradient {
fill: url(#gradient-future);
}
.supver_branch-labels text {
dominant-baseline: central;
text-anchor: middle;
@ -85,7 +96,7 @@
<!-- Branch labels -->
<g class="supver_branch-labels">
<BOUCLE_labels(DATA){source table, #VAL{true}|SupportedVersions::branchesToShow}>
<g[ class="supver_(#VALEUR|SupportedVersions::state)"]>
[<g class="supver_(#VALEUR|SupportedVersions::state)">
<rect
x="0"
y="[(#BRANCH|SupportedVersions::top)]"
@ -105,20 +116,27 @@
<!-- Branch blocks -->
<g class="supver_branches">
<BOUCLE_active_branches(DATA){source table, #VAL{true}|SupportedVersions::branchesToShow}>
<rect
class="[supver_(#ACTIVE_SUPPORT|SupportedVersions::stableOrGradient)]"
[<rect
class="supver_(#BRANCH|SupportedVersions::stateOrGradient{stable})"
x="[(#INITIAL_RELEASE|SupportedVersions::horizCoord)]"
y="[(#BRANCH|SupportedVersions::top)]"
width="[(#ACTIVE_SUPPORT|SupportedVersions::horizCoord|strmoins{#INITIAL_RELEASE|SupportedVersions::horizCoord})]"
[width="(#BRANCH|SupportedVersions::rectWidth{stable})"]
height="#SUPPORTED_VERSIONS{svg/branch_height}"
/>
<rect
class="[supver_(#EOL|SupportedVersions::securityOrGradient)]"
/>]
[<rect
class="supver_(#BRANCH|SupportedVersions::stateOrGradient{security})"
x="[(#ACTIVE_SUPPORT|SupportedVersions::horizCoord)]"
y="[(#BRANCH|SupportedVersions::top)]"
width="[(#EOL|SupportedVersions::horizCoord|strmoins{#ACTIVE_SUPPORT|SupportedVersions::horizCoord})]"
[width="(#BRANCH|SupportedVersions::rectWidth{security})"]
height="#SUPPORTED_VERSIONS{svg/branch_height}"
/>
/>]
[<rect
class="supver_(#BRANCH|SupportedVersions::stateOrGradient{future})"
x="[(#INITIAL_RELEASE|SupportedVersions::horizCoord)]"
y="[(#BRANCH|SupportedVersions::top)]"
[width="(#BRANCH|SupportedVersions::rectWidth{future})"]
height="#SUPPORTED_VERSIONS{svg/branch_height}"
/>]
</BOUCLE_active_branches>
</g>

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

6
modeles/supportedversions_latest.html

@ -2,11 +2,11 @@
<div>
<h2 class="h4"><:supportedversions:latest_releases:></h2>
<ul class="spip">
<BOUCLE_latest(DATA){source table, #NULL|SupportedVersions::branchesToShow}>
<BOUCLE_latest(DATA){source table, #NULL|SupportedVersions::branchesToShow}>[
<li>
#LAST_VERSION_RELEASE : [<small>(#LAST_DATE_RELEASE|affdate)</small>]
(#LAST_VERSION_RELEASE) : [<small>(#LAST_DATE_RELEASE|affdate)</small>]
</li>
</BOUCLE_latest>
]</BOUCLE_latest>
</ul>
</div>
</B_latest>

189
supportedversions_fonctions.php

@ -68,6 +68,21 @@ class SupportedVersions
self::$releases = json_decode(file_get_contents(find_in_path(self::$releasesFile)), true);
}
/**
* Filtre qui sélectionne les branches qu'on souhaite afficher.
*
* Par défaut, le filtre sélection les maintenues à la date courante,
* c'est-à-dire les branches stable ou security.
*
* le paramètre sert à inclure les branches non-maintenues dans la limite
* des bornes sur calendrier
*
* les branches futures sont sélectionnées à condition qu'un date prévisionnelle de sortie existe
* et qu'elle soit dans les limite des bornes du calendrier
*
* @param boolean $includeEol embed eol branches if true.
* @return array
*/
public static function branchesToShow($eol = false) {
// @codeCoverageIgnoreStart
if (!self::$config) {
@ -79,11 +94,20 @@ class SupportedVersions
return array_reduce(
self::$releases,
function ($branches, $release) use ($eol, $now) {
if ($release['initial_release'] != '') {
if ($eol && $release['eol'] != '' && new DateTime($release['eol']) > self::$minDate) {
$branches[] = $release;
} elseif ($release['eol'] == '' || $release['eol'] > $now) {
$branches[] = $release;
if ($release['initial_release'] !== '') {
$start = new DateTime($release['initial_release']);
$state = self::state($release);
$statesToShow = ['future', 'stable', 'security'];
if ($eol) {
array_push($statesToShow, 'eol');
}
if (in_array($state, $statesToShow)) {
$end = ($release['eol'] !== '') ? new DateTime($release['eol']) : '';
$limit = (new DateTime(self::$minDate->format('Y-m-d')))->sub(new DateInterval('P1D'));
$end = max(($end ? $end : self::$maxDate), $limit);
if (self::inCalendar($start, $end)) {
$branches[] = $release;
}
}
}
@ -116,14 +140,8 @@ class SupportedVersions
//Calendar Part
protected static function dateHorizCoord(DateTime $date) {
$diff = $date->diff(self::$minDate);
if (!$diff->invert) {
return self::$config['svg']['margin_left'];
}
return self::$config['svg']['margin_left'] +
($diff->days / (365.24 / self::$config['svg']['year_width']));
protected static function inCalendar(DateTime $start, DateTime $end) {
return $start < self::$maxDate && $end >= self::$minDate;
}
public static function years() {
@ -143,15 +161,43 @@ class SupportedVersions
}
// @codeCoverageIgnoreEnd
if ($date) {
return self::dateHorizCoord(date_create_from_format('Y-m-d', $date));
}
$horizCoord = $date ?
new DateTime($date) :
self::$maxDate;
return self::dateHorizCoord(self::$maxDate);
return self::dateHorizCoord($horizCoord);
}
//SVG Part
/**
* Renvoie la coordonnée x d'une date dans le calendrier svg.
*
* - coordonnée 'x' de début du calendrier si la date est antérieure à la date de début du calendrier
* - coordonnée 'x' de fin du calendrier si la date est postérieure à la date de fin du calendrier
*
* @uses width
*
* @param DateTime $date
* @return int
*/
protected static function dateHorizCoord(DateTime $date) {
$diff = $date->diff(self::$minDate);
if (!$diff->invert) {
return self::$config['svg']['margin_left'];
}
$diff2 = self::$maxDate->diff($date);
if (!$diff2->invert) {
return self::$config['svg']['margin_left'] +
self::width(self::$config['svg']['margin_left']) +
self::$config['svg']['year_width'];
}
return self::$config['svg']['margin_left'] +
intval($diff->days / (365.24 / self::$config['svg']['year_width']));
}
/**
* Filtre qui détermine l'état d'une version par rapport à la date du jour.
*
@ -190,7 +236,7 @@ class SupportedVersions
$bug = $valeurs['active_support'] ? new DateTime($valeurs['active_support']) : null;
$security = $valeurs['eol'] ? new DateTime($valeurs['eol']) : null;
if ($initial && $initial < self::$now) {
if ($initial && $initial <= self::$now) {
$state = 'stable';
}
if ($bug && $bug < self::$now) {
@ -269,33 +315,120 @@ class SupportedVersions
(count(self::branchesToShow(true)) * self::$config['svg']['branch_height']);
}
public static function stableOrGradient($date) {
/**
* Filtre calculant la largeur du rectangle, d'un état d'une branche.
*
* @param array $values
* @param string $state
* @return int
*/
public static function rectWidth($branch, $state) {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$gradient = '';
// Etat inconnu
if (!in_array($state, ['security', 'stable', 'future'])) {
return '';
}
$filteredBranches = array_filter(self::$releases, function ($release) use ($branch) {
return $branch === $release['branch'];
});
$values = array_pop($filteredBranches);
// Branche inconnue
if (!isset($values)) {
return '';
}
if ($date == '' || new DateTime($date) > self::$maxDate) {
$gradient .= '-gradient';
$endDate = $values['eol'];
$startDate = $values['initial_release'];
if ($state == 'security') {
$startDate = $values['active_support'];
}
if ($state == 'stable') {
$endDate = $values['active_support'] ? $values['active_support'] : $endDate;
}
$startDate = new DateTime($startDate);
$endDate = new DateTime($endDate);
return 'stable'.$gradient;
if (strrpos(self::stateOrGradient($values['branch'], $state), '-gradient')) {
$endDate = self::$maxDate;
}
$rectWidth = intval(
self::dateHorizCoord($endDate) - self::dateHorizCoord($startDate)
);
return $rectWidth > 0 ? $rectWidth : '';
}
public static function securityOrGradient($date) {
/**
* Filtre calculant la class CSS d'un rectangle SVG de l'état d'une branche.
*
* Si la branche est inconnue, renvoie une chaine vide ('').
* Si l'état n'est pas affichable, renvoie une chaine vide ('').
* Si cycle de vie de la branche est en dehors des bornes du calendrier, renvoie une chaine vide ('').
* - i.e. : fin de vie avant la date de début, sortie effective ou prévue après la date de fin
* Si l'état de la branche se termine dans les bornes du calendrier, renvoie l'état.
* - i.e : stable, security, future
* Si l'état de la branche n'a pas de fin prévue, renvoie l'état et la mention gradient.
* - i.e. : stable-gradient, security-gradient, future-gradient.
*
* @param string $branch
* @param string $state
* @return string
*/
public static function stateOrGradient($branch, $state) {
// @codeCoverageIgnoreStart
if (!self::$config) {
self::init();
}
// @codeCoverageIgnoreEnd
$gradient = '';
// Etat inconnu
if (!in_array($state, ['security', 'stable', 'future'])) {
return '';
}
$filteredBranches = array_filter(self::$releases, function ($release) use ($branch) {
return $branch === $release['branch'];
});
$values = array_pop($filteredBranches);
// Branche inconnue
if (!isset($values)) {
return '';
}
$endDate = $values['eol'];
$startDate = $values['initial_release'];
if ($state == 'security') {
$startDate = $values['active_support'];
}
if ($state == 'stable') {
$endDate = $values['active_support'] ? $values['active_support'] : $endDate;
}
if ($date == '' || new DateTime($date) > self::$maxDate) {
$gradient .= '-gradient';
// Date de début de l'état non prévue
if ($startDate === '') {
return '';
}
if (!self::inCalendar(new DateTime($startDate), new DateTime($endDate))) {
return '';
}
$originalState = self::state($values);
if ($state !== 'future' && $originalState == 'future') {
return '';
}
if ($state === 'future' && $originalState !== 'future') {
return '';
}
return 'security'.$gradient;
if ($endDate === '' || new DateTime($endDate) > self::$maxDate) {
$state .= '-gradient';
}
return $state;
}
}

2
tests/FunctionsTest.php

@ -5,6 +5,7 @@ namespace JamesRezo\SupportedVersions\Test;
class FunctionsTest extends TestCase
{
/**
* @group pipelines
* @covers ::supportedversions_insert_head_css
*
* @return void
@ -20,6 +21,7 @@ class FunctionsTest extends TestCase
}
/**
* @group balises
* @covers ::balise_SUPPORTED_VERSIONS_dist
*
* @return void

2
tests/SupportedVersions.php

@ -11,7 +11,7 @@ class SupportedVersions extends \SupportedVersions
return [
'config' => self::$config,
'now' => self::$now,
'releasesFile' => self::$releasesFile,
'releasesFile' => self::$releasesFile
];
}

277
tests/SupportedVersionsTest.php

@ -62,6 +62,7 @@ class SupportedVersionsTest extends TestCase
}
/**
* @group filtres
* @dataProvider dataSupportedVersionsState
*
* @param string $expected
@ -115,6 +116,7 @@ class SupportedVersionsTest extends TestCase
}
/**
* @group internal
* @dataProvider dataSupportedVersionsInit
*
* @param string $expected
@ -137,39 +139,18 @@ class SupportedVersionsTest extends TestCase
{
return [
'stables-seulement' => [
[
[
'branch' => '3.0',
'initial_release' => '1971-08-01',
'eol' => '',
],
],
['0.9', '1.1', '2.0', '2.1', '4.0', '4.1'],
false,
],
'toutes-versions-dans-l-intervalle-de-temps-' => [
[
[
'branch' => '1.0',
'initial_release' => '1971-02-03',
'eol' => '1971-06-06',
],
[
'branch' => '2.0',
'initial_release' => '1971-04-01',
'eol' => '1971-09-01',
],
[
'branch' => '3.0',
'initial_release' => '1971-08-01',
'eol' => '',
],
],
'toutes-versions-dans-l-intervalle-de-temps' => [
['0.8', '0.9', '1.0', '1.1', '2.0', '2.1', '4.0', '4.1'],
true,
],
];
}
/**
* @group criteres
* @dataProvider dataSupportedVersionsBranchesToShow
*
* @param array $expected
@ -188,117 +169,160 @@ class SupportedVersionsTest extends TestCase
$branches = SupportedVersions::branchesToShow($eol);
//Then
$this->assertEquals($expected, $branches);
$this->assertEquals($expected, array_reduce(
$branches,
function ($branchNames, $branch) {
$branchNames[] = $branch['branch'];
return $branchNames;
},
[]
));
}
public function dataSupportedVersionsEoledBranches()
{
return [
'nominal' => [
[
[
'branch' => '0.1',
'initial_release' => '1969-02-03',
'eol' => '1969-06-06'
],
[
'branch' => '1.0',
'initial_release' => '1971-02-03',
'eol' => '1971-06-06',
],
[
'branch' => '2.0',
'initial_release' => '1971-04-01',
'eol' => '1971-09-01',
],
],
[
'calendar' => [
'min_year' => 'P1Y',
'max_year' => 'P2Y',
],
],
'date-courante' => [
['0.1', '0.8', '1.0'],
'',
],
'plus-tard' => [
['0.1', '0.8', '1.0', '1.1', '4.1'],
'1972-03-01',
],
];
}
/**
* @group criteres
* @dataProvider dataSupportedVersionsEoledBranches
*
* @param array $expected
* @param array $config
* @param array $expected
* @param string $now
* @return void
*/
public function testSupportedVersionsEoledBranches($expected, $config)
public function testSupportedVersionsEoledBranches($expected, $now)
{
//Given
SupportedVersions::setConfig($config, $this->now);
SupportedVersions::setConfig($this->calendarConfig, $now ? $now : $this->now);
//When
$branches = SupportedVersions::eoledBranches();
//Then
$this->assertEquals($expected, $branches);
$this->assertEquals($expected, array_reduce(
$branches,
function ($branchNames, $branch) {
$branchNames[] = $branch['branch'];
return $branchNames;
},
[]
));
}
public function dataSupportedVersionsSecurityOrGradient()
public function dataSupportedVersionsStateOrGradient()
{
return [
'date-is-empty' => [
'security-gradient',
'1.0-unknown-state' => [
'',
'1.0',
'unknonwn',
],
'0.0-unknown-branch' => [
'',
'0.0',
'stable',
],
'0.1-stable-before-svg' => [
'',
'0.1',
'stable',
],
'0.1-eol-before-svg' => [
'',
'0.1',
'security',
],
'1.0-eol-in-svg' => [
'security',
'1.0',
'security',
],
'1.0-stable-in-svg' => [
'stable',
'1.0',
'stable',
],
'1.0-no-future' => [
'',
'1.0',
'future',
],
'3.0-future-after-svg' => [
'',
'3.0',
'future',
],
'no-gradient' => [
'3.0-security-after-svg' => [
'',
'3.0',
'security',
'1971-01-01'
],
'out-of-scope-with-gradient' => [
'3.0-stable-after-svg' => [
'',
'3.0',
'stable',
],
'1.1-security-gradient' => [
'security-gradient',
'1974-01-01'
'1.1',
'security',
],
'2.1-stable-gradient' => [
'stable-gradient',
'2.1',
'stable',
],
'4.1-future' => [
'future',
'4.1',
'future',
],
'4.1-future-is-not-stable' => [
'',
'4.1',
'stable',
],
'4.0-future-gradient' => [
'future-gradient',
'4.0',
'future',
],
];
}
/**
* @dataProvider dataSupportedVersionsSecurityOrGradient
*
* @param string $expected
* @param string $date
* @return void
*/
public function testSupportedVersionsSecurityOrGradient($expected, $date)
{
//Given
SupportedVersions::setConfig(
$this->calendarConfig,
$this->now,
);
//When
$cssClass = SupportedVersions::securityOrGradient($date);
//Then
$this->assertEquals($expected, $cssClass);
}
/**
* @dataProvider dataSupportedVersionsSecurityOrGradient
* @group filtres
* @group svg
* @dataProvider dataSupportedVersionsStateOrGradient
*
* @param string $expected
* @param string $date
* @param string $branch
* @param string $state
* @return void
*/
public function testSupportedVersionsStableOrGradient($expected, $date)
public function testSupportedVersionsStateOrGradient($expected, $branch, $state)
{
//Given
SupportedVersions::setConfig(
$this->calendarConfig,
$this->now,
);
$expected = str_replace('security', 'stable', $expected);
//When
$cssClass = SupportedVersions::stableOrGradient($date);
$cssClass = SupportedVersions::stateOrGradient($branch, $state);
//Then
$this->assertEquals($expected, $cssClass);
@ -308,21 +332,27 @@ class SupportedVersionsTest extends TestCase
{
return [
'date-is-empty' => [
868.1962545175775,
812,
'',
],
'date-in-svg' => [
589.2344759610119,
589,
'1971-11-30',
],
'date-out-svg' => [
'date-before-svg' => [
100,
'1969-01-01',
],
'date-after-svg' => [
812,
'1974-01-01',
],
];
}
/**
* @group filtres
* @group svg
* @dataProvider dataSupportedVersionsHorizCoord
*
* @param float $expected
@ -356,13 +386,14 @@ class SupportedVersionsTest extends TestCase
'0.2',
],
'branch-exists' => [
112,
304,
'2.0',
],
];
}
/**
* @group svg
* @dataProvider dataSupportedVersionsTop
*
* @param int $expected
@ -383,4 +414,64 @@ class SupportedVersionsTest extends TestCase
//Then
$this->assertEquals($expected, $actual);
}
public function dataSupportedVersionsRectWidth()
{
return [
'state-unknown' => [
'',
'0.9',
'unknown'
],
'branch-unknown' => [
'',
'0.0',
'stable',
],
'avant-le-cadre-après-le-cadre' => [
712,
'0.9',
'stable'
],
'avant-le-cadre-dans-le-cadre' => [
278,
'0.8',
'stable',
],
'dans-le-cadre-après-le-cadre' => [
261,
'1.1',
'security',
],
'dans-le-cadre-dans-le-cadre' => [
87,
'1.0',
'stable',
],
];
}
/**
* @group svg
* @dataProvider dataSupportedVersionsRectWidth
*
* @param float $expected
* @param string $start
* @param string $end
* @return void
*/
public function testSupportedVersionsRectWidth($expected, $branch, $state)
{
//Given
SupportedVersions::setConfig(
array_merge($this->svgConfig, $this->calendarConfig),
$this->now
);
//When
$actual = SupportedVersions::rectWidth($branch, $state);
//Then
$this->assertEquals($expected, $actual);
}
}

2
tests/TestCase.php

@ -9,7 +9,7 @@ class TestCase extends BaseTestCase
{
protected $now = '1971-11-05 18:40:12.345678Z';
protected $calendarConfig = ['calendar' => ['min_year' => 'P1Y', 'max_year' => 'P2Y']];
protected $calendarConfig = ['calendar' => ['min_year' => 'P1Y', 'max_year' => 'P1Y']];
protected $svgConfig = [
'svg' => [

51
tests/releases/init.json

@ -2,26 +2,67 @@
{
"branch": "0.1",
"initial_release": "1969-02-03",
"active_support": "",
"eol": "1969-06-06"
},
{
"branch": "0.8",
"initial_release": "1969-09-03",
"active_support": "1971-02-03",
"eol": "1971-02-03"
},
{
"branch": "0.9",
"initial_release": "1969-11-05",
"active_support": "",
"eol": ""
},
{
"branch": "1.0",
"initial_release": "1971-02-03",
"eol": "1971-06-06"
"active_support": "1971-06-06",
"eol": "1971-10-07"
},
{
"branch": "1.1",
"initial_release": "1971-06-06",
"active_support": "1971-10-07",
"eol": "1972-02-03"
},
{
"branch": "2.0",
"initial_release": "1971-04-01",
"eol": "1971-09-01"
"initial_release": "1971-07-01",
"active_support": "1972-03-09",
"eol": "1972-11-05"
},
{
"branch": "3.0",
"initial_release": "1971-08-01",
"branch": "2.1",
"initial_release": "1971-10-07",
"active_support": "1972-06-06",
"eol": ""
},
{
"branch": "3.0",
"initial_release": "1972-03-01",
"active_support": "1972-11-05",
"eol": "1973-07-01"
},
{
"branch": "4.0",
"initial_release": "1971-11-06",
"active_support": "",
"eol": ""
},
{
"branch": "4.1",
"initial_release": "1971-12-01",
"active_support": "1971-12-01",
"eol": "1971-12-01"
},
{
"branch": "5.0",
"initial_release": "",
"active_support": "",
"eol": ""
}
]

Loading…
Cancel
Save