Skip to content

Commit

Permalink
Merge pull request #214 from XetaIO/fix-testcases
Browse files Browse the repository at this point in the history
Fix TestCases
  • Loading branch information
Emeric committed Apr 17, 2017
2 parents 020bcb3 + ce03afc commit 3b71571
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -39,7 +39,8 @@
"phpunit/phpunit": "*",
"cakephp/cakephp-codesniffer": "dev-master",
"cakephp/debug_kit": "~3.0",
"cakephp/bake": "~1.0"
"cakephp/bake": "~1.0",
"phpro/grumphp": "^0.11.4"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 16 additions & 0 deletions grumphp.yml
@@ -0,0 +1,16 @@
parameters:
bin_dir: ./vendor/bin
git_dir: .
tasks:
phpversion:
project: '5.6'
phpcs:
standard: "vendor/cakephp/cakephp-codesniffer/CakePHP/"
ignore_patterns:
- "*.ctp"
- config/
- logs/
- plugins/
- tests/
- tmp/
- webroot/
39 changes: 20 additions & 19 deletions src/Event/Notifications.php
Expand Up @@ -31,13 +31,14 @@ public function implementedEvents()
public function newNotification(Event $event)
{
$this->Notifications = TableRegistry::get('Notifications');
$type = $event->getData('type');

if (!isset($event->data['type'])) {
if (is_null($type)) {
return false;
}
$event->data['type'] = strtolower($event->data['type']);
$type = strtolower($type);

switch ($event->data['type']) {
switch ($type) {
case 'conversation.reply':
$result = $this->_conversationReply($event);
break;
Expand Down Expand Up @@ -70,7 +71,7 @@ public function dispatchParticipants(Event $event)
$participants = $this->ConversationsUsers
->find()
->where([
'ConversationsUsers.conversation_id' => $event->data['conversation_id']
'ConversationsUsers.conversation_id' => $event->getData('conversation_id')
])
->contain([
'Users' => function ($q) {
Expand All @@ -91,8 +92,8 @@ public function dispatchParticipants(Event $event)
}

foreach ($participants as $participant) {
if ($participant->user_id != $event->data['sender_id']) {
$event->data['participant'] = $participant;
if ($participant->user_id != $event->getData('sender_id')) {
$event->setData('participant', $participant);

$this->newNotification($event);
}
Expand All @@ -110,7 +111,7 @@ public function dispatchParticipants(Event $event)
*/
protected function _conversationReply(Event $event)
{
if (!is_integer($event->data['conversation_id'])) {
if (!is_integer($event->getData('conversation_id'))) {
return false;
}

Expand All @@ -120,7 +121,7 @@ protected function _conversationReply(Event $event)
$conversation = $this->Conversations
->find()
->where([
'Conversations.id' => $event->data['conversation_id']
'Conversations.id' => $event->getData('conversation_id')
])
->select([
'id', 'user_id', 'title', 'last_message_id'
Expand All @@ -130,7 +131,7 @@ protected function _conversationReply(Event $event)
$sender = $this->Users
->find('medium')
->where([
'Users.id' => $event->data['sender_id']
'Users.id' => $event->getData('sender_id')
])
->first();

Expand All @@ -139,8 +140,8 @@ protected function _conversationReply(Event $event)
->find()
->where([
'Notifications.foreign_key' => $conversation->id,
'Notifications.type' => $event->data['type'],
'Notifications.user_id' => $event->data['participant']->user->id
'Notifications.type' => $event->getData('type'),
'Notifications.user_id' => $event->getData('participant')->user->id
])
->first();

Expand All @@ -151,8 +152,8 @@ protected function _conversationReply(Event $event)
$this->Notifications->save($hasReplied);
} else {
$data = [];
$data['user_id'] = $event->data['participant']->user->id;
$data['type'] = $event->data['type'];
$data['user_id'] = $event->getData('participant')->user->id;
$data['type'] = $event->getData('type');
$data['data'] = serialize(['sender' => $sender, 'conversation' => $conversation]);
$data['foreign_key'] = $conversation->id;

Expand All @@ -176,7 +177,7 @@ protected function _bot(Event $event)

$user = $this->Users
->find()
->where(['id' => $event->data['user_id']])
->where(['id' => $event->getData('user_id')])
->first();

if (is_null($user)) {
Expand All @@ -185,7 +186,7 @@ protected function _bot(Event $event)

$data = [];
$data['user_id'] = $user->id;
$data['type'] = $event->data['type'];
$data['type'] = $event->getData('type');
$data['data'] = serialize(['icon' => '../img/notifications/welcome.png']);

$entity = $this->Notifications->newEntity($data);
Expand All @@ -208,7 +209,7 @@ protected function _badge(Event $event)

$badge = $this->Badges
->find()
->where(['Badges.id' => $event->data['badge']->badge_id])
->where(['Badges.id' => $event->getData('badge')->badge_id])
->first();

if (is_null($badge)) {
Expand All @@ -219,7 +220,7 @@ protected function _badge(Event $event)

$user = $this->Users
->find()
->where(['id' => $event->data['badge']->user_id])
->where(['id' => $event->getData('badge')->user_id])
->select([
'id'
])
Expand All @@ -230,8 +231,8 @@ protected function _badge(Event $event)
}

$data = [];
$data['user_id'] = $event->data['badge']->user_id;
$data['type'] = $event->data['type'];
$data['user_id'] = $event->getData('badge')->user_id;
$data['type'] = $event->getData('type');
$data['data'] = serialize(['badge' => $badge, 'user' => $user]);

$entity = $this->Notifications->newEntity($data);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/AttachmentsControllerTest.php
Expand Up @@ -81,7 +81,7 @@ public function testDownloadNotConnected()
]);
$this->get(['controller' => 'attachments', 'action' => 'download', 'type' => 'blog', 'id' => 1]);
$this->assertResponseCode(302);
$this->assertRedirect(['controller' => 'users', 'action' => 'login']);
$this->assertRedirect(['controller' => 'users', 'action' => 'login', 'redirect' => '/attachments/download/blog/1']);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Controller/UsersControllerTest.php
Expand Up @@ -238,7 +238,7 @@ public function testAccountUnauthorized()
{
$this->get(['controller' => 'users', 'action' => 'account']);
$this->assertResponseSuccess();
$this->assertRedirect(['controller' => 'users', 'action' => 'login']);
$this->assertRedirect(['controller' => 'users', 'action' => 'login', 'redirect' => '/users/account']);
}

/**
Expand Down Expand Up @@ -326,7 +326,7 @@ public function testSettingsUnauthorized()
{
$this->get(['controller' => 'users', 'action' => 'settings']);
$this->assertResponseSuccess();
$this->assertRedirect(['controller' => 'users', 'action' => 'login']);
$this->assertRedirect(['controller' => 'users', 'action' => 'login', 'redirect' => '/users/settings']);
}

/**
Expand Down

0 comments on commit 3b71571

Please sign in to comment.