From 770f9876595a3cebd4b911a237ec1e681bc506be Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 5 Dec 2014 13:52:51 +0100 Subject: adding supported libraries - including min and max version --- tests/data/app/expected-info.json | 15 +++++++++++++++ tests/data/app/valid-info.xml | 3 +++ 2 files changed, 18 insertions(+) (limited to 'tests/data') diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index fc0ab224977..a425622998b 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -44,6 +44,21 @@ }, "@value": "notepad.exe" } + ], + "lib": [ + { + "@attributes" : { + "min-version": "1.2" + }, + "@value": "xml" + }, + { + "@attributes" : { + "max-version": "2.0" + }, + "@value": "intl" + }, + "curl" ] } } diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index f01f5fd55ea..0ea15b63a4b 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -25,5 +25,8 @@ mysql grep notepad.exe + xml + intl + curl -- cgit v1.2.3 From ee46548f57310b45ce723fd03ec29bfb686f8bc2 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 5 Dec 2014 14:51:41 +0100 Subject: adding dependencies for supported platforms --- lib/private/app/dependencyanalyzer.php | 21 +++++++++++++++++++++ tests/data/app/expected-info.json | 3 ++- tests/data/app/valid-info.xml | 1 + tests/lib/app/dependencyanalyzer.php | 28 ++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) (limited to 'tests/data') diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index af36637b675..2e838872385 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -48,6 +48,7 @@ class DependencyAnalyzer { $this->analyzeDatabases(); $this->analyzeCommands(); $this->analyzeLibraries(); + $this->analyzeOS(); return $this->missing; } @@ -135,6 +136,26 @@ class DependencyAnalyzer { } } + private function analyzeOS() { + if (!isset($this->dependencies['os'])) { + return; + } + + $oss = $this->dependencies['os']; + if (empty($oss)) { + return; + } + $oss = array_map(function($os) { + return $this->getValue($os); + }, $oss); + $currentOS = $this->platform->getOS(); + if (!in_array($currentOS, $oss)) { + $this->addMissing((string)$this->l->t('Following platforms are supported: %s', join(', ', $oss))); + } + } + + + /** * @param $element * @return mixed diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index a425622998b..b899df7a8d6 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -59,6 +59,7 @@ "@value": "intl" }, "curl" - ] + ], + "os": "Linux" } } diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index 0ea15b63a4b..42f4e3edb7f 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -28,5 +28,6 @@ xml intl curl + Linux diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 872d5cfb2c5..1cd24193ea6 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -141,6 +141,34 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $this->assertEquals($expectedMissing, $missing); } + /** + * @dataProvider providesOS + * @param $expectedMissing + * @param $oss + */ + function testOS($expectedMissing, $oss) { + $app = array( + 'dependencies' => array() + ); + if (!is_null($oss)) { + $app['dependencies']['os'] = $oss; + } + + $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); + $missing = $analyser->analyze(); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + function providesOS() { + return array( + array(array(), null), + array(array(), array()), + array(array('Following platforms are supported: WINNT'), array('WINNT')) + ); + } + function providesLibs() { return array( // we expect curl to exist -- cgit v1.2.3 From 5a03e0a5cf30f4ad5cecd7a90ad3bc2a004770aa Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Fri, 5 Dec 2014 15:28:33 +0100 Subject: adding dependency to owncloud version - with fallback to requiremin and requiremax --- lib/private/app/dependencyanalyzer.php | 27 +++++++++++++++++++++++++++ lib/private/app/platform.php | 8 ++++++++ tests/data/app/expected-info.json | 8 +++++++- tests/data/app/valid-info.xml | 1 + tests/lib/app/dependencyanalyzer.php | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) (limited to 'tests/data') diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index 2e838872385..795017e2b37 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -26,6 +26,8 @@ class DependencyAnalyzer { /** @var array */ private $dependencies = array(); + private $appInfo = array(); + /** * @param array $app * @param Platform $platform @@ -49,6 +51,7 @@ class DependencyAnalyzer { $this->analyzeCommands(); $this->analyzeLibraries(); $this->analyzeOS(); + $this->analyzeOC(); return $this->missing; } @@ -154,7 +157,31 @@ class DependencyAnalyzer { } } + private function analyzeOC() { + $minVersion = null; + if (isset($this->dependencies['owncloud']['@attributes']['min-version'])) { + $minVersion = $this->dependencies['owncloud']['@attributes']['min-version']; + } elseif (isset($this->appInfo['requiremin'])) { + $minVersion = $this->appInfo['requiremin']; + } + $maxVersion = null; + if (isset($this->dependencies['oc']['@attributes']['max-version'])) { + $maxVersion = $this->dependencies['oc']['@attributes']['max-version']; + } elseif (isset($this->appInfo['requiremax'])) { + $maxVersion = $this->appInfo['requiremax']; + } + if (!is_null($minVersion)) { + if (version_compare($this->platform->getOcVersion(), $minVersion, '<')) { + $this->addMissing((string)$this->l->t('ownCloud %s or higher is required.', $minVersion)); + } + } + if (!is_null($maxVersion)) { + if (version_compare($this->platform->getOcVersion(), $maxVersion, '>')) { + $this->addMissing((string)$this->l->t('ownCloud with a version lower than %s is required.', $maxVersion)); + } + } + } /** * @param $element diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php index 6279bb5f20c..ba96fba00db 100644 --- a/lib/private/app/platform.php +++ b/lib/private/app/platform.php @@ -10,6 +10,7 @@ namespace OC\App; +use OC_Util; use OCP\IConfig; /** @@ -35,6 +36,13 @@ class Platform { return phpversion(); } + /** + * @return string + */ + public function getOcVersion() { + return OC_Util::getVersion(); + } + /** * @return string */ diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index b899df7a8d6..ab4f103939a 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -60,6 +60,12 @@ }, "curl" ], - "os": "Linux" + "os": "Linux", + "owncloud": { + "@attributes" : { + "min-version": "7.01", + "max-version": "8" + } + } } } diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index 42f4e3edb7f..4b22d55d7bc 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -29,5 +29,6 @@ intl curl Linux + diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 1cd24193ea6..9c5db96e045 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -51,6 +51,9 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { } return null; })); + $this->platformMock->expects($this->any()) + ->method('getOcVersion') + ->will( $this->returnValue('8.0.1')); $this->l10nMock = $this->getMockBuilder('\OCP\IL10N') ->disableOriginalConstructor() @@ -161,6 +164,35 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $this->assertEquals($expectedMissing, $missing); } + /** + * @dataProvider providesOC + * @param $expectedMissing + * @param $oc + */ + function testOC($expectedMissing, $oc) { + $app = array( + 'dependencies' => array() + ); + if (!is_null($oc)) { + $app['dependencies']['oc'] = $oc; + } + + $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); + $missing = $analyser->analyze(); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + function providesOC() { + return array( + // no version -> no missing dependency + array(array(), null), + array(array('ownCloud 9 or higher is required.'), array('@attributes' => array('min-version' => '9'))), + array(array('ownCloud with a version lower than 5.1.2 is required.'), array('@attributes' => array('max-version' => '5.1.2'))), + ); + } + function providesOS() { return array( array(array(), null), -- cgit v1.2.3 From f1d17141133efa267ed5b30f01a4117162b76ce6 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Thu, 11 Dec 2014 16:22:30 +0100 Subject: fix unit tests --- tests/data/app/expected-info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/data') diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index ab4f103939a..d86ffed482b 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -63,7 +63,7 @@ "os": "Linux", "owncloud": { "@attributes" : { - "min-version": "7.01", + "min-version": "7.0.1", "max-version": "8" } } -- cgit v1.2.3