From 1354cee18ebde998a83f9a019d4137071efa8c02 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 1 Dec 2014 17:34:28 +0100 Subject: translate labels properly --- lib/private/app.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/private/app.php b/lib/private/app.php index 8e36d43bfb1..86db8fd9f55 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -809,7 +809,7 @@ class OC_App { if(isset($info['shipped']) and ($info['shipped'] == 'true')) { $info['internal'] = true; - $info['internallabel'] = $l->t('Recommended'); + $info['internallabel'] = (string)$l->t('Recommended'); $info['internalclass'] = 'recommendedapp'; $info['removable'] = false; } else { @@ -920,7 +920,7 @@ class OC_App { $app1[$i]['score'] = $app['score']; $app1[$i]['removable'] = false; if ($app['label'] == 'recommended') { - $app1[$i]['internallabel'] = $l->t('Recommended'); + $app1[$i]['internallabel'] = (string)$l->t('Recommended'); $app1[$i]['internalclass'] = 'recommendedapp'; } -- cgit v1.2.3 From 40e03ba314fce481c58d92da7070d72c4226c95c Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 1 Dec 2014 17:35:01 +0100 Subject: adding default key value pair for 'types' --- lib/private/app/infoparser.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib') diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index b4bdbea5c04..b0327fa4fd1 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -60,6 +60,9 @@ class InfoParser { if (!array_key_exists('public', $array)) { $array['public'] = array(); } + if (!array_key_exists('types', $array)) { + $array['types'] = array(); + } if (array_key_exists('documentation', $array)) { foreach ($array['documentation'] as $key => $url) { -- cgit v1.2.3 From b469e9f6fb83758ad91b8e41d81319ab3a73f098 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 1 Dec 2014 21:47:22 +0100 Subject: introduce dependency analyzer to take care of app dependencies some more unit tests on xml info parser --- lib/private/app/dependencyanalyzer.php | 58 ++++++++++++++++++++ lib/private/app/infoparser.php | 6 ++- lib/private/app/platform.php | 17 ++++++ settings/controller/appsettingscontroller.php | 10 +++- tests/data/app/strange-types-info.json | 24 +++++++++ tests/data/app/strange-types-info.xml | 23 ++++++++ tests/lib/app/dependencyanalyzer.php | 77 +++++++++++++++++++++++++++ tests/lib/app/infoparser.php | 21 +++++--- 8 files changed, 227 insertions(+), 9 deletions(-) create mode 100644 lib/private/app/dependencyanalyzer.php create mode 100644 lib/private/app/platform.php create mode 100644 tests/data/app/strange-types-info.json create mode 100644 tests/data/app/strange-types-info.xml create mode 100644 tests/lib/app/dependencyanalyzer.php (limited to 'lib') diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php new file mode 100644 index 00000000000..c76181926e2 --- /dev/null +++ b/lib/private/app/dependencyanalyzer.php @@ -0,0 +1,58 @@ +system = $system; + $this->l = $l; + $this->missing = array(); + $this->dependencies = array(); + if (array_key_exists('dependencies', $app)) { + $this->dependencies = $app['dependencies']; + } + } + + /** + * @param array $app + * @returns array of missing dependencies + */ + public function analyze() { + $this->analysePhpVersion(); + return $this->missing; + } + + private function analysePhpVersion() { + if (!array_key_exists('php', $this->dependencies)) { + return; + } + + if (array_key_exists('min-version', $this->dependencies['php'])) { + $minVersion = $this->dependencies['php']['min-version']; + if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) { + $this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion); + } + } + if (array_key_exists('max-version', $this->dependencies['php'])) { + $maxVersion = $this->dependencies['php']['max-version']; + if (version_compare($this->system->getPhpVersion(), $maxVersion, '>')) { + $this->missing[] = (string)$this->l->t('PHP with a version less then %s is required.', $maxVersion); + } + } + } + +} diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index b0327fa4fd1..e220fb40df6 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -64,7 +64,7 @@ class InfoParser { $array['types'] = array(); } - if (array_key_exists('documentation', $array)) { + if (array_key_exists('documentation', $array) && is_array($array['documentation'])) { foreach ($array['documentation'] as $key => $url) { // If it is not an absolute URL we assume it is a key // i.e. admin-ldap will get converted to go.php?to=admin-ldap @@ -78,7 +78,9 @@ class InfoParser { if (array_key_exists('types', $array)) { foreach ($array['types'] as $type => $v) { unset($array['types'][$type]); - $array['types'][] = $type; + if (is_string($type)) { + $array['types'][] = $type; + } } } diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php new file mode 100644 index 00000000000..292159337a0 --- /dev/null +++ b/lib/private/app/platform.php @@ -0,0 +1,17 @@ +l10n); + $missing = $dependencyAnalyzer->analyze(); + + $app['canInstall'] = empty($missing); + $app['missingDependencies'] = $missing; return $app; }, $apps); return array('apps' => $apps, 'status' => 'success'); } - } diff --git a/tests/data/app/strange-types-info.json b/tests/data/app/strange-types-info.json new file mode 100644 index 00000000000..eedf8bd0518 --- /dev/null +++ b/tests/data/app/strange-types-info.json @@ -0,0 +1,24 @@ +{ + "info": [], + "remote": [], + "public": [], + "id": "files_encryption", + "name": "Server-side Encryption", + "description": "\n\tThis application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. \n\tNote that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation \n\t", + "licence": "AGPL", + "author": "Sam Tuke, Bjoern Schiessle, Florin Peter", + "requiremin": "4", + "shipped": "true", + "documentation": { + "user": "https://docs.example.com/server/go.php?to=user-encryption", + "admin": "https://docs.example.com/server/go.php?to=admin-encryption" + }, + "rememberlogin": "false", + "types": [], + "ocsid": "166047", + "dependencies": { + "php": { + "min-version": 5.4 + } + } +} diff --git a/tests/data/app/strange-types-info.xml b/tests/data/app/strange-types-info.xml new file mode 100644 index 00000000000..e7e8f0d0281 --- /dev/null +++ b/tests/data/app/strange-types-info.xml @@ -0,0 +1,23 @@ + + + files_encryption + Server-side Encryption + + This application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. + Note that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation + + AGPL + Sam Tuke, Bjoern Schiessle, Florin Peter + 4 + true + + user-encryption + admin-encryption + + false + + 166047 + + 5.4 + + diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php new file mode 100644 index 00000000000..d0c2919f47a --- /dev/null +++ b/tests/lib/app/dependencyanalyzer.php @@ -0,0 +1,77 @@ +platformMock = $this->getMockBuilder('\OC\App\Platform') + ->getMock(); + $this->platformMock->expects($this->any()) + ->method('getPhpVersion') + ->will( $this->returnValue('5.4.3')); + $this->l10nMock = $this->getMockBuilder('\OCP\IL10N') + ->disableOriginalConstructor() + ->getMock(); + $this->l10nMock->expects($this->any()) + ->method('t') + ->will($this->returnCallback(function($text, $parameters = array()) { + return vsprintf($text, $parameters); + })); + } + + /** + * @dataProvider providesPhpVersion + */ + public function testPhpVersion($expectedMissing, $minVersion, $maxVersion) { + $app = array( + 'dependencies' => array( + 'php' => array() + ) + ); + if (!is_null($minVersion)) { + $app['dependencies']['php']['min-version'] = $minVersion; + } + if (!is_null($maxVersion)) { + $app['dependencies']['php']['max-version'] = $maxVersion; + } + $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); + $missing = $analyser->analyze(); + + $this->assertTrue(is_array($missing)); + $this->assertEquals(count($expectedMissing), count($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + function providesPhpVersion() { + return array( + array(array(), null, null), + array(array(), '5.4', null), + 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'), + ); + } +} diff --git a/tests/lib/app/infoparser.php b/tests/lib/app/infoparser.php index 277e1582e45..20668c05086 100644 --- a/tests/lib/app/infoparser.php +++ b/tests/lib/app/infoparser.php @@ -39,15 +39,24 @@ class InfoParser extends \PHPUnit_Framework_TestCase { $this->parser = new \OC\App\InfoParser($httpHelper, $urlGenerator); } - public function testParsingValidXml() { - $expectedData = json_decode(file_get_contents(OC::$SERVERROOT.'/tests/data/app/expected-info.json'), true); - $data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/valid-info.xml'); + /** + * @dataProvider providesInfoXml + */ + public function testParsingValidXml($expectedJson, $xmlFile) { + $expectedData = null; + if (!is_null($expectedJson)) { + $expectedData = json_decode(file_get_contents(OC::$SERVERROOT . "/tests/data/app/$expectedJson"), true); + } + $data = $this->parser->parse(OC::$SERVERROOT. "/tests/data/app/$xmlFile"); $this->assertEquals($expectedData, $data); } - public function testParsingInvalidXml() { - $data = $this->parser->parse(OC::$SERVERROOT.'/tests/data/app/invalid-info.xml'); - $this->assertNull($data); + function providesInfoXml() { + return array( + array('expected-info.json', 'valid-info.xml'), + array('strange-types-info.json', 'strange-types-info.xml'), + array(null, 'invalid-info.xml'), + ); } } -- cgit v1.2.3 From ba52c996cf81781d752748986c761667f59691a3 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Mon, 1 Dec 2014 23:43:27 +0100 Subject: adding supported databases --- lib/private/app/dependencyanalyzer.php | 16 ++++++++++++++ lib/private/app/platform.php | 16 ++++++++++++++ settings/controller/appsettingscontroller.php | 2 +- tests/data/app/expected-info.json | 3 ++- tests/data/app/valid-info.xml | 6 ++++- tests/lib/app/dependencyanalyzer.php | 32 +++++++++++++++++++++++++++ 6 files changed, 72 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index c76181926e2..7fd181c076c 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -33,6 +33,7 @@ class DependencyAnalyzer { */ public function analyze() { $this->analysePhpVersion(); + $this->analyseSupportedDatabases(); return $this->missing; } @@ -55,4 +56,19 @@ class DependencyAnalyzer { } } + private function analyseSupportedDatabases() { + if (!array_key_exists('database', $this->dependencies)) { + return; + } + + $supportedDatabases = $this->dependencies['database']; + if (empty($supportedDatabases)) { + return; + } + $currentDatabase = $this->system->getDatabase(); + if (!in_array($currentDatabase, $supportedDatabases)) { + $this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases)); + } + } + } diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php index 292159337a0..39f8a2979f9 100644 --- a/lib/private/app/platform.php +++ b/lib/private/app/platform.php @@ -10,8 +10,24 @@ namespace OC\App; +use OCP\IConfig; + class Platform { + + function __construct(IConfig $config) { + $this->config = $config; + } + public function getPhpVersion() { return phpversion(); } + + public function getDatabase() { + $dbType = $this->config->getSystemValue('dbtype', 'sqlite'); + if ($dbType === 'sqlite3') { + $dbType = 'sqlite'; + } + + return $dbType; + } } diff --git a/settings/controller/appsettingscontroller.php b/settings/controller/appsettingscontroller.php index 1f7e3b259fe..3ad52bd2187 100644 --- a/settings/controller/appsettingscontroller.php +++ b/settings/controller/appsettingscontroller.php @@ -127,7 +127,7 @@ class AppSettingsController extends Controller { $app['canUnInstall'] = !$app['active'] && $app['removable']; // analyse dependencies - $dependencyAnalyzer = new DependencyAnalyzer($app, new Platform(), $this->l10n); + $dependencyAnalyzer = new DependencyAnalyzer($app, new Platform($this->config), $this->l10n); $missing = $dependencyAnalyzer->analyze(); $app['canInstall'] = empty($missing); diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index 50e81a48fd2..9be6062220f 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -19,6 +19,7 @@ "dependencies": { "php": { "min-version": 5.4 - } + }, + "database":["sqlite", "mysql"] } } diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index 81abb276902..3a40e62d147 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -20,6 +20,10 @@ 166047 - 5.4 + + 5.4 + + sqlite + mysql diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index d0c2919f47a..25f2ad8caa8 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -27,10 +27,14 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { public function setUp() { $this->platformMock = $this->getMockBuilder('\OC\App\Platform') + ->disableOriginalConstructor() ->getMock(); $this->platformMock->expects($this->any()) ->method('getPhpVersion') ->will( $this->returnValue('5.4.3')); + $this->platformMock->expects($this->any()) + ->method('getDatabase') + ->will( $this->returnValue('mysql')); $this->l10nMock = $this->getMockBuilder('\OCP\IL10N') ->disableOriginalConstructor() ->getMock(); @@ -64,6 +68,34 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $this->assertEquals($expectedMissing, $missing); } + /** + * @dataProvider providesDatabases + */ + public function testDatabases($expectedMissing, $databases) { + $app = array( + 'dependencies' => array( + ) + ); + if (!is_null($databases)) { + $app['dependencies']['database'] = $databases; + } + $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); + $missing = $analyser->analyze(); + + $this->assertTrue(is_array($missing)); + $this->assertEquals(count($expectedMissing), count($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + 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: sqlite, postgres'), array('sqlite', 'postgres')), + ); + } + function providesPhpVersion() { return array( array(array(), null, null), -- cgit v1.2.3 From c80ec91f281419e59b3fd2ce2668278e440d6768 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 2 Dec 2014 11:03:25 +0100 Subject: switch to different parsing implementation to get xml attributes properly handled --- lib/private/app/infoparser.php | 57 +++++++++++++++++++++++++++++++++- tests/data/app/expected-info.json | 16 ++++++++-- tests/data/app/strange-types-info.json | 24 -------------- tests/data/app/strange-types-info.xml | 23 -------------- tests/data/app/valid-info.xml | 10 +++--- tests/lib/app/infoparser.php | 1 - 6 files changed, 75 insertions(+), 56 deletions(-) delete mode 100644 tests/data/app/strange-types-info.json delete mode 100644 tests/data/app/strange-types-info.xml (limited to 'lib') diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index e220fb40df6..3d2b42765aa 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -47,7 +47,7 @@ class InfoParser { if ($xml == false) { return null; } - $array = json_decode(json_encode((array)$xml), TRUE); + $array = $this->xmlToArray($xml, false); if (is_null($array)) { return null; } @@ -86,4 +86,59 @@ class InfoParser { return $array; } + + /** + * @param \SimpleXMLElement $xml + * @return array + */ + function xmlToArray($xml) { + if (!$xml->children()) { + return (string)$xml; + } + + $array = array(); + foreach ($xml->children() as $element => $node) { + $totalElement = count($xml->{$element}); + + if (!isset($array[$element])) { + $array[$element] = ""; + } + /** + * @var \SimpleXMLElement $node + */ + + // Has attributes + if ($attributes = $node->attributes()) { + $data = array( + '@attributes' => array(), + ); + if (!count($node->children())){ + $value = (string)$node; + if (!empty($value)) { + $data['@value'] = (string)$node; + } + } else { + $data = array_merge($data, $this->xmlToArray($node)); + } + foreach ($attributes as $attr => $value) { + $data['@attributes'][$attr] = (string)$value; + } + + if ($totalElement > 1) { + $array[$element][] = $data; + } else { + $array[$element] = $data; + } + // Just a value + } else { + if ($totalElement > 1) { + $array[$element][] = $this->xmlToArray($node); + } else { + $array[$element] = $this->xmlToArray($node); + } + } + } + + return $array; + } } diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index 9be6062220f..6da69fb9ad7 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -18,8 +18,20 @@ "ocsid": "166047", "dependencies": { "php": { - "min-version": 5.4 + "@attributes" : { + "min-version": "5.4", + "max-version": "5.5" + } }, - "database":["sqlite", "mysql"] + "databases": { + "database": [ + { + "@attributes" : { + "min-version": "3.0" + }, + "@value": "sqlite"}, + "mysql" + ] + } } } diff --git a/tests/data/app/strange-types-info.json b/tests/data/app/strange-types-info.json deleted file mode 100644 index eedf8bd0518..00000000000 --- a/tests/data/app/strange-types-info.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "info": [], - "remote": [], - "public": [], - "id": "files_encryption", - "name": "Server-side Encryption", - "description": "\n\tThis application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. \n\tNote that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation \n\t", - "licence": "AGPL", - "author": "Sam Tuke, Bjoern Schiessle, Florin Peter", - "requiremin": "4", - "shipped": "true", - "documentation": { - "user": "https://docs.example.com/server/go.php?to=user-encryption", - "admin": "https://docs.example.com/server/go.php?to=admin-encryption" - }, - "rememberlogin": "false", - "types": [], - "ocsid": "166047", - "dependencies": { - "php": { - "min-version": 5.4 - } - } -} diff --git a/tests/data/app/strange-types-info.xml b/tests/data/app/strange-types-info.xml deleted file mode 100644 index e7e8f0d0281..00000000000 --- a/tests/data/app/strange-types-info.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - files_encryption - Server-side Encryption - - This application encrypts all files accessed by ownCloud at rest, wherever they are stored. As an example, with this application enabled, external cloud based Amazon S3 storage will be encrypted, protecting this data on storage outside of the control of the Admin. When this application is enabled for the first time, all files are encrypted as users log in and are prompted for their password. The recommended recovery key option enables recovery of files in case the key is lost. - Note that this app encrypts all files that are touched by ownCloud, so external storage providers and applications such as SharePoint will see new files encrypted when they are accessed. Encryption is based on AES 128 or 256 bit keys. More information is available in the Encryption documentation - - AGPL - Sam Tuke, Bjoern Schiessle, Florin Peter - 4 - true - - user-encryption - admin-encryption - - false - - 166047 - - 5.4 - - diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index 3a40e62d147..cdb688c6b3f 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -20,10 +20,10 @@ 166047 - - 5.4 - - sqlite - mysql + + + sqlite + mysql + diff --git a/tests/lib/app/infoparser.php b/tests/lib/app/infoparser.php index 20668c05086..13c0b51e117 100644 --- a/tests/lib/app/infoparser.php +++ b/tests/lib/app/infoparser.php @@ -55,7 +55,6 @@ class InfoParser extends \PHPUnit_Framework_TestCase { function providesInfoXml() { return array( array('expected-info.json', 'valid-info.xml'), - array('strange-types-info.json', 'strange-types-info.xml'), array(null, 'invalid-info.xml'), ); } -- cgit v1.2.3 From b028a6afac6964a4c07ce83ed0f43969ab587117 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 2 Dec 2014 11:49:31 +0100 Subject: adjust dependency analyzer to use attributes properly --- lib/private/app/dependencyanalyzer.php | 41 ++++++++++++++++++++++------------ tests/lib/app/dependencyanalyzer.php | 8 +++---- 2 files changed, 31 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index 7fd181c076c..ae5ecf76cd1 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -12,13 +12,25 @@ namespace OC\App; class DependencyAnalyzer { + /** @var Platform */ + private $system; + + /** @var \OCP\IL10N */ + private $l; + + /** @var array */ + private $missing; + + /** @var array */ + private $dependencies; + /** * @param array $app - * @param Platform $system + * @param Platform $platform * @param \OCP\IL10N $l */ - function __construct(array $app, $system, $l) { - $this->system = $system; + function __construct(array $app, $platform, $l) { + $this->system = $platform; $this->l = $l; $this->missing = array(); $this->dependencies = array(); @@ -38,18 +50,14 @@ class DependencyAnalyzer { } private function analysePhpVersion() { - if (!array_key_exists('php', $this->dependencies)) { - return; - } - - if (array_key_exists('min-version', $this->dependencies['php'])) { - $minVersion = $this->dependencies['php']['min-version']; + if (isset($this->dependencies['php']['@attributes']['min-version'])) { + $minVersion = $this->dependencies['php']['@attributes']['min-version']; if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) { $this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion); } } - if (array_key_exists('max-version', $this->dependencies['php'])) { - $maxVersion = $this->dependencies['php']['max-version']; + if (isset($this->dependencies['php']['@attributes']['max-version'])) { + $maxVersion = $this->dependencies['php']['@attributes']['max-version']; if (version_compare($this->system->getPhpVersion(), $maxVersion, '>')) { $this->missing[] = (string)$this->l->t('PHP with a version less then %s is required.', $maxVersion); } @@ -57,18 +65,23 @@ class DependencyAnalyzer { } private function analyseSupportedDatabases() { - if (!array_key_exists('database', $this->dependencies)) { + if (!isset($this->dependencies['databases'])) { return; } - $supportedDatabases = $this->dependencies['database']; + $supportedDatabases = $this->dependencies['databases']; if (empty($supportedDatabases)) { return; } + $supportedDatabases = array_map(function($db) { + if (isset($db['@value'])) { + return $db['@value']; + } + return $db; + }, $supportedDatabases); $currentDatabase = $this->system->getDatabase(); if (!in_array($currentDatabase, $supportedDatabases)) { $this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases)); } } - } diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 25f2ad8caa8..122eb377d55 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -55,10 +55,10 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { ) ); if (!is_null($minVersion)) { - $app['dependencies']['php']['min-version'] = $minVersion; + $app['dependencies']['php']['@attributes']['min-version'] = $minVersion; } if (!is_null($maxVersion)) { - $app['dependencies']['php']['max-version'] = $maxVersion; + $app['dependencies']['php']['@attributes']['max-version'] = $maxVersion; } $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); $missing = $analyser->analyze(); @@ -77,7 +77,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { ) ); if (!is_null($databases)) { - $app['dependencies']['database'] = $databases; + $app['dependencies']['databases'] = $databases; } $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); $missing = $analyser->analyze(); @@ -92,7 +92,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { // non BC - in case on databases are defined -> all are supported array(array(), null), array(array(), array()), - array(array('Following databases are supported: sqlite, postgres'), array('sqlite', 'postgres')), + array(array('Following databases are supported: sqlite, postgres'), array('sqlite', array('@value' => 'postgres'))), ); } -- cgit v1.2.3 From eb81c52b9517321fb6e8da4c80f04f43ed96e3f7 Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 2 Dec 2014 15:06:51 +0100 Subject: fix an issue where the types tag holds an empty string --- lib/private/app/infoparser.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/private/app/infoparser.php b/lib/private/app/infoparser.php index 3d2b42765aa..0bfbf6bd139 100644 --- a/lib/private/app/infoparser.php +++ b/lib/private/app/infoparser.php @@ -76,11 +76,15 @@ class InfoParser { } } if (array_key_exists('types', $array)) { - foreach ($array['types'] as $type => $v) { - unset($array['types'][$type]); - if (is_string($type)) { - $array['types'][] = $type; + if (is_array($array['types'])) { + foreach ($array['types'] as $type => $v) { + unset($array['types'][$type]); + if (is_string($type)) { + $array['types'][] = $type; + } } + } else { + $array['types'] = array(); } } -- cgit v1.2.3 From b55ac514ac8a555e0fa14a391fec02d4c675748f Mon Sep 17 00:00:00 2001 From: Thomas Müller Date: Tue, 2 Dec 2014 15:14:48 +0100 Subject: no nested xml tags on dependencies --- lib/private/app/dependencyanalyzer.php | 4 ++-- tests/data/app/expected-info.json | 18 ++++++++---------- tests/data/app/valid-info.xml | 6 ++---- tests/lib/app/dependencyanalyzer.php | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) (limited to 'lib') diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index ae5ecf76cd1..fb4b3761656 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -65,11 +65,11 @@ class DependencyAnalyzer { } private function analyseSupportedDatabases() { - if (!isset($this->dependencies['databases'])) { + if (!isset($this->dependencies['database'])) { return; } - $supportedDatabases = $this->dependencies['databases']; + $supportedDatabases = $this->dependencies['database']; if (empty($supportedDatabases)) { return; } diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index 8ab6e48ac6d..fc0ab224977 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -23,16 +23,14 @@ "max-version": "5.5" } }, - "databases": { - "database": [ - { - "@attributes" : { - "min-version": "3.0" - }, - "@value": "sqlite"}, - "mysql" - ] - }, + "database": [ + { + "@attributes" : { + "min-version": "3.0" + }, + "@value": "sqlite"}, + "mysql" + ], "command": [ { "@attributes" : { diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index 354a39832fb..f01f5fd55ea 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -21,10 +21,8 @@ 166047 - - sqlite - mysql - + sqlite + mysql grep notepad.exe diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 122eb377d55..7d06842e8ad 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -77,7 +77,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { ) ); if (!is_null($databases)) { - $app['dependencies']['databases'] = $databases; + $app['dependencies']['database'] = $databases; } $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); $missing = $analyser->analyze(); -- cgit v1.2.3