From 78a3625ddfc67e7e6743a2ff6fd31e1566b174c8 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Thu, 14 Feb 2013 21:59:24 +0100 Subject: final adoptions for mssql connectivity --- tests/lib/dbschema.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index fb60ce7dbb7..e20a04ef7fd 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -91,9 +91,15 @@ class Test_DBSchema extends PHPUnit_Framework_TestCase { break; case 'pgsql': $sql = "SELECT tablename AS table_name, schemaname AS schema_name " - . "FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' " - . "AND schemaname != 'information_schema' " - . "AND tablename = '".$table."'"; + . "FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' " + . "AND schemaname != 'information_schema' " + . "AND tablename = '".$table."'"; + $query = OC_DB::prepare($sql); + $result = $query->execute(array()); + $exists = $result && $result->fetchOne(); + break; + case 'mssql': + $sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{$table}'"; $query = OC_DB::prepare($sql); $result = $query->execute(array()); $exists = $result && $result->fetchOne(); -- cgit v1.2.3 From 5bf3d286f02474c99dd52b2680594c9ed272f92a Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 25 Feb 2013 12:38:00 +0100 Subject: created unittests and factored out version test into seperate method --- lib/app.php | 36 ++++++++++++++++++++++++++++++++---- tests/lib/app.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 tests/lib/app.php (limited to 'tests') diff --git a/lib/app.php b/lib/app.php index 91bb833b0d0..2eb43a582e2 100644 --- a/lib/app.php +++ b/lib/app.php @@ -223,8 +223,7 @@ class OC_App{ // check if the app is compatible with this version of ownCloud $info=OC_App::getAppInfo($app); $version=OC_Util::getVersion(); - $fullVersion = (float) ($version[0] . '.' . $version[1] . $version[2]); - if(!isset($info['require']) or ($fullVersion < (float) $info['require'])) { + if(!isset($info['require']) or !self::isAppVersionCompatible($version, $info['require'])) { OC_Log::write('core', 'App "'.$info['name'].'" can\'t be installed because it is' .' not compatible with this version of ownCloud', @@ -852,8 +851,7 @@ class OC_App{ foreach($apps as $app) { // check if the app is compatible with this version of ownCloud $info = OC_App::getAppInfo($app); - $fullVersion = (float) ($version[0] . '.' . $version[1] . $version[2]); - if(!isset($info['require']) or ($fullVersion < (float) $info['require'])) { + if(!isset($info['require']) or !self::isAppVersionCompatible($version, $info['require'])) { OC_Log::write('core', 'App "'.$info['name'].'" ('.$app.') can\'t be used because it is' .' not compatible with this version of ownCloud', @@ -864,6 +862,36 @@ class OC_App{ } } + + /** + * Compares the app version with the owncloud version to see if the app + * requires a newer version than the currently active one + * @param array $owncloudVersions array with 3 entries: major minor bugfix + * @param string $appRequired the required version from the xml + * major.minor.bugfix + * @return boolean true if compatible, otherwise false + */ + public static function isAppVersionCompatible($owncloudVersions, $appRequired){ + $appVersions = explode('.', $appRequired); + + for($i=0; $i + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class Test_App extends PHPUnit_Framework_TestCase { + + + public function testIsAppVersionCompatibleSingleOCNumber(){ + $oc = array(4); + $app = '4.0'; + + $this->assertTrue(OC_App::isAppVersionCompatible($oc, $app)); + } + + + public function testIsAppVersionCompatibleMultipleOCNumber(){ + $oc = array(4, 3, 1); + $app = '4.3'; + + $this->assertTrue(OC_App::isAppVersionCompatible($oc, $app)); + } + + + public function testIsAppVersionCompatibleMultipleAppNumber(){ + $oc = array(4); + $app = '4'; + + $this->assertTrue(OC_App::isAppVersionCompatible($oc, $app)); + } + + + public function testIsAppVersionCompatibleSingleAppNumber(){ + $oc = array(4, 3); + $app = '4'; + + $this->assertTrue(OC_App::isAppVersionCompatible($oc, $app)); + } + + + public function testIsAppVersionCompatibleShouldFail(){ + $oc = array(4, 3, 1); + $app = '4.3.2'; + + $this->assertFalse(OC_App::isAppVersionCompatible($oc, $app)); + } + + +} \ No newline at end of file -- cgit v1.2.3 From 8068051ca42395db7386db3f8993276ad1b1007b Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 25 Feb 2013 12:47:34 +0100 Subject: more tests to fail the version check --- tests/lib/app.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/lib/app.php b/tests/lib/app.php index 2bcc34d3321..9cab36903a2 100644 --- a/tests/lib/app.php +++ b/tests/lib/app.php @@ -25,7 +25,7 @@ class Test_App extends PHPUnit_Framework_TestCase { } - public function testIsAppVersionCompatibleMultipleAppNumber(){ + public function testIsAppVersionCompatibleSingleNumber(){ $oc = array(4); $app = '4'; @@ -48,5 +48,19 @@ class Test_App extends PHPUnit_Framework_TestCase { $this->assertFalse(OC_App::isAppVersionCompatible($oc, $app)); } + public function testIsAppVersionCompatibleShouldFailTwoVersionNumbers(){ + $oc = array(4, 3, 1); + $app = '4.4'; + + $this->assertFalse(OC_App::isAppVersionCompatible($oc, $app)); + } + + + public function testIsAppVersionCompatibleShouldFailOneVersionNumbers(){ + $oc = array(4, 3, 1); + $app = '5'; + + $this->assertFalse(OC_App::isAppVersionCompatible($oc, $app)); + } } \ No newline at end of file -- cgit v1.2.3 From f415f3e03e733e6110827d28470aae51bdaea844 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 25 Feb 2013 23:06:26 +0100 Subject: return true once one owncloud version number is bigger at any position --- lib/app.php | 2 ++ tests/lib/app.php | 8 ++++++++ 2 files changed, 10 insertions(+) (limited to 'tests') diff --git a/lib/app.php b/lib/app.php index 2eb43a582e2..55b4543ec9f 100644 --- a/lib/app.php +++ b/lib/app.php @@ -885,6 +885,8 @@ class OC_App{ if($owncloudVersion < $appVersion){ return false; + } elseif ($owncloudVersion > $appVersion) { + return true; } } diff --git a/tests/lib/app.php b/tests/lib/app.php index 9cab36903a2..c452d752c9f 100644 --- a/tests/lib/app.php +++ b/tests/lib/app.php @@ -40,6 +40,14 @@ class Test_App extends PHPUnit_Framework_TestCase { $this->assertTrue(OC_App::isAppVersionCompatible($oc, $app)); } + + public function testIsAppVersionCompatibleComplex(){ + $oc = array(5, 0, 0); + $app = '4.5.1'; + + $this->assertTrue(OC_App::isAppVersionCompatible($oc, $app)); + } + public function testIsAppVersionCompatibleShouldFail(){ $oc = array(4, 3, 1); -- cgit v1.2.3