From ffd58d06fa827827c696cb46e5c0e2fca3c240bc Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 3 Sep 2016 18:02:00 -0400 Subject: Support version operators for plugin directory: >= and > --- ChangeLog | 1 + app/Core/Plugin/Directory.php | 7 +++++++ tests/units/Core/Plugin/DirectoryTest.php | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/ChangeLog b/ChangeLog index ba2aa6ad..b18606f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,7 @@ Improvements: * Add "reference" hooks * Show project name in task forms * Convert vanilla CSS to SASS +* Support version operators for plugin directory: >= and > Other changes: diff --git a/app/Core/Plugin/Directory.php b/app/Core/Plugin/Directory.php index 21f11ca9..27c3514e 100644 --- a/app/Core/Plugin/Directory.php +++ b/app/Core/Plugin/Directory.php @@ -40,6 +40,13 @@ class Directory extends BaseCore return true; } + foreach (array('>=', '>') as $operator) { + if (strpos($plugin['compatible_version'], $operator) === 0) { + $pluginVersion = substr($plugin['compatible_version'], strlen($operator)); + return version_compare($appVersion, $pluginVersion, $operator); + } + } + return $plugin['compatible_version'] === $appVersion; } diff --git a/tests/units/Core/Plugin/DirectoryTest.php b/tests/units/Core/Plugin/DirectoryTest.php index 13aef4b9..302bd6f6 100644 --- a/tests/units/Core/Plugin/DirectoryTest.php +++ b/tests/units/Core/Plugin/DirectoryTest.php @@ -12,6 +12,11 @@ class DirectoryTest extends Base $this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '1.0.29'), '1.0.28')); $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), '1.0.28')); $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), 'master.1234')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), 'master')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), '1.0.32')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), '1.0.33')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>1.0.32'), '1.0.33')); + $this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '>1.0.32'), '1.0.32')); } public function testGetAvailablePlugins() -- cgit v1.2.3