Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2016-09-06 11:54:58 +0300
committerJoas Schilling <coding@schilljs.com>2016-09-06 11:54:58 +0300
commitbe268c9fdc13a25ca3bdb9fc1cf46f10952bc115 (patch)
tree9d3fb9a7cc4e7919958b41b083879664c74a33db /tests/Unit
parentd61a1dfc396a09853f62633f7b96bce4b59e2b55 (diff)
Fix all tests
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/AppInfo/ApplicationTest.php54
-rw-r--r--tests/Unit/Controller/EndpointControllerTest.php50
-rw-r--r--tests/Unit/HandlerTest.php2
3 files changed, 46 insertions, 60 deletions
diff --git a/tests/Unit/AppInfo/ApplicationTest.php b/tests/Unit/AppInfo/ApplicationTest.php
index 61db3aa..e79f364 100644
--- a/tests/Unit/AppInfo/ApplicationTest.php
+++ b/tests/Unit/AppInfo/ApplicationTest.php
@@ -22,8 +22,14 @@
namespace OCA\Notifications\Tests\Unit\AppInfo;
+use OCA\Notifications\App;
use OCA\Notifications\AppInfo\Application;
+use OCA\Notifications\Capabilities;
+use OCA\Notifications\Controller\EndpointController;
+use OCA\Notifications\Handler;
use OCA\Notifications\Tests\Unit\TestCase;
+use OCP\AppFramework\OCSController;
+use OCP\Notification\IApp;
/**
* Class ApplicationTest
@@ -51,8 +57,17 @@ class ApplicationTest extends TestCase {
public function dataContainerQuery() {
return array(
- array('EndpointController', 'OCA\Notifications\Controller\EndpointController'),
- array('Capabilities', 'OCA\Notifications\Capabilities'),
+ // lib/
+ array(App::class),
+ array(App::class, IApp::class),
+ array(Capabilities::class),
+ array(Handler::class),
+
+ // Controller/
+ array('EndpointController', EndpointController::class),
+ array('EndpointController', OCSController::class),
+ array(EndpointController::class),
+ array(EndpointController::class, OCSController::class),
);
}
@@ -61,37 +76,10 @@ class ApplicationTest extends TestCase {
* @param string $service
* @param string $expected
*/
- public function testContainerQuery($service, $expected) {
+ public function testContainerQuery($service, $expected = null) {
+ if ($expected === null) {
+ $expected = $service;
+ }
$this->assertTrue($this->container->query($service) instanceof $expected);
}
-
- public function dataGetCurrentUser() {
- $user = $this->getMockBuilder('OCP\IUser')
- ->disableOriginalConstructor()
- ->getMock();
- $user->expects($this->any())
- ->method('getUID')
- ->willReturn('uid');
-
- return [
- [$user, 'uid'],
- [null, ''],
- ];
- }
-
- /**
- * @dataProvider dataGetCurrentUser
- * @param mixed $user
- * @param string $expected
- */
- public function testGetCurrentUser($user, $expected) {
- $session = $this->getMockBuilder('OCP\IUserSession')
- ->disableOriginalConstructor()
- ->getMock();
- $session->expects($this->any())
- ->method('getUser')
- ->willReturn($user);
-
- $this->assertSame($expected, $this->invokePrivate($this->app, 'getCurrentUser', [$session]));
- }
}
diff --git a/tests/Unit/Controller/EndpointControllerTest.php b/tests/Unit/Controller/EndpointControllerTest.php
index a98be77..db764ac 100644
--- a/tests/Unit/Controller/EndpointControllerTest.php
+++ b/tests/Unit/Controller/EndpointControllerTest.php
@@ -25,6 +25,7 @@ namespace OCA\Notifications\Tests\Unit\Controller;
use OCA\Notifications\Controller\EndpointController;
use OCA\Notifications\Tests\Unit\TestCase;
use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\DataResponse;
class EndpointControllerTest extends TestCase {
/** @var \OCP\IRequest|\PHPUnit_Framework_MockObject_MockObject */
@@ -181,7 +182,8 @@ class EndpointControllerTest extends TestCase {
->willReturn($notifications);
$response = $controller->listNotifications();
- $this->assertInstanceOf('OC_OCS_Result', $response);
+ $this->assertInstanceOf(DataResponse::class, $response);
+ $this->assertSame(Http::STATUS_OK, $response->getStatus());
$headers = $response->getHeaders();
$this->assertArrayHasKey('ETag', $headers);
@@ -246,7 +248,8 @@ class EndpointControllerTest extends TestCase {
->willReturn($notifications);
$response = $controller->listNotifications();
- $this->assertInstanceOf('OC_OCS_Result', $response);
+ $this->assertInstanceOf(DataResponse::class, $response);
+ $this->assertSame(Http::STATUS_OK, $response->getStatus());
$headers = $response->getHeaders();
$this->assertArrayHasKey('ETag', $headers);
@@ -261,9 +264,8 @@ class EndpointControllerTest extends TestCase {
->willReturn(false);
$response = $controller->listNotifications();
- $this->assertInstanceOf('OC_OCS_Result', $response);
-
- $this->assertSame(Http::STATUS_NO_CONTENT, $response->getStatusCode());
+ $this->assertInstanceOf(DataResponse::class, $response);
+ $this->assertSame(Http::STATUS_NO_CONTENT, $response->getStatus());
}
public function dataGetNotification() {
@@ -305,10 +307,9 @@ class EndpointControllerTest extends TestCase {
->with($id, $notification)
->willReturn('$notification');
- $response = $controller->getNotification(['id' => (string) $id]);
- $this->assertInstanceOf('OC_OCS_Result', $response);
-
- $this->assertSame(100, $response->getStatusCode());
+ $response = $controller->getNotification($id);
+ $this->assertInstanceOf(DataResponse::class, $response);
+ $this->assertSame(Http::STATUS_OK, $response->getStatus());
}
public function dataGetNotificationNoId() {
@@ -317,21 +318,21 @@ class EndpointControllerTest extends TestCase {
->getMock();
return [
- [false, [], false, null], // No notifiers
- [true, [], false, null], // No id
- [true, ['id' => 42], true, null], // Not found in database
- [true, ['id' => 42], true, $notification], // Not handled on prepare
+ [false, null, false, null], // No notifiers
+ [true, null, false, null], // No id
+ [true, 42, true, null], // Not found in database
+ [true, 42, true, $notification], // Not handled on prepare
];
}
/**
* @dataProvider dataGetNotificationNoId
* @param bool $hasNotifiers
- * @param array $parameters
+ * @param mixed $id
* @param bool $called
* @param null|\OCP\Notification\INotification $notification
*/
- public function testGetNotificationNoId($hasNotifiers, array $parameters, $called, $notification) {
+ public function testGetNotificationNoId($hasNotifiers, $id, $called, $notification) {
$controller = $this->getController();
$this->manager->expects($this->once())
@@ -346,10 +347,9 @@ class EndpointControllerTest extends TestCase {
->method('prepare')
->willThrowException(new \InvalidArgumentException());
- $response = $controller->getNotification($parameters);
- $this->assertInstanceOf('OC_OCS_Result', $response);
-
- $this->assertSame(404, $response->getStatusCode());
+ $response = $controller->getNotification($id);
+ $this->assertInstanceOf(DataResponse::class, $response);
+ $this->assertSame(Http::STATUS_NOT_FOUND, $response->getStatus());
}
public function dataDeleteNotification() {
@@ -371,10 +371,9 @@ class EndpointControllerTest extends TestCase {
->method('deleteById')
->with($id, $username);
- $response = $controller->deleteNotification(['id' => (string) $id]);
- $this->assertInstanceOf('OC_OCS_Result', $response);
-
- $this->assertSame(100, $response->getStatusCode());
+ $response = $controller->deleteNotification($id);
+ $this->assertInstanceOf(DataResponse::class, $response);
+ $this->assertSame(Http::STATUS_OK, $response->getStatus());
}
public function testDeleteNotificationNoId() {
@@ -384,9 +383,8 @@ class EndpointControllerTest extends TestCase {
->method('deleteById');
$response = $controller->deleteNotification([]);
- $this->assertInstanceOf('OC_OCS_Result', $response);
-
- $this->assertSame(404, $response->getStatusCode());
+ $this->assertInstanceOf(DataResponse::class, $response);
+ $this->assertSame(Http::STATUS_NOT_FOUND, $response->getStatus());
}
public function dataNotificationToArray() {
diff --git a/tests/Unit/HandlerTest.php b/tests/Unit/HandlerTest.php
index 2e8836d..99cf804 100644
--- a/tests/Unit/HandlerTest.php
+++ b/tests/Unit/HandlerTest.php
@@ -87,7 +87,7 @@ class HandlerTest extends TestCase {
$this->assertCount(0, $notifications, 'Wrong notification count for user2 before beginning');
// Add and count
- $this->assertGreaterThan($this->handler->add($notification), 0);
+ $this->assertGreaterThan(0, $this->handler->add($notification));
$this->assertSame(1, $this->handler->count($limitedNotification1), 'Wrong notification count for user1 after adding');
$this->assertSame(0, $this->handler->count($limitedNotification2), 'Wrong notification count for user2 after adding');