diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2016-05-20 15:38:20 +0200 |
---|---|---|
committer | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-05-20 15:38:20 +0200 |
commit | 94ad54ec9b96d41a614fbbad4a97b34c41a6901f (patch) | |
tree | f3eb7cdda2704aaf0cd59d58efe66bcbd34cb67d /tests/lib/App | |
parent | 2ef751b1ec28f7b5c7113af60ec8c9fa0ae1cf87 (diff) | |
download | nextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.tar.gz nextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.zip |
Move tests/ to PSR-4 (#24731)
* Move a-b to PSR-4
* Move c-d to PSR-4
* Move e+g to PSR-4
* Move h-l to PSR-4
* Move m-r to PSR-4
* Move s-u to PSR-4
* Move files/ to PSR-4
* Move remaining tests to PSR-4
* Remove Test\ from old autoloader
Diffstat (limited to 'tests/lib/App')
-rw-r--r-- | tests/lib/App/CodeChecker/CodeCheckerTest.php | 64 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/DeprecationCheckTest.php | 70 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/InfoCheckerTest.php | 74 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/Mock/TestList.php | 92 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/NodeVisitorTest.php | 73 | ||||
-rw-r--r-- | tests/lib/App/CodeChecker/StrongComparisonCheckTest.php | 70 | ||||
-rw-r--r-- | tests/lib/App/DependencyAnalyzerTest.php | 298 | ||||
-rw-r--r-- | tests/lib/App/InfoParserTest.php | 55 | ||||
-rw-r--r-- | tests/lib/App/ManagerTest.php | 381 | ||||
-rw-r--r-- | tests/lib/App/PlatformRepositoryTest.php | 65 |
10 files changed, 1242 insertions, 0 deletions
diff --git a/tests/lib/App/CodeChecker/CodeCheckerTest.php b/tests/lib/App/CodeChecker/CodeCheckerTest.php new file mode 100644 index 00000000000..cdbb7c17da5 --- /dev/null +++ b/tests/lib/App/CodeChecker/CodeCheckerTest.php @@ -0,0 +1,64 @@ +<?php +/** + * Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\App\CodeChecker; + +use OC\App\CodeChecker\CodeChecker; +use OC\App\CodeChecker\EmptyCheck; +use OC\App\CodeChecker\PrivateCheck; +use Test\TestCase; + +class CodeCheckerTest extends TestCase { + + /** + * @dataProvider providesFilesToCheck + * @param string $expectedErrorToken + * @param int $expectedErrorCode + * @param string $fileToVerify + */ + public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { + $checker = new CodeChecker( + new PrivateCheck(new EmptyCheck()) + ); + $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); + + $this->assertEquals(1, count($errors)); + $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']); + $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']); + } + + public function providesFilesToCheck() { + return [ + ['OC_Hook', 1000, 'test-extends.php'], + ['oC_Avatar', 1001, 'test-implements.php'], + ['OC_App', 1002, 'test-static-call.php'], + ['OC_API', 1003, 'test-const.php'], + ['OC_AppConfig', 1004, 'test-new.php'], + ['OC_AppConfig', 1006, 'test-use.php'], + ]; + } + + /** + * @dataProvider validFilesData + * @param string $fileToVerify + */ + public function testPassValidUsage($fileToVerify) { + $checker = new CodeChecker( + new PrivateCheck(new EmptyCheck()) + ); + $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); + + $this->assertEquals(0, count($errors)); + } + + public function validFilesData() { + return [ + ['test-identical-operator.php'], + ]; + } +} diff --git a/tests/lib/App/CodeChecker/DeprecationCheckTest.php b/tests/lib/App/CodeChecker/DeprecationCheckTest.php new file mode 100644 index 00000000000..ee69f075a61 --- /dev/null +++ b/tests/lib/App/CodeChecker/DeprecationCheckTest.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\App\CodeChecker; + +use OC\App\CodeChecker\CodeChecker; +use OC\App\CodeChecker\DeprecationCheck; +use OC\App\CodeChecker\EmptyCheck; +use Test\TestCase; + +class DeprecationCheckTest extends TestCase { + + /** + * @dataProvider providesFilesToCheck + * @param string $expectedErrorToken + * @param int $expectedErrorCode + * @param string $fileToVerify + */ + public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { + $checker = new CodeChecker( + new DeprecationCheck(new EmptyCheck()) + ); + $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); + + $this->assertEquals(1, count($errors)); + $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']); + $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']); + } + + public function providesFilesToCheck() { + return [ + ['OCP\AppFramework\IApi', 1006, 'test-deprecated-use.php'], + ['OCP\AppFramework\IApi', 1006, 'test-deprecated-use-alias.php'], + ['AppFramework\IApi', 1001, 'test-deprecated-use-sub.php'], + ['OAF\IApi', 1001, 'test-deprecated-use-sub-alias.php'], + ['OC_API::ADMIN_AUTH', 1003, 'test-const.php'], + ]; + } + + /** + * @dataProvider validFilesData + * @param string $fileToVerify + */ + public function testPassValidUsage($fileToVerify) { + $checker = new CodeChecker( + new DeprecationCheck(new EmptyCheck()) + ); + $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); + + $this->assertEquals(0, count($errors)); + } + + public function validFilesData() { + return [ + ['test-equal.php'], + ['test-not-equal.php'], + ['test-extends.php'], + ['test-implements.php'], + ['test-static-call.php'], + ['test-new.php'], + ['test-use.php'], + ['test-identical-operator.php'], + ]; + } +} diff --git a/tests/lib/App/CodeChecker/InfoCheckerTest.php b/tests/lib/App/CodeChecker/InfoCheckerTest.php new file mode 100644 index 00000000000..1032e800be1 --- /dev/null +++ b/tests/lib/App/CodeChecker/InfoCheckerTest.php @@ -0,0 +1,74 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Test\App\CodeChecker; + +use OC\App\CodeChecker\InfoChecker; +use OC\App\InfoParser; +use Test\TestCase; + +class InfoCheckerTest extends TestCase { + /** @var InfoChecker */ + protected $infoChecker; + + public static function setUpBeforeClass() { + \OC::$APPSROOTS[] = [ + 'path' => \OC::$SERVERROOT . '/tests/apps', + 'url' => '/apps-test', + 'writable' => false, + ]; + } + + public static function tearDownAfterClass() { + // remove last element + array_pop(\OC::$APPSROOTS); + } + + protected function setUp() { + parent::setUp(); + $infoParser = new InfoParser(\OC::$server->getURLGenerator()); + + $this->infoChecker = new InfoChecker($infoParser); + } + + public function appInfoData() { + return [ + ['testapp-infoxml', []], + ['testapp-version', []], + ['testapp-infoxml-version', []], + ['testapp-infoxml-version-different', [['type' => 'differentVersions', 'message' => 'appinfo/version: 1.2.4 - appinfo/info.xml: 1.2.3']]], + ['testapp-version-missing', []], + ['testapp-name-missing', [['type' => 'mandatoryFieldMissing', 'field' => 'name']]], + ]; + } + + /** + * @dataProvider appInfoData + * + * @param $appId + * @param $expectedErrors + */ + public function testApps($appId, $expectedErrors) { + $errors = $this->infoChecker->analyse($appId); + + $this->assertEquals($expectedErrors, $errors); + } +} diff --git a/tests/lib/App/CodeChecker/Mock/TestList.php b/tests/lib/App/CodeChecker/Mock/TestList.php new file mode 100644 index 00000000000..1fe83293acf --- /dev/null +++ b/tests/lib/App/CodeChecker/Mock/TestList.php @@ -0,0 +1,92 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Test\App\CodeChecker\Mock; + +use OC\App\CodeChecker\ICheck; + +class TestList implements ICheck { + /** @var ICheck */ + protected $check; + + /** + * @param ICheck $check + */ + public function __construct(ICheck $check) { + $this->check = $check; + } + + /** + * @param int $errorCode + * @param string $errorObject + * @return string + */ + public function getDescription($errorCode, $errorObject) { + return 'testing'; + } + + /** + * @return array E.g.: `'ClassName' => 'oc version',` + */ + public function getClasses() { + return [ + // Deprecated classes + 'OCP\AppFramework\IApi' => '8.0.0', + ]; + } + + /** + * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` + */ + public function getConstants() { + return [ + // Deprecated constants + 'OCP\NamespaceName\ClassName::CONSTANT_NAME' => '8.0.0', + ]; + } + + /** + * @return array E.g.: `'functionName' => 'oc version',` + */ + public function getFunctions() { + return [ + // Deprecated functions + 'OCP\NamespaceName\ClassName::functionName' => '8.0.0', + ]; + } + + /** + * @return array E.g.: `'ClassName::methodName' => 'oc version',` + */ + public function getMethods() { + return [ + // Deprecated methods + 'OCP\NamespaceName\ClassName::methodName' => '8.0.0', + ]; + } + + /** + * @return bool + */ + public function checkStrongComparisons() { + return true; + } +} diff --git a/tests/lib/App/CodeChecker/NodeVisitorTest.php b/tests/lib/App/CodeChecker/NodeVisitorTest.php new file mode 100644 index 00000000000..ca0b6e9ccc1 --- /dev/null +++ b/tests/lib/App/CodeChecker/NodeVisitorTest.php @@ -0,0 +1,73 @@ +<?php +/** + * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\App\CodeChecker; + +use OC\App\CodeChecker\CodeChecker; +use OC\App\CodeChecker\EmptyCheck; +use Test\App\CodeChecker\Mock\TestList; +use Test\TestCase; + +class NodeVisitorTest extends TestCase { + + public function providesFilesToCheck() { + return [ + [[['OCP\AppFramework\IApi', 1006]], 'test-deprecated-use.php'], + [[['OCP\AppFramework\IApi', 1006]], 'test-deprecated-use-alias.php'], + [[['AppFramework\IApi', 1001]], 'test-deprecated-use-sub.php'], + [[['OAF\IApi', 1001]], 'test-deprecated-use-sub-alias.php'], + + [[['OCP\NamespaceName\ClassName::CONSTANT_NAME', 1003]], 'test-deprecated-constant.php'], + [[['Alias::CONSTANT_NAME', 1003]], 'test-deprecated-constant-alias.php'], + [[['NamespaceName\ClassName::CONSTANT_NAME', 1003]], 'test-deprecated-constant-sub.php'], + [[['SubAlias\ClassName::CONSTANT_NAME', 1003]], 'test-deprecated-constant-sub-alias.php'], + + [[ + ['OCP\NamespaceName\ClassName::functionName', 1002], + ['OCP\NamespaceName\ClassName::methodName', 1007], + ], 'test-deprecated-function.php'], + [[ + ['Alias::functionName', 1002], + ['Alias::methodName', 1007], + ], 'test-deprecated-function-alias.php'], + [[ + ['NamespaceName\ClassName::functionName', 1002], + ['NamespaceName\ClassName::methodName', 1007], + ], 'test-deprecated-function-sub.php'], + [[ + ['SubAlias\ClassName::functionName', 1002], + ['SubAlias\ClassName::methodName', 1007], + ], 'test-deprecated-function-sub-alias.php'], + + // TODO Failing to resolve variables to classes +// [[['OCP\NamespaceName\ClassName::methodName', 1007]], 'test-deprecated-method.php'], +// [[['Alias::methodName', 1002]], 'test-deprecated-method-alias.php'], +// [[['NamespaceName\ClassName::methodName', 1002]], 'test-deprecated-method-sub.php'], +// [[['SubAlias\ClassName::methodName', 1002]], 'test-deprecated-method-sub-alias.php'], + ]; + } + + /** + * @dataProvider providesFilesToCheck + * @param array $expectedErrors + * @param string $fileToVerify + */ + public function testMethodsToCheck($expectedErrors, $fileToVerify) { + $checker = new CodeChecker( + new TestList(new EmptyCheck()) + ); + $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); + + $this->assertCount(sizeof($expectedErrors), $errors); + + foreach ($expectedErrors as $int => $expectedError) { + $this->assertEquals($expectedError[0], $errors[$int]['disallowedToken']); + $this->assertEquals($expectedError[1], $errors[$int]['errorCode']); + } + } +} diff --git a/tests/lib/App/CodeChecker/StrongComparisonCheckTest.php b/tests/lib/App/CodeChecker/StrongComparisonCheckTest.php new file mode 100644 index 00000000000..c73eae286ab --- /dev/null +++ b/tests/lib/App/CodeChecker/StrongComparisonCheckTest.php @@ -0,0 +1,70 @@ +<?php +/** + * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\App\CodeChecker; + +use OC\App\CodeChecker\CodeChecker; +use OC\App\CodeChecker\EmptyCheck; +use OC\App\CodeChecker\StrongComparisonCheck; +use Test\TestCase; + +class StrongComparisonCheckTest extends TestCase { + + /** + * @dataProvider providesFilesToCheck + * @param string $expectedErrorToken + * @param int $expectedErrorCode + * @param string $fileToVerify + */ + public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { + $checker = new CodeChecker( + new StrongComparisonCheck(new EmptyCheck()) + ); + $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); + + $this->assertEquals(1, count($errors)); + $this->assertEquals($expectedErrorCode, $errors[0]['errorCode']); + $this->assertEquals($expectedErrorToken, $errors[0]['disallowedToken']); + } + + public function providesFilesToCheck() { + return [ + ['==', 1005, 'test-equal.php'], + ['!=', 1005, 'test-not-equal.php'], + ]; + } + + /** + * @dataProvider validFilesData + * @param string $fileToVerify + */ + public function testPassValidUsage($fileToVerify) { + $checker = new CodeChecker( + new StrongComparisonCheck(new EmptyCheck()) + ); + $errors = $checker->analyseFile(\OC::$SERVERROOT . "/tests/data/app/code-checker/$fileToVerify"); + + $this->assertEquals(0, count($errors)); + } + + public function validFilesData() { + return [ + ['test-deprecated-use.php'], + ['test-deprecated-use-alias.php'], + ['test-deprecated-use-sub.php'], + ['test-deprecated-use-sub-alias.php'], + ['test-extends.php'], + ['test-implements.php'], + ['test-static-call.php'], + ['test-const.php'], + ['test-new.php'], + ['test-use.php'], + ['test-identical-operator.php'], + ]; + } +} diff --git a/tests/lib/App/DependencyAnalyzerTest.php b/tests/lib/App/DependencyAnalyzerTest.php new file mode 100644 index 00000000000..7882f6dd031 --- /dev/null +++ b/tests/lib/App/DependencyAnalyzerTest.php @@ -0,0 +1,298 @@ +<?php + +/** + * @author Thomas Müller + * @copyright 2014 Thomas Müller deepdiver@owncloud.com + * later. + * See the COPYING-README file. + */ + +namespace Test\App; + +use OC; +use OC\App\Platform; +use OCP\IL10N; +use Test\TestCase; + +class DependencyAnalyzerTest extends TestCase { + + /** @var Platform */ + private $platformMock; + + /** @var IL10N */ + private $l10nMock; + + /** @var \OC\App\DependencyAnalyzer */ + private $analyser; + + 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('getIntSize') + ->will( $this->returnValue('4')); + $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.2')); + + $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); + })); + + $this->analyser = new \OC\App\DependencyAnalyzer($this->platformMock, $this->l10nMock); + } + + /** + * @dataProvider providesPhpVersion + * + * @param string $expectedMissing + * @param string $minVersion + * @param string $maxVersion + * @param string $intSize + */ + public function testPhpVersion($expectedMissing, $minVersion, $maxVersion, $intSize) { + $app = array( + 'dependencies' => array( + 'php' => array() + ) + ); + if (!is_null($minVersion)) { + $app['dependencies']['php']['@attributes']['min-version'] = $minVersion; + } + if (!is_null($maxVersion)) { + $app['dependencies']['php']['@attributes']['max-version'] = $maxVersion; + } + if (!is_null($intSize)) { + $app['dependencies']['php']['@attributes']['min-int-size'] = $intSize; + } + $missing = $this->analyser->analyze($app); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + /** + * @dataProvider providesDatabases + */ + public function testDatabases($expectedMissing, $databases) { + $app = array( + 'dependencies' => array( + ) + ); + if (!is_null($databases)) { + $app['dependencies']['database'] = $databases; + } + $missing = $this->analyser->analyze($app); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + /** + * @dataProvider providesCommands + * + * @param string $expectedMissing + * @param string|null $commands + */ + 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($expectedMissing, $missing); + } + + /** + * @return array + */ + function providesOC() { + return array( + // no version -> no missing dependency + array(array(), null), + array(array(), array('@attributes' => array('min-version' => '8', 'max-version' => '8'))), + array(array(), array('@attributes' => array('min-version' => '8.0', 'max-version' => '8.0'))), + array(array(), array('@attributes' => array('min-version' => '8.0.2', 'max-version' => '8.0.2'))), + array(array('ownCloud 8.0.3 or higher is required.'), array('@attributes' => array('min-version' => '8.0.3'))), + array(array('ownCloud 9 or higher is required.'), array('@attributes' => array('min-version' => '9'))), + [['ownCloud 8.0.1 or lower is required.'], ['@attributes' => ['max-version' => '8.0.1']]], + ); + } + + /** + * @return array + */ + 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')) + ); + } + + /** + * @return array + */ + 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'))), + array(array('Library curl with a version lower than 2.3.3 is required - available version 2.3.4.'), + array(array('@attributes' => array('max-version' => '2.3.3'), '@value' => 'curl'))), + array(array('Library curl with a version higher than 2.3.5 is required - available version 2.3.4.'), + array(array('@attributes' => array('min-version' => '2.3.5'), '@value' => 'curl'))), + array(array(), + array(array('@attributes' => array('min-version' => '2.3.4', 'max-version' => '2.3.4'), '@value' => 'curl'))), + array(array(), + array(array('@attributes' => array('min-version' => '2.3', 'max-version' => '2.3'), '@value' => 'curl'))), + array(array(), + array(array('@attributes' => array('min-version' => '2', 'max-version' => '2'), '@value' => 'curl'))), + ); + } + + /** + * @return array + */ + 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'), + ); + } + + /** + * @return array + */ + 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'))), + ); + } + + /** + * @return array + */ + function providesPhpVersion() { + return array( + array(array(), null, null, null), + array(array(), '5.4', null, null), + array(array(), null, '5.5', null), + array(array(), '5.4', '5.5', null), + array(array('PHP 5.4.4 or higher is required.'), '5.4.4', null, null), + array(array('PHP with a version lower than 5.4.2 is required.'), null, '5.4.2', null), + array(array('64bit or higher PHP required.'), null, null, 64), + array(array(), '5.4', '5.4', null), + ); + } +} diff --git a/tests/lib/App/InfoParserTest.php b/tests/lib/App/InfoParserTest.php new file mode 100644 index 00000000000..7f52507bcf7 --- /dev/null +++ b/tests/lib/App/InfoParserTest.php @@ -0,0 +1,55 @@ +<?php + +/** + * @author Thomas Müller + * @copyright 2014 Thomas Müller deepdiver@owncloud.com + * later. + * See the COPYING-README file. + */ + +namespace Test\App; + +use OC; +use OCP\IURLGenerator; +use Test\TestCase; + +class InfoParserTest extends TestCase { + + /** @var \OC\App\InfoParser */ + private $parser; + + public function setUp() { + $urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject $urlGenerator */ + $urlGenerator->expects($this->any()) + ->method('linkToDocs') + ->will($this->returnCallback(function ($url) { + return "https://docs.example.com/server/go.php?to=$url"; + })); + + $this->parser = new \OC\App\InfoParser($urlGenerator); + } + + /** + * @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); + } + + function providesInfoXml() { + return array( + array('expected-info.json', 'valid-info.xml'), + array(null, 'invalid-info.xml'), + ); + } +} diff --git a/tests/lib/App/ManagerTest.php b/tests/lib/App/ManagerTest.php new file mode 100644 index 00000000000..26584829b5f --- /dev/null +++ b/tests/lib/App/ManagerTest.php @@ -0,0 +1,381 @@ +<?php + +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\App; + +use OC\Group\Group; +use OC\User\User; +use Test\TestCase; + +/** + * Class Manager + * + * @package Test\App + * @group DB + */ +class ManagerTest extends TestCase { + /** + * @return \OCP\IAppConfig | \PHPUnit_Framework_MockObject_MockObject + */ + protected function getAppConfig() { + $appConfig = array(); + $config = $this->getMockBuilder('\OCP\IAppConfig') + ->disableOriginalConstructor() + ->getMock(); + + $config->expects($this->any()) + ->method('getValue') + ->will($this->returnCallback(function ($app, $key, $default) use (&$appConfig) { + return (isset($appConfig[$app]) and isset($appConfig[$app][$key])) ? $appConfig[$app][$key] : $default; + })); + $config->expects($this->any()) + ->method('setValue') + ->will($this->returnCallback(function ($app, $key, $value) use (&$appConfig) { + if (!isset($appConfig[$app])) { + $appConfig[$app] = array(); + } + $appConfig[$app][$key] = $value; + })); + $config->expects($this->any()) + ->method('getValues') + ->will($this->returnCallback(function ($app, $key) use (&$appConfig) { + if ($app) { + return $appConfig[$app]; + } else { + $values = array(); + foreach ($appConfig as $app => $appData) { + if (isset($appData[$key])) { + $values[$app] = $appData[$key]; + } + } + return $values; + } + })); + + return $config; + } + + /** @var \OCP\IUserSession */ + protected $userSession; + + /** @var \OCP\IGroupManager */ + protected $groupManager; + + /** @var \OCP\IAppConfig */ + protected $appConfig; + + /** @var \OCP\ICache */ + protected $cache; + + /** @var \OCP\ICacheFactory */ + protected $cacheFactory; + + /** @var \OCP\App\IAppManager */ + protected $manager; + + /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ + protected $eventDispatcher; + + protected function setUp() { + parent::setUp(); + + $this->userSession = $this->getMock('\OCP\IUserSession'); + $this->groupManager = $this->getMock('\OCP\IGroupManager'); + $this->appConfig = $this->getAppConfig(); + $this->cacheFactory = $this->getMock('\OCP\ICacheFactory'); + $this->cache = $this->getMock('\OCP\ICache'); + $this->eventDispatcher = $this->getMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $this->cacheFactory->expects($this->any()) + ->method('create') + ->with('settings') + ->willReturn($this->cache); + $this->manager = new \OC\App\AppManager($this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher); + } + + protected function expectClearCache() { + $this->cache->expects($this->once()) + ->method('clear') + ->with('listApps'); + } + + public function testEnableApp() { + $this->expectClearCache(); + $this->manager->enableApp('test'); + $this->assertEquals('yes', $this->appConfig->getValue('test', 'enabled', 'no')); + } + + public function testDisableApp() { + $this->expectClearCache(); + $this->manager->disableApp('test'); + $this->assertEquals('no', $this->appConfig->getValue('test', 'enabled', 'no')); + } + + public function testEnableAppForGroups() { + $groups = array( + new Group('group1', array(), null), + new Group('group2', array(), null) + ); + $this->expectClearCache(); + $this->manager->enableAppForGroups('test', $groups); + $this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no')); + } + + public function dataEnableAppForGroupsAllowedTypes() { + return [ + [[]], + [[ + 'types' => [], + ]], + [[ + 'types' => ['nickvergessen'], + ]], + ]; + } + + /** + * @dataProvider dataEnableAppForGroupsAllowedTypes + * + * @param array $appInfo + */ + public function testEnableAppForGroupsAllowedTypes(array $appInfo) { + $groups = array( + new Group('group1', array(), null), + new Group('group2', array(), null) + ); + $this->expectClearCache(); + + /** @var \OC\App\AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ + $manager = $this->getMockBuilder('OC\App\AppManager') + ->setConstructorArgs([ + $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher + ]) + ->setMethods([ + 'getAppInfo' + ]) + ->getMock(); + + $manager->expects($this->once()) + ->method('getAppInfo') + ->with('test') + ->willReturn($appInfo); + + $manager->enableAppForGroups('test', $groups); + $this->assertEquals('["group1","group2"]', $this->appConfig->getValue('test', 'enabled', 'no')); + } + + public function dataEnableAppForGroupsForbiddenTypes() { + return [ + ['filesystem'], + ['prelogin'], + ['authentication'], + ['logging'], + ['prevent_group_restriction'], + ]; + } + + /** + * @dataProvider dataEnableAppForGroupsForbiddenTypes + * + * @param string $type + * + * @expectedException \Exception + * @expectedExceptionMessage test can't be enabled for groups. + */ + public function testEnableAppForGroupsForbiddenTypes($type) { + $groups = array( + new Group('group1', array(), null), + new Group('group2', array(), null) + ); + + /** @var \OC\App\AppManager|\PHPUnit_Framework_MockObject_MockObject $manager */ + $manager = $this->getMockBuilder('OC\App\AppManager') + ->setConstructorArgs([ + $this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher + ]) + ->setMethods([ + 'getAppInfo' + ]) + ->getMock(); + + $manager->expects($this->once()) + ->method('getAppInfo') + ->with('test') + ->willReturn([ + 'types' => [$type], + ]); + + $manager->enableAppForGroups('test', $groups); + } + + public function testIsInstalledEnabled() { + $this->appConfig->setValue('test', 'enabled', 'yes'); + $this->assertTrue($this->manager->isInstalled('test')); + } + + public function testIsInstalledDisabled() { + $this->appConfig->setValue('test', 'enabled', 'no'); + $this->assertFalse($this->manager->isInstalled('test')); + } + + public function testIsInstalledEnabledForGroups() { + $this->appConfig->setValue('test', 'enabled', '["foo"]'); + $this->assertTrue($this->manager->isInstalled('test')); + } + + public function testIsEnabledForUserEnabled() { + $this->appConfig->setValue('test', 'enabled', 'yes'); + $user = new User('user1', null); + $this->assertTrue($this->manager->isEnabledForUser('test', $user)); + } + + public function testIsEnabledForUserDisabled() { + $this->appConfig->setValue('test', 'enabled', 'no'); + $user = new User('user1', null); + $this->assertFalse($this->manager->isEnabledForUser('test', $user)); + } + + public function testIsEnabledForUserEnabledForGroup() { + $user = new User('user1', null); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(array('foo', 'bar'))); + + $this->appConfig->setValue('test', 'enabled', '["foo"]'); + $this->assertTrue($this->manager->isEnabledForUser('test', $user)); + } + + public function testIsEnabledForUserDisabledForGroup() { + $user = new User('user1', null); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(array('bar'))); + + $this->appConfig->setValue('test', 'enabled', '["foo"]'); + $this->assertFalse($this->manager->isEnabledForUser('test', $user)); + } + + public function testIsEnabledForUserLoggedOut() { + $this->appConfig->setValue('test', 'enabled', '["foo"]'); + $this->assertFalse($this->manager->IsEnabledForUser('test')); + } + + public function testIsEnabledForUserLoggedIn() { + $user = new User('user1', null); + + $this->userSession->expects($this->once()) + ->method('getUser') + ->will($this->returnValue($user)); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(array('foo', 'bar'))); + + $this->appConfig->setValue('test', 'enabled', '["foo"]'); + $this->assertTrue($this->manager->isEnabledForUser('test')); + } + + public function testGetInstalledApps() { + $this->appConfig->setValue('test1', 'enabled', 'yes'); + $this->appConfig->setValue('test2', 'enabled', 'no'); + $this->appConfig->setValue('test3', 'enabled', '["foo"]'); + $this->assertEquals(['dav', 'federatedfilesharing', 'files', 'test1', 'test3'], $this->manager->getInstalledApps()); + } + + public function testGetAppsForUser() { + $user = new User('user1', null); + $this->groupManager->expects($this->any()) + ->method('getUserGroupIds') + ->with($user) + ->will($this->returnValue(array('foo', 'bar'))); + + $this->appConfig->setValue('test1', 'enabled', 'yes'); + $this->appConfig->setValue('test2', 'enabled', 'no'); + $this->appConfig->setValue('test3', 'enabled', '["foo"]'); + $this->appConfig->setValue('test4', 'enabled', '["asd"]'); + $this->assertEquals(['dav', 'federatedfilesharing', 'files', 'test1', 'test3'], $this->manager->getEnabledAppsForUser($user)); + } + + public function testGetAppsNeedingUpgrade() { + $this->manager = $this->getMockBuilder('\OC\App\AppManager') + ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher]) + ->setMethods(['getAppInfo']) + ->getMock(); + + $appInfos = [ + 'dav' => ['id' => 'dav'], + 'files' => ['id' => 'files'], + 'federatedfilesharing' => ['id' => 'federatedfilesharing'], + 'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '9.0.0'], + 'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'], + 'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'], + 'test4' => ['id' => 'test4', 'version' => '3.0.0', 'requiremin' => '8.1.0'], + 'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'], + ]; + + $this->manager->expects($this->any()) + ->method('getAppInfo') + ->will($this->returnCallback( + function($appId) use ($appInfos) { + return $appInfos[$appId]; + } + )); + + $this->appConfig->setValue('test1', 'enabled', 'yes'); + $this->appConfig->setValue('test1', 'installed_version', '1.0.0'); + $this->appConfig->setValue('test2', 'enabled', 'yes'); + $this->appConfig->setValue('test2', 'installed_version', '1.0.0'); + $this->appConfig->setValue('test3', 'enabled', 'yes'); + $this->appConfig->setValue('test3', 'installed_version', '1.0.0'); + $this->appConfig->setValue('test4', 'enabled', 'yes'); + $this->appConfig->setValue('test4', 'installed_version', '2.4.0'); + + $apps = $this->manager->getAppsNeedingUpgrade('8.2.0'); + + $this->assertCount(2, $apps); + $this->assertEquals('test1', $apps[0]['id']); + $this->assertEquals('test4', $apps[1]['id']); + } + + public function testGetIncompatibleApps() { + $this->manager = $this->getMockBuilder('\OC\App\AppManager') + ->setConstructorArgs([$this->userSession, $this->appConfig, $this->groupManager, $this->cacheFactory, $this->eventDispatcher]) + ->setMethods(['getAppInfo']) + ->getMock(); + + $appInfos = [ + 'dav' => ['id' => 'dav'], + 'files' => ['id' => 'files'], + 'federatedfilesharing' => ['id' => 'federatedfilesharing'], + 'test1' => ['id' => 'test1', 'version' => '1.0.1', 'requiremax' => '8.0.0'], + 'test2' => ['id' => 'test2', 'version' => '1.0.0', 'requiremin' => '8.2.0'], + 'test3' => ['id' => 'test3', 'version' => '1.2.4', 'requiremin' => '9.0.0'], + 'testnoversion' => ['id' => 'testnoversion', 'requiremin' => '8.2.0'], + ]; + + $this->manager->expects($this->any()) + ->method('getAppInfo') + ->will($this->returnCallback( + function($appId) use ($appInfos) { + return $appInfos[$appId]; + } + )); + + $this->appConfig->setValue('test1', 'enabled', 'yes'); + $this->appConfig->setValue('test2', 'enabled', 'yes'); + $this->appConfig->setValue('test3', 'enabled', 'yes'); + + $apps = $this->manager->getIncompatibleApps('8.2.0'); + + $this->assertCount(2, $apps); + $this->assertEquals('test1', $apps[0]['id']); + $this->assertEquals('test3', $apps[1]['id']); + } +} diff --git a/tests/lib/App/PlatformRepositoryTest.php b/tests/lib/App/PlatformRepositoryTest.php new file mode 100644 index 00000000000..783f8f473ff --- /dev/null +++ b/tests/lib/App/PlatformRepositoryTest.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 PlatformRepositoryTest 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'), + ); + }} |