summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2016-11-09 13:53:54 +0100
committerGitHub <noreply@github.com>2016-11-09 13:53:54 +0100
commiteadccc239a91490e1165dcc5a94c8c4845a3f66a (patch)
treed2409b6984716734074b892d410af7a9e52e388e /tests
parent6a75296ccbd37d11f88f1e69cfe4063a802c438c (diff)
parent9305094b8b10a3160dc2200934e86010fadd9a02 (diff)
downloadnextcloud-server-eadccc239a91490e1165dcc5a94c8c4845a3f66a.tar.gz
nextcloud-server-eadccc239a91490e1165dcc5a94c8c4845a3f66a.zip
Merge pull request #2052 from nextcloud/ros-definitions-as-php-class
Use a php class for the definitions to avoid loading problems
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/Notification/ManagerTest.php4
-rw-r--r--tests/lib/RichObjectStrings/DefinitionsTest.php93
-rw-r--r--tests/lib/RichObjectStrings/ValidatorTest.php3
3 files changed, 98 insertions, 2 deletions
diff --git a/tests/lib/Notification/ManagerTest.php b/tests/lib/Notification/ManagerTest.php
index 4410781bc31..e280838424b 100644
--- a/tests/lib/Notification/ManagerTest.php
+++ b/tests/lib/Notification/ManagerTest.php
@@ -23,6 +23,7 @@ namespace Test\Notification;
use OC\Notification\Manager;
use OCP\Notification\IManager;
+use OCP\RichObjectStrings\IValidator;
use Test\TestCase;
class ManagerTest extends TestCase {
@@ -31,7 +32,8 @@ class ManagerTest extends TestCase {
public function setUp() {
parent::setUp();
- $this->manager = new Manager();
+ $validator = $this->createMock(IValidator::class);
+ $this->manager = new Manager($validator);
}
public function testRegisterApp() {
diff --git a/tests/lib/RichObjectStrings/DefinitionsTest.php b/tests/lib/RichObjectStrings/DefinitionsTest.php
new file mode 100644
index 00000000000..e0d400bff2c
--- /dev/null
+++ b/tests/lib/RichObjectStrings/DefinitionsTest.php
@@ -0,0 +1,93 @@
+<?php
+/**
+ * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\RichObjectStrings;
+
+
+use OCP\RichObjectStrings\Definitions;
+use Test\TestCase;
+
+class DefinitionsTest extends TestCase {
+
+ public function dataGetDefinition() {
+ $definitions = new Definitions();
+ $testsuite = [];
+ foreach ($definitions->definitions as $type => $definition) {
+ $testsuite[] = [$type, $definition];
+ }
+ return $testsuite;
+ }
+
+ /**
+ * @expectedException \OCP\RichObjectStrings\InvalidObjectExeption
+ * @expectedExceptionMessage Object type is undefined
+ */
+ public function testGetDefinitionNotExisting() {
+ $definitions = new Definitions();
+ $definitions->getDefinition('NotExistingType');
+ }
+
+ /**
+ * @dataProvider dataGetDefinition
+ * @param string $type
+ * @param array $expected
+ */
+ public function testGetDefinition($type, array $expected) {
+ $definitions = new Definitions();
+ $definition = $definitions->getDefinition($type);
+
+ $this->assertEquals($expected, $definition);
+ $this->assertArrayHasKey('author', $definition);
+ $this->assertNotEquals('', $definition['author'], 'Author of definition must not be empty');
+ $this->assertArrayHasKey('app', $definition);
+ $this->assertNotEquals('', $definition['app'], 'App of definition must not be empty');
+ $this->assertArrayHasKey('since', $definition);
+ $this->assertNotEmpty($definition['since'], 'Since of definition must not be empty');
+ $this->assertArrayHasKey('parameters', $definition);
+ $this->assertTrue(is_array($definition['parameters']), 'Parameters of definition must be of type array');
+ $this->assertNotEmpty($definition['parameters'], 'Parameters of definition must not be empty');
+
+
+ $this->assertArrayHasKey('id', $definition['parameters'], 'Parameter ID must be defined');
+ $this->assertArrayHasKey('name', $definition['parameters'], 'Parameter name must be defined');
+
+ foreach ($definition['parameters'] as $parameter => $data) {
+ $this->validateParameter($parameter, $data);
+ }
+ }
+
+ public function validateParameter($parameter, $data) {
+ $this->assertTrue(is_array($data), 'Parameter ' . $parameter . ' is invalid');
+ $this->assertArrayHasKey('since', $data);
+ $this->assertNotEmpty($data['since'], 'Since of parameter ' . $parameter . ' must not be empty');
+ $this->assertArrayHasKey('required', $data);
+ $this->assertTrue(is_bool($data['required']), 'Required of parameter ' . $parameter . ' must be a boolean');
+ if ($parameter === 'id' || $parameter === 'name') {
+ $this->assertTrue($data['required'], 'Parameter ' . $parameter . ' must be required');
+ }
+
+ $this->assertArrayHasKey('description', $data);
+ $this->assertNotEquals('', $data['description'], 'Description of parameter ' . $parameter . ' must not be empty');
+ $this->assertArrayHasKey('example', $data);
+ $this->assertNotEquals('', $data['example'], 'Example of parameter ' . $parameter . ' must not be empty');
+
+ }
+}
diff --git a/tests/lib/RichObjectStrings/ValidatorTest.php b/tests/lib/RichObjectStrings/ValidatorTest.php
index b97388ab8e0..f18d1bdd908 100644
--- a/tests/lib/RichObjectStrings/ValidatorTest.php
+++ b/tests/lib/RichObjectStrings/ValidatorTest.php
@@ -23,12 +23,13 @@ namespace Test\RichObjectStrings;
use OC\RichObjectStrings\Validator;
+use OCP\RichObjectStrings\Definitions;
use Test\TestCase;
class ValidatorTest extends TestCase {
public function test() {
- $v = new Validator();
+ $v = new Validator(new Definitions());
$v->validate('test', []);
$v->validate('test {string1} test {foo} test {bar}.', [
'string1' => [