Skip to content

Commit

Permalink
feat(tests): Add a demo app for testing
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Dec 21, 2023
1 parent f00db4c commit 4ffcaa5
Show file tree
Hide file tree
Showing 7 changed files with 1,350 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# https://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
52 changes: 52 additions & 0 deletions tests/appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>notifications</id>
<name>Notifications</name>
<summary><![CDATA[This app provides a backend and frontend for the notification API available in Nextcloud.]]></summary>
<description><![CDATA[This app provides a backend and frontend for the notification API available in Nextcloud.
The API is used by other apps to notify users in the web UI and sync clients about various things. Some examples are:
📬 Federated file sharing: You received a new remote share
📑 Comments: Another user mentioned you in a comment on a file
🚢 Update notification: Available update for an app or nextcloud itself
📣 Announcement center: An announcement was posted by an admin]]></description>

<version>2.16.0</version>
<licence>agpl</licence>
<author>Joas Schilling</author>

<types>
<logging/>
</types>

<category>tools</category>

<website>https://github.com/nextcloud/notifications</website>
<bugs>https://github.com/nextcloud/notifications/issues</bugs>
<repository>https://github.com/nextcloud/notifications.git</repository>

<dependencies>
<nextcloud min-version="28" max-version="28" />
</dependencies>

<background-jobs>
<job>OCA\Notifications\BackgroundJob\GenerateUserSettings</job>
<job>OCA\Notifications\BackgroundJob\SendNotificationMails</job>
</background-jobs>

<commands>
<command>OCA\Notifications\Command\Generate</command>
<command>OCA\Notifications\Command\TestPush</command>
</commands>

<settings>
<admin>OCA\Notifications\Settings\Admin</admin>
<admin-section>OCA\Notifications\Settings\AdminSection</admin-section>
<personal>OCA\Notifications\Settings\Personal</personal>
<personal-section>OCA\Notifications\Settings\PersonalSection</personal-section>
</settings>
</info>
42 changes: 42 additions & 0 deletions tests/appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023, Joas Schilling <[email protected]>
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Joas Schilling <[email protected]>
*
* @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/>
*
*/

return [
'ocs' => [
['name' => 'AdminSettings#adminScopeImplicitFromAdminRequired', 'url' => '/api/{apiVersion}/default-admin', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'AdminSettings#movedToDefaultScope', 'url' => '/api/{apiVersion}/default-admin-overwritten', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'AdminSettings#movedToSettingsTag', 'url' => '/api/{apiVersion}/moved-with-tag', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],

['name' => 'Settings#federationByController', 'url' => '/api/{apiVersion}/controller-scope', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#ignoreByDeprecatedAttributeOnMethod', 'url' => '/api/{apiVersion}/ignore-openapi-attribute', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#ignoreByScopeOnMethod', 'url' => '/api/{apiVersion}/ignore-method-scope', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#movedToDefaultScope', 'url' => '/api/{apiVersion}/default-scope', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#movedToAdminScope', 'url' => '/api/{apiVersion}/admin-scope', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#defaultAndAdminScope', 'url' => '/api/{apiVersion}/default-and-admin-scope', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#nestedSchemas', 'url' => '/api/{apiVersion}/nested-schemas', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
['name' => 'Settings#listSchemas', 'url' => '/api/{apiVersion}/list-schemas', 'verb' => 'POST', 'requirements' => ['apiVersion' => '(v2)']],
],
];
69 changes: 69 additions & 0 deletions tests/lib/Controller/AdminSettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2021, Julien Barnoin <[email protected]>
*
* @author Julien Barnoin <[email protected]>
*
* @license AGPL-3.0-or-later
*
* 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 OCA\Notifications\Controller;

use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;

class AdminSettingsController extends OCSController {
/**
* Route is only in the admin scope because there is no "NoAdminRequired" annotation or attribute
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Personal settings updated
*/
public function adminScopeImplicitFromAdminRequired(): DataResponse {
return new DataResponse();
}

/**
* Route is in the default scope because the method overwrites with the Attribute
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Personal settings updated
*/
#[OpenAPI]
public function movedToDefaultScope(): DataResponse {
return new DataResponse();
}

/**
* Route in default scope with tags
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Personal settings updated
*/
#[OpenAPI(tags: ['settings', 'admin-settings'])]
public function movedToSettingsTag(): DataResponse {
return new DataResponse();
}
}
164 changes: 164 additions & 0 deletions tests/lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2021, Julien Barnoin <[email protected]>
*
* @author Julien Barnoin <[email protected]>
*
* @license AGPL-3.0-or-later
*
* 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 OCA\Notifications\Controller;

use OCA\Notifications\ResponseDefinitions;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;

/**
* @psalm-import-type NotificationsPushDevice from ResponseDefinitions
* @psalm-import-type NotificationsNotification from ResponseDefinitions
* @psalm-import-type NotificationsCollection from ResponseDefinitions
*/
#[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)]
class SettingsController extends OCSController {

/**
* @NoAdminRequired
*
* Route is ignored because of scope on the controller
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: OK
*/
public function federationByController(): DataResponse {
return new DataResponse();
}

/**
* @NoAdminRequired
*
* Route is ignored because of IgnoreOpenAPI attribute on the method
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: OK
*/
#[IgnoreOpenAPI]
public function ignoreByDeprecatedAttributeOnMethod(): DataResponse {
return new DataResponse();
}

/**
* @NoAdminRequired
*
* Route is ignored because of scope on the method
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: OK
*/
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
public function ignoreByScopeOnMethod(): DataResponse {
return new DataResponse();
}

/**
* @NoAdminRequired
*
* Route is only in the default scope
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Personal settings updated
*/
#[OpenAPI]
public function movedToDefaultScope(): DataResponse {
return new DataResponse();
}

/**
* @NoAdminRequired
*
* Route is only in the admin scope due to defined scope
*
* @return DataResponse<Http::STATUS_OK, NotificationsPushDevice, array{}>
*
* 200: Admin settings updated
*/
#[OpenAPI(scope: OpenAPI::SCOPE_ADMINISTRATION)]
public function movedToAdminScope(): DataResponse {
return new DataResponse($this->createNotificationsPushDevice());
}

/**
* @return NotificationsPushDevice
*/
protected function createNotificationsPushDevice(): array {
return [
'publicKey' => 'publicKey',
'deviceIdentifier' => 'deviceIdentifier',
'signature' => 'signature',
];
}

/**
* @NoAdminRequired
*
* Route is in admin and default scope
*
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}>
*
* 200: Admin settings updated
*/
#[OpenAPI]
#[OpenAPI(scope: OpenAPI::SCOPE_ADMINISTRATION)]
public function defaultAndAdminScope(): DataResponse {
return new DataResponse();
}

/**
* @NoAdminRequired
*
* Route is ignored because of scope on the controller
*
* @return DataResponse<Http::STATUS_OK, list<NotificationsNotification>, array{}>
*
* 200: OK
*/
public function nestedSchemas(): DataResponse {
return new DataResponse();
}

/**
* @NoAdminRequired
*
* Route is ignored because of scope on the controller
*
* @return DataResponse<Http::STATUS_OK, NotificationsCollection, array{}>
*
* 200: OK
*/
public function listSchemas(): DataResponse {
return new DataResponse();
}
}
Loading

0 comments on commit 4ffcaa5

Please sign in to comment.