diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/app/code-checker/test-const.php | 10 | ||||
-rw-r--r-- | tests/data/app/code-checker/test-extends.php | 8 | ||||
-rw-r--r-- | tests/data/app/code-checker/test-implements.php | 9 | ||||
-rw-r--r-- | tests/data/app/code-checker/test-new.php | 10 | ||||
-rw-r--r-- | tests/data/app/code-checker/test-static-call.php | 10 | ||||
-rw-r--r-- | tests/lib/app/codechecker.php | 38 |
6 files changed, 85 insertions, 0 deletions
diff --git a/tests/data/app/code-checker/test-const.php b/tests/data/app/code-checker/test-const.php new file mode 100644 index 00000000000..2af6baf2f3d --- /dev/null +++ b/tests/data/app/code-checker/test-const.php @@ -0,0 +1,10 @@ +<?php + +/** + * Class BadClass - accessing consts on blacklisted classes is not allowed + */ +class BadClass { + public function foo() { + $bar = OC_API::ADMIN_AUTH; + } +} diff --git a/tests/data/app/code-checker/test-extends.php b/tests/data/app/code-checker/test-extends.php new file mode 100644 index 00000000000..39d29da92dc --- /dev/null +++ b/tests/data/app/code-checker/test-extends.php @@ -0,0 +1,8 @@ +<?php + +/** + * Class BadClass - sub class a forbidden class is not allowed + */ +class BadClass extends OC_Hook { + +} diff --git a/tests/data/app/code-checker/test-implements.php b/tests/data/app/code-checker/test-implements.php new file mode 100644 index 00000000000..3bf2f959b52 --- /dev/null +++ b/tests/data/app/code-checker/test-implements.php @@ -0,0 +1,9 @@ +<?php + +/** + * Class BadClass - sub class a forbidden class is not allowed + * NOTE: lowercase typo is intended + */ +class BadClass implements oC_Avatar { + +} diff --git a/tests/data/app/code-checker/test-new.php b/tests/data/app/code-checker/test-new.php new file mode 100644 index 00000000000..0522d473d96 --- /dev/null +++ b/tests/data/app/code-checker/test-new.php @@ -0,0 +1,10 @@ +<?php + +/** + * Class BadClass - creating an instance of a blacklisted class is not allowed + */ +class BadClass { + public function foo() { + $bar = new OC_AppConfig(); + } +} diff --git a/tests/data/app/code-checker/test-static-call.php b/tests/data/app/code-checker/test-static-call.php new file mode 100644 index 00000000000..4afe0b1174d --- /dev/null +++ b/tests/data/app/code-checker/test-static-call.php @@ -0,0 +1,10 @@ +<?php + +/** + * Class BadClass - calling static methods on blacklisted classes is not allowed + */ +class BadClass { + public function foo() { + OC_App::isEnabled('bar'); + } +} diff --git a/tests/lib/app/codechecker.php b/tests/lib/app/codechecker.php new file mode 100644 index 00000000000..64403fd0f23 --- /dev/null +++ b/tests/lib/app/codechecker.php @@ -0,0 +1,38 @@ +<?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; + +use OC; + +class CodeChecker extends \Test\TestCase { + + /** + * @dataProvider providesFilesToCheck + * @param $expectedErrors + * @param $fileToVerify + */ + public function testFindInvalidUsage($expectedErrorToken, $expectedErrorCode, $fileToVerify) { + $checker = new OC\App\CodeChecker(); + $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'], + ]; + } +} |