|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: arthur |
|
5
|
|
|
* Date: 14.10.18 |
|
6
|
|
|
* Time: 19:04 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Foundation\Tests; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Foundation\Abstracts\Tests\HttpTest; |
|
13
|
|
|
use Modules\User\Entities\User; |
|
14
|
|
|
use Modules\User\Notifications\UserRegisteredNotification; |
|
15
|
|
|
|
|
16
|
|
|
class NotificationsTest extends HttpTest |
|
17
|
|
|
{ |
|
18
|
|
|
public function testDatabaseNotification() |
|
19
|
|
|
{ |
|
20
|
|
|
$user = $this->getHttpUser(); |
|
21
|
|
|
$user->notifyNow(new UserRegisteredNotification($user)); |
|
22
|
|
|
$user->notifyNow(new UserRegisteredNotification($user)); |
|
23
|
|
|
|
|
24
|
|
|
$notifications = User::find($user->getKey())->unreadNotifications; |
|
25
|
|
|
$this->assertCount(2, $notifications); |
|
26
|
|
|
$notification = $user->unreadNotifications()->first(); |
|
27
|
|
|
$notificationId = $notification->getKey(); |
|
28
|
|
|
$response = $this->http('POST', 'v1/notifications/' . $notificationId); |
|
29
|
|
|
$response->assertStatus(200); |
|
30
|
|
|
$unreadnotifications = User::find($user->getKey())->unreadNotifications; |
|
31
|
|
|
$this->assertCount(1, $unreadnotifications); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testAllNotificationsRoute() |
|
35
|
|
|
{ |
|
36
|
|
|
$user = $this->getHttpUser(); |
|
37
|
|
|
$user->notifyNow(new UserRegisteredNotification($user)); |
|
38
|
|
|
$user->notifyNow(new UserRegisteredNotification($user)); |
|
39
|
|
|
$response = $this->http('GET', 'v1/notifications'); |
|
40
|
|
|
$response->assertStatus(200); |
|
41
|
|
|
/*$notificationsReponse = $this->decodeHttpContent($response->getContent());*/ |
|
42
|
|
|
/*$notifications = (array)User::find($user->getKey())->notifications->toArray(); |
|
43
|
|
|
$this->assertArraySubset($this->decodeHttpContent($response->getContent()), (array)$notifications);*/ |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testUnreadNotificationsRoute() |
|
47
|
|
|
{ |
|
48
|
|
|
$user = $this->getHttpUser(); |
|
49
|
|
|
$user->notifyNow(new UserRegisteredNotification($user)); |
|
50
|
|
|
$user->notifyNow(new UserRegisteredNotification($user)); |
|
51
|
|
|
$user->notifyNow(new UserRegisteredNotification($user)); |
|
52
|
|
|
$notification = $user->unreadNotifications()->first(); |
|
53
|
|
|
$notificationId = $notification->getKey(); |
|
54
|
|
|
$response = $this->http('POST', 'v1/notifications/' . $notificationId); |
|
55
|
|
|
$response->assertStatus(200); |
|
56
|
|
|
$response = $this->http('GET', 'v1/notifications/unread'); |
|
57
|
|
|
$response->assertStatus(200); |
|
58
|
|
|
$notifications = (array)User::find($user->getKey())->unreadNotifications->toArray(); |
|
|
|
|
|
|
59
|
|
|
//$this->assertEquals($notifications, $this->decodeHttpContent($response->getContent())); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|