diff options
author | Bernhard Posselt <Raydiation@users.noreply.github.com> | 2014-12-15 12:34:46 +0100 |
---|---|---|
committer | Bernhard Posselt <Raydiation@users.noreply.github.com> | 2014-12-15 12:34:46 +0100 |
commit | be45366013c50d9a9d18e258c66e18798719d8df (patch) | |
tree | f9e897521e0e93e1f96755ae60752a9ea7c0bcda /tests | |
parent | b831914aa66ab9591dd4593233cc8f67ed6cf8eb (diff) | |
parent | e58b9d3eb70996a6ccccabf979125fc0797fbd85 (diff) | |
download | nextcloud-server-be45366013c50d9a9d18e258c66e18798719d8df.tar.gz nextcloud-server-be45366013c50d9a9d18e258c66e18798719d8df.zip |
Merge pull request #12625 from owncloud/app-dependencies-libs-and-commands
adding dependencies for command line tools and php libraries
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/app/expected-info.json | 24 | ||||
-rw-r--r-- | tests/data/app/valid-info.xml | 5 | ||||
-rw-r--r-- | tests/lib/app/dependencyanalyzer.php | 166 | ||||
-rw-r--r-- | tests/lib/app/platformrepository.php | 65 |
4 files changed, 246 insertions, 14 deletions
diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index fc0ab224977..d86ffed482b 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -44,6 +44,28 @@ }, "@value": "notepad.exe" } - ] + ], + "lib": [ + { + "@attributes" : { + "min-version": "1.2" + }, + "@value": "xml" + }, + { + "@attributes" : { + "max-version": "2.0" + }, + "@value": "intl" + }, + "curl" + ], + "os": "Linux", + "owncloud": { + "@attributes" : { + "min-version": "7.0.1", + "max-version": "8" + } + } } } diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index f01f5fd55ea..4b22d55d7bc 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -25,5 +25,10 @@ <database>mysql</database> <command os="linux">grep</command> <command os="windows">notepad.exe</command> + <lib min-version="1.2">xml</lib> + <lib max-version="2.0">intl</lib> + <lib>curl</lib> + <os>Linux</os> + <owncloud min-version="7.0.1" max-version="8" /> </dependencies> </info> diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 7d06842e8ad..a79995b78b3 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -15,16 +15,15 @@ use OCP\IL10N; class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { - /** - * @var Platform - */ + /** @var Platform */ private $platformMock; - /** - * @var IL10N - */ + /** @var IL10N */ private $l10nMock; + /** @var \OC\App\DependencyAnalyzer */ + private $analyser; + public function setUp() { $this->platformMock = $this->getMockBuilder('\OC\App\Platform') ->disableOriginalConstructor() @@ -35,6 +34,26 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $this->platformMock->expects($this->any()) ->method('getDatabase') ->will( $this->returnValue('mysql')); + $this->platformMock->expects($this->any()) + ->method('getOS') + ->will( $this->returnValue('Linux')); + $this->platformMock->expects($this->any()) + ->method('isCommandKnown') + ->will( $this->returnCallback(function($command) { + return ($command === 'grep'); + })); + $this->platformMock->expects($this->any()) + ->method('getLibraryVersion') + ->will( $this->returnCallback(function($lib) { + if ($lib === 'curl') { + return "2.3.4"; + } + return null; + })); + $this->platformMock->expects($this->any()) + ->method('getOcVersion') + ->will( $this->returnValue('8.0.1')); + $this->l10nMock = $this->getMockBuilder('\OCP\IL10N') ->disableOriginalConstructor() ->getMock(); @@ -43,6 +62,8 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { ->will($this->returnCallback(function($text, $parameters = array()) { return vsprintf($text, $parameters); })); + + $this->analyser = new \OC\App\DependencyAnalyzer($this->platformMock, $this->l10nMock); } /** @@ -60,11 +81,9 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { if (!is_null($maxVersion)) { $app['dependencies']['php']['@attributes']['max-version'] = $maxVersion; } - $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); - $missing = $analyser->analyze(); + $missing = $this->analyser->analyze($app); $this->assertTrue(is_array($missing)); - $this->assertEquals(count($expectedMissing), count($missing)); $this->assertEquals($expectedMissing, $missing); } @@ -79,19 +98,140 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { if (!is_null($databases)) { $app['dependencies']['database'] = $databases; } - $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); - $missing = $analyser->analyze(); + $missing = $this->analyser->analyze($app); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + /** + * @dataProvider providesCommands + */ + public function testCommand($expectedMissing, $commands) { + $app = array( + 'dependencies' => array( + ) + ); + if (!is_null($commands)) { + $app['dependencies']['command'] = $commands; + } + $missing = $this->analyser->analyze($app); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + /** + * @dataProvider providesLibs + * @param $expectedMissing + * @param $libs + */ + function testLibs($expectedMissing, $libs) { + $app = array( + 'dependencies' => array( + ) + ); + if (!is_null($libs)) { + $app['dependencies']['lib'] = $libs; + } + + $missing = $this->analyser->analyze($app); + + $this->assertTrue(is_array($missing)); + $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; + } + + $missing = $this->analyser->analyze($app); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + /** + * @dataProvider providesOC + * @param $expectedMissing + * @param $oc + */ + function testOC($expectedMissing, $oc) { + $app = array( + 'dependencies' => array() + ); + if (!is_null($oc)) { + $app['dependencies']['owncloud'] = $oc; + } + + $missing = $this->analyser->analyze($app); $this->assertTrue(is_array($missing)); - $this->assertEquals(count($expectedMissing), count($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), + array(array(), array()), + array(array('Following platforms are supported: ANDROID'), 'ANDROID'), + array(array('Following platforms are supported: WINNT'), array('WINNT')) + ); + } + + function providesLibs() { + return array( + // we expect curl to exist + array(array(), 'curl'), + // we expect abcde to exist + array(array('The library abcde is not available.'), array('abcde')), + // curl in version 100.0 does not exist + array(array('Library curl with a version higher than 100.0 is required - available version 2.3.4.'), + array(array('@attributes' => array('min-version' => '100.0'), '@value' => 'curl'))), + // curl in version 100.0 does not exist + array(array('Library curl with a version lower than 1.0.0 is required - available version 2.3.4.'), + array(array('@attributes' => array('max-version' => '1.0.0'), '@value' => 'curl'))) + ); + } + + function providesCommands() { + return array( + array(array(), null), + // grep is known on linux + array(array(), array(array('@attributes' => array('os' => 'Linux'), '@value' => 'grep'))), + // grepp is not known on linux + array(array('The command line tool grepp could not be found'), array(array('@attributes' => array('os' => 'Linux'), '@value' => 'grepp'))), + // we don't care about tools on Windows - we are on Linux + array(array(), array(array('@attributes' => array('os' => 'Windows'), '@value' => 'grepp'))), + // grep is known on all systems + array(array(), 'grep'), + ); + } + function providesDatabases() { return array( // non BC - in case on databases are defined -> all are supported array(array(), null), array(array(), array()), + array(array('Following databases are supported: mongodb'), 'mongodb'), array(array('Following databases are supported: sqlite, postgres'), array('sqlite', array('@value' => 'postgres'))), ); } @@ -103,7 +243,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { array(array(), null, '5.5'), array(array(), '5.4', '5.5'), array(array('PHP 5.4.4 or higher is required.'), '5.4.4', null), - array(array('PHP with a version less then 5.4.2 is required.'), null, '5.4.2'), + array(array('PHP with a version lower than 5.4.2 is required.'), null, '5.4.2'), ); } } diff --git a/tests/lib/app/platformrepository.php b/tests/lib/app/platformrepository.php new file mode 100644 index 00000000000..3d8849ce8ab --- /dev/null +++ b/tests/lib/app/platformrepository.php @@ -0,0 +1,65 @@ +<?php + +/** + * @author Thomas Müller + * @copyright 2014 Thomas Müller deepdiver@owncloud.com + * later. + * See the COPYING-README file. + */ + +namespace Test\App; + +use OC; + +class PlatformRepository extends \Test\TestCase { + + /** + * @dataProvider providesVersions + * @param $expected + * @param $input + */ + public function testVersion($input, $expected) { + $pr = new OC\App\PlatformRepository(); + $normalizedVersion = $pr->normalizeVersion($input); + $this->assertEquals($expected, $normalizedVersion); + } + + public function providesVersions() { + return array( + 'none' => array('1.0.0', '1.0.0.0'), + 'none/2' => array('1.2.3.4', '1.2.3.4'), + 'parses state' => array('1.0.0RC1dev', '1.0.0.0-RC1-dev'), + 'CI parsing' => array('1.0.0-rC15-dev', '1.0.0.0-RC15-dev'), + 'delimiters' => array('1.0.0.RC.15-dev', '1.0.0.0-RC15-dev'), + 'RC uppercase' => array('1.0.0-rc1', '1.0.0.0-RC1'), + 'patch replace' => array('1.0.0.pl3-dev', '1.0.0.0-patch3-dev'), + 'forces w.x.y.z' => array('1.0-dev', '1.0.0.0-dev'), + 'forces w.x.y.z/2' => array('0', '0.0.0.0'), + 'parses long' => array('10.4.13-beta', '10.4.13.0-beta'), + 'parses long/2' => array('10.4.13beta2', '10.4.13.0-beta2'), + 'parses long/semver' => array('10.4.13beta.2', '10.4.13.0-beta2'), + 'expand shorthand' => array('10.4.13-b', '10.4.13.0-beta'), + 'expand shorthand2' => array('10.4.13-b5', '10.4.13.0-beta5'), + 'strips leading v' => array('v1.0.0', '1.0.0.0'), + 'strips v/datetime' => array('v20100102', '20100102'), + 'parses dates y-m' => array('2010.01', '2010-01'), + 'parses dates w/ .' => array('2010.01.02', '2010-01-02'), + 'parses dates w/ -' => array('2010-01-02', '2010-01-02'), + 'parses numbers' => array('2010-01-02.5', '2010-01-02-5'), + 'parses dates y.m.Y' => array('2010.1.555', '2010.1.555.0'), + 'parses datetime' => array('20100102-203040', '20100102-203040'), + 'parses dt+number' => array('20100102203040-10', '20100102203040-10'), + 'parses dt+patch' => array('20100102-203040-p1', '20100102-203040-patch1'), + 'parses master' => array('dev-master', '9999999-dev'), + 'parses trunk' => array('dev-trunk', '9999999-dev'), +// 'parses branches' => array('1.x-dev', '1.9999999.9999999.9999999-dev'), + 'parses arbitrary' => array('dev-feature-foo', 'dev-feature-foo'), + 'parses arbitrary2' => array('DEV-FOOBAR', 'dev-FOOBAR'), + 'parses arbitrary3' => array('dev-feature/foo', 'dev-feature/foo'), + 'ignores aliases' => array('dev-master as 1.0.0', '9999999-dev'), +// 'semver metadata' => array('dev-master+foo.bar', '9999999-dev'), +// 'semver metadata/2' => array('1.0.0-beta.5+foo', '1.0.0.0-beta5'), +// 'semver metadata/3' => array('1.0.0+foo', '1.0.0.0'), +// 'metadata w/ alias' => array('1.0.0+foo as 2.0', '1.0.0.0'), + ); + }} |