@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace florinp\messenger\controller; |
| 4 | 4 | |
| 5 | -use Symfony\Component\HttpFoundation\Response; |
|
| 6 | 5 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 7 | 6 | |
| 8 | 7 | class main |
@@ -8,204 +8,204 @@ |
||
| 8 | 8 | class main |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - protected $user; |
|
| 12 | - protected $model; |
|
| 13 | - protected $request; |
|
| 14 | - protected $notification_manager; |
|
| 15 | - protected $emojione; |
|
| 16 | - protected $upload; |
|
| 17 | - protected $download; |
|
| 18 | - |
|
| 19 | - public function __construct( |
|
| 20 | - \phpbb\request\request $request, |
|
| 21 | - \phpbb\user $user, |
|
| 22 | - \florinp\messenger\models\main_model $model, |
|
| 23 | - \phpbb\notification\manager $notification_manager, |
|
| 24 | - \florinp\messenger\libs\emojione $emojione, |
|
| 25 | - \florinp\messenger\libs\upload $upload, |
|
| 26 | - \florinp\messenger\libs\download $download |
|
| 27 | - ) |
|
| 28 | - { |
|
| 29 | - $this->request = $request; |
|
| 30 | - $this->user = $user; |
|
| 31 | - $this->model = $model; |
|
| 32 | - $this->notification_manager = $notification_manager; |
|
| 33 | - $this->emojione = $emojione; |
|
| 34 | - $this->upload = $upload; |
|
| 35 | - $this->download = $download; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function handle() |
|
| 39 | - { |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - public function index() |
|
| 43 | - { |
|
| 44 | - |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function publish() |
|
| 48 | - { |
|
| 49 | - $text = $this->request->variable('text', '', true); |
|
| 50 | - $receiver_id = $this->request->variable('receiver_id', 0); |
|
| 51 | - $sender_id = $this->user->data['user_id']; |
|
| 52 | - |
|
| 53 | - $response = array(); |
|
| 54 | - if ($receiver_id != 0 && trim($text) != '') { |
|
| 55 | - $text = htmlspecialchars($text); |
|
| 56 | - $text = str_replace(array("\n", "\r"), '', $text); |
|
| 57 | - |
|
| 58 | - $message = array( |
|
| 59 | - 'sender_id' => $sender_id, |
|
| 60 | - 'receiver_id' => $receiver_id, |
|
| 61 | - 'text' => $text, |
|
| 62 | - 'sentAt' => time() |
|
| 63 | - ); |
|
| 64 | - |
|
| 65 | - if ($id = $this->model->sendMessage($message)) { |
|
| 66 | - $lastMessage = $this->model->getMessageById($id); |
|
| 67 | - $response = array('success' => true, 'message' => $lastMessage); |
|
| 68 | - } else { |
|
| 69 | - $response = array( |
|
| 70 | - 'succes' => false, |
|
| 71 | - 'error' => 'An error has been ocurred!' |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - return new JsonResponse($response, 200); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function getFile($id) |
|
| 80 | - { |
|
| 81 | - $id = explode('_', $id)[1]; |
|
| 82 | - $file = $this->model->getFileById($id); |
|
| 83 | - $this->download->setFile($file['file']); |
|
| 84 | - $this->download->sendDownload(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function sendFile() |
|
| 88 | - { |
|
| 89 | - $receiver_id = $this->request->variable('receiver_id', 0); |
|
| 90 | - $sender_id = $this->user->data['user_id']; |
|
| 91 | - |
|
| 92 | - $response = array(); |
|
| 93 | - $file = $this->request->file('file'); |
|
| 94 | - if ($receiver_id != 0 && !empty($file)) { |
|
| 95 | - if ($file['error'] == 0) { |
|
| 96 | - $this->upload->file($file); |
|
| 97 | - $this->upload->set_allowed_mime_types(array( |
|
| 98 | - 'image/gif', |
|
| 99 | - 'image/jpeg', |
|
| 100 | - 'image/png', |
|
| 101 | - 'application/pdf', |
|
| 102 | - 'application/x-rar-compressed', |
|
| 103 | - 'application/zip', |
|
| 104 | - 'application/x-7z-compressed', |
|
| 105 | - 'text/plain' |
|
| 106 | - )); |
|
| 107 | - $results = $this->upload->upload(); |
|
| 108 | - if (isset($results['errors']) && count($results['errors'])) { |
|
| 109 | - $response = array( |
|
| 110 | - 'success' => false, |
|
| 111 | - 'errors' => $results['errors'] |
|
| 112 | - ); |
|
| 113 | - } else { |
|
| 114 | - $data = array( |
|
| 115 | - 'sender_id' => $sender_id, |
|
| 116 | - 'receiver_id' => $receiver_id, |
|
| 117 | - 'fileName' => $results['original_filename'], |
|
| 118 | - 'file' => $results['filename'], |
|
| 119 | - 'type' => $results['mime'], |
|
| 120 | - ); |
|
| 121 | - if ($id = $this->model->sendFile($data)) { |
|
| 122 | - $lastFile = $this->model->getFileById($id); |
|
| 123 | - $response = array( |
|
| 124 | - 'success' => true, |
|
| 125 | - 'file' => $lastFile |
|
| 126 | - ); |
|
| 127 | - } else { |
|
| 128 | - $response = array( |
|
| 129 | - 'succes' => false, |
|
| 130 | - 'error' => 'An error has been ocurred!' |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - } else { |
|
| 135 | - $response = array( |
|
| 136 | - 'succes' => false, |
|
| 137 | - 'error' => $file['error'] |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return new JsonResponse($response, 200); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function load() |
|
| 146 | - { |
|
| 147 | - $friend_id = $this->request->variable('friend_id', 0); |
|
| 148 | - |
|
| 149 | - if ($friend_id > 0) { |
|
| 150 | - $messages = $this->model->getMessages($friend_id); |
|
| 151 | - return new JsonResponse($messages, 200); |
|
| 152 | - } |
|
| 153 | - return new JsonResponse(array('success' => false, 'error' => 'The request is invalid'), 200); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function updateMessages() |
|
| 157 | - { |
|
| 158 | - $friend_id = $this->request->variable('friend_id', 0); |
|
| 159 | - if ($friend_id > 0) { |
|
| 160 | - $newVal = $this->model->updateMessagesStatus($friend_id); |
|
| 161 | - return new JsonResponse(array('success' => true, 'newVal' => $newVal), 200); |
|
| 162 | - } |
|
| 163 | - return new JsonResponse(array('success' => false), 200); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - public function checkForNewMessages() |
|
| 167 | - { |
|
| 168 | - $friend_id = $this->request->variable('friend_id', 0); |
|
| 169 | - if ($friend_id > 0) { |
|
| 170 | - $messages = $this->model->getInboxFromId($friend_id); |
|
| 171 | - return new JsonResponse(array('success' => true, 'messages' => $messages), 200); |
|
| 172 | - } |
|
| 173 | - return new JsonResponse(array('success' => false), 200); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - public function getFriends() |
|
| 177 | - { |
|
| 178 | - $friends = $this->model->getFriends(); |
|
| 179 | - $friends_online = array_filter($friends, function ($friend) { |
|
| 180 | - return $friend['user_status'] != 0; |
|
| 181 | - }); |
|
| 182 | - |
|
| 183 | - $response = array( |
|
| 184 | - 'friends_online' => count($friends_online), |
|
| 185 | - 'friends_list' => $friends |
|
| 186 | - ); |
|
| 187 | - |
|
| 188 | - return new JsonResponse($response, 200); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - public function getEmoticons() |
|
| 192 | - { |
|
| 193 | - $emoticons = \florinp\messenger\libs\emojione::$ascii_replace; |
|
| 194 | - $eicons = array(); |
|
| 195 | - foreach ($emoticons as $code => $value) { |
|
| 196 | - $eicons[$value] = $code; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $response = array(); |
|
| 200 | - foreach ($eicons as $emoticon) { |
|
| 201 | - $item = array(); |
|
| 202 | - $item['code'] = $emoticon; |
|
| 203 | - $item['image'] = $this->emojione->toImage($emoticon); |
|
| 204 | - |
|
| 205 | - $response[] = $item; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return new JsonResponse($response, 200); |
|
| 209 | - } |
|
| 11 | + protected $user; |
|
| 12 | + protected $model; |
|
| 13 | + protected $request; |
|
| 14 | + protected $notification_manager; |
|
| 15 | + protected $emojione; |
|
| 16 | + protected $upload; |
|
| 17 | + protected $download; |
|
| 18 | + |
|
| 19 | + public function __construct( |
|
| 20 | + \phpbb\request\request $request, |
|
| 21 | + \phpbb\user $user, |
|
| 22 | + \florinp\messenger\models\main_model $model, |
|
| 23 | + \phpbb\notification\manager $notification_manager, |
|
| 24 | + \florinp\messenger\libs\emojione $emojione, |
|
| 25 | + \florinp\messenger\libs\upload $upload, |
|
| 26 | + \florinp\messenger\libs\download $download |
|
| 27 | + ) |
|
| 28 | + { |
|
| 29 | + $this->request = $request; |
|
| 30 | + $this->user = $user; |
|
| 31 | + $this->model = $model; |
|
| 32 | + $this->notification_manager = $notification_manager; |
|
| 33 | + $this->emojione = $emojione; |
|
| 34 | + $this->upload = $upload; |
|
| 35 | + $this->download = $download; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function handle() |
|
| 39 | + { |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + public function index() |
|
| 43 | + { |
|
| 44 | + |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function publish() |
|
| 48 | + { |
|
| 49 | + $text = $this->request->variable('text', '', true); |
|
| 50 | + $receiver_id = $this->request->variable('receiver_id', 0); |
|
| 51 | + $sender_id = $this->user->data['user_id']; |
|
| 52 | + |
|
| 53 | + $response = array(); |
|
| 54 | + if ($receiver_id != 0 && trim($text) != '') { |
|
| 55 | + $text = htmlspecialchars($text); |
|
| 56 | + $text = str_replace(array("\n", "\r"), '', $text); |
|
| 57 | + |
|
| 58 | + $message = array( |
|
| 59 | + 'sender_id' => $sender_id, |
|
| 60 | + 'receiver_id' => $receiver_id, |
|
| 61 | + 'text' => $text, |
|
| 62 | + 'sentAt' => time() |
|
| 63 | + ); |
|
| 64 | + |
|
| 65 | + if ($id = $this->model->sendMessage($message)) { |
|
| 66 | + $lastMessage = $this->model->getMessageById($id); |
|
| 67 | + $response = array('success' => true, 'message' => $lastMessage); |
|
| 68 | + } else { |
|
| 69 | + $response = array( |
|
| 70 | + 'succes' => false, |
|
| 71 | + 'error' => 'An error has been ocurred!' |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + return new JsonResponse($response, 200); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function getFile($id) |
|
| 80 | + { |
|
| 81 | + $id = explode('_', $id)[1]; |
|
| 82 | + $file = $this->model->getFileById($id); |
|
| 83 | + $this->download->setFile($file['file']); |
|
| 84 | + $this->download->sendDownload(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function sendFile() |
|
| 88 | + { |
|
| 89 | + $receiver_id = $this->request->variable('receiver_id', 0); |
|
| 90 | + $sender_id = $this->user->data['user_id']; |
|
| 91 | + |
|
| 92 | + $response = array(); |
|
| 93 | + $file = $this->request->file('file'); |
|
| 94 | + if ($receiver_id != 0 && !empty($file)) { |
|
| 95 | + if ($file['error'] == 0) { |
|
| 96 | + $this->upload->file($file); |
|
| 97 | + $this->upload->set_allowed_mime_types(array( |
|
| 98 | + 'image/gif', |
|
| 99 | + 'image/jpeg', |
|
| 100 | + 'image/png', |
|
| 101 | + 'application/pdf', |
|
| 102 | + 'application/x-rar-compressed', |
|
| 103 | + 'application/zip', |
|
| 104 | + 'application/x-7z-compressed', |
|
| 105 | + 'text/plain' |
|
| 106 | + )); |
|
| 107 | + $results = $this->upload->upload(); |
|
| 108 | + if (isset($results['errors']) && count($results['errors'])) { |
|
| 109 | + $response = array( |
|
| 110 | + 'success' => false, |
|
| 111 | + 'errors' => $results['errors'] |
|
| 112 | + ); |
|
| 113 | + } else { |
|
| 114 | + $data = array( |
|
| 115 | + 'sender_id' => $sender_id, |
|
| 116 | + 'receiver_id' => $receiver_id, |
|
| 117 | + 'fileName' => $results['original_filename'], |
|
| 118 | + 'file' => $results['filename'], |
|
| 119 | + 'type' => $results['mime'], |
|
| 120 | + ); |
|
| 121 | + if ($id = $this->model->sendFile($data)) { |
|
| 122 | + $lastFile = $this->model->getFileById($id); |
|
| 123 | + $response = array( |
|
| 124 | + 'success' => true, |
|
| 125 | + 'file' => $lastFile |
|
| 126 | + ); |
|
| 127 | + } else { |
|
| 128 | + $response = array( |
|
| 129 | + 'succes' => false, |
|
| 130 | + 'error' => 'An error has been ocurred!' |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + } else { |
|
| 135 | + $response = array( |
|
| 136 | + 'succes' => false, |
|
| 137 | + 'error' => $file['error'] |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return new JsonResponse($response, 200); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function load() |
|
| 146 | + { |
|
| 147 | + $friend_id = $this->request->variable('friend_id', 0); |
|
| 148 | + |
|
| 149 | + if ($friend_id > 0) { |
|
| 150 | + $messages = $this->model->getMessages($friend_id); |
|
| 151 | + return new JsonResponse($messages, 200); |
|
| 152 | + } |
|
| 153 | + return new JsonResponse(array('success' => false, 'error' => 'The request is invalid'), 200); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function updateMessages() |
|
| 157 | + { |
|
| 158 | + $friend_id = $this->request->variable('friend_id', 0); |
|
| 159 | + if ($friend_id > 0) { |
|
| 160 | + $newVal = $this->model->updateMessagesStatus($friend_id); |
|
| 161 | + return new JsonResponse(array('success' => true, 'newVal' => $newVal), 200); |
|
| 162 | + } |
|
| 163 | + return new JsonResponse(array('success' => false), 200); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + public function checkForNewMessages() |
|
| 167 | + { |
|
| 168 | + $friend_id = $this->request->variable('friend_id', 0); |
|
| 169 | + if ($friend_id > 0) { |
|
| 170 | + $messages = $this->model->getInboxFromId($friend_id); |
|
| 171 | + return new JsonResponse(array('success' => true, 'messages' => $messages), 200); |
|
| 172 | + } |
|
| 173 | + return new JsonResponse(array('success' => false), 200); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + public function getFriends() |
|
| 177 | + { |
|
| 178 | + $friends = $this->model->getFriends(); |
|
| 179 | + $friends_online = array_filter($friends, function ($friend) { |
|
| 180 | + return $friend['user_status'] != 0; |
|
| 181 | + }); |
|
| 182 | + |
|
| 183 | + $response = array( |
|
| 184 | + 'friends_online' => count($friends_online), |
|
| 185 | + 'friends_list' => $friends |
|
| 186 | + ); |
|
| 187 | + |
|
| 188 | + return new JsonResponse($response, 200); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + public function getEmoticons() |
|
| 192 | + { |
|
| 193 | + $emoticons = \florinp\messenger\libs\emojione::$ascii_replace; |
|
| 194 | + $eicons = array(); |
|
| 195 | + foreach ($emoticons as $code => $value) { |
|
| 196 | + $eicons[$value] = $code; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $response = array(); |
|
| 200 | + foreach ($eicons as $emoticon) { |
|
| 201 | + $item = array(); |
|
| 202 | + $item['code'] = $emoticon; |
|
| 203 | + $item['image'] = $this->emojione->toImage($emoticon); |
|
| 204 | + |
|
| 205 | + $response[] = $item; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return new JsonResponse($response, 200); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | } |
@@ -6,108 +6,108 @@ |
||
| 6 | 6 | |
| 7 | 7 | class main_test extends \phpbb_test_case { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * @var \florinp\messenger\controller\main |
|
| 11 | - */ |
|
| 12 | - protected $controller; |
|
| 13 | - |
|
| 14 | - public function setUp() { |
|
| 15 | - parent::setUp(); |
|
| 16 | - /** |
|
| 17 | - * @var \phpbb\user $user Mock the user class |
|
| 18 | - */ |
|
| 19 | - $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var \phpbb\request\request $request |
|
| 23 | - */ |
|
| 24 | - $request = $this->getMockBuilder('\phpbb\request\request') |
|
| 25 | - ->disableOriginalConstructor() |
|
| 26 | - ->getMock(); |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var \florinp\messenger\models\main_model $model |
|
| 30 | - */ |
|
| 31 | - $model = $this->getMockBuilder('\florinp\messenger\models\main_model') |
|
| 32 | - ->disableOriginalConstructor() |
|
| 33 | - ->getMock(); |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var \phpbb\notification\manager $notification_manager |
|
| 37 | - */ |
|
| 38 | - $notification_manager = $this->getMockBuilder('\phpbb\notification\manager') |
|
| 39 | - ->disableOriginalConstructor() |
|
| 40 | - ->getMock(); |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var \florinp\messenger\libs\emojione $emojione |
|
| 44 | - */ |
|
| 45 | - $emojione = $this->getMockBuilder('\florinp\messenger\libs\emojione') |
|
| 46 | - ->disableOriginalConstructor() |
|
| 47 | - ->getMock(); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var \florinp\messenger\libs\upload $upload |
|
| 51 | - */ |
|
| 52 | - $upload = $this->getMockBuilder('\florinp\messenger\libs\upload') |
|
| 53 | - ->disableOriginalConstructor() |
|
| 54 | - ->getMock(); |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var \florinp\messenger\libs\download $download |
|
| 58 | - */ |
|
| 59 | - $download = $this->getMockBuilder('\florinp\messenger\libs\download') |
|
| 60 | - ->disableOriginalConstructor() |
|
| 61 | - ->getMock(); |
|
| 62 | - |
|
| 63 | - $this->controller = new \florinp\messenger\controller\main( |
|
| 64 | - $request, |
|
| 65 | - $user, |
|
| 66 | - $model, |
|
| 67 | - $notification_manager, |
|
| 68 | - $emojione, |
|
| 69 | - $upload, |
|
| 70 | - $download |
|
| 71 | - ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - public function tearDown() { |
|
| 75 | - $this->controller = null; |
|
| 76 | - parent::tearDown(); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function publish_data() { |
|
| 80 | - return array( |
|
| 81 | - array(200, json_encode(array())) |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @dataProvider publish_data |
|
| 87 | - */ |
|
| 88 | - public function test_publish($status_code, $page_content) { |
|
| 89 | - $response = $this->controller->publish(); |
|
| 90 | - $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
| 91 | - $this->assertEquals($status_code, $response->getStatusCode()); |
|
| 92 | - $this->assertEquals($page_content, $response->getContent()); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function load_data() { |
|
| 96 | - return array( |
|
| 97 | - array(200, json_encode(array( |
|
| 98 | - 'success' => false, |
|
| 99 | - 'error' => 'The request is invalid' |
|
| 100 | - ))) |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @dataProvider load_data |
|
| 106 | - */ |
|
| 107 | - public function test_load($status_code, $page_content) { |
|
| 108 | - $response = $this->controller->load(); |
|
| 109 | - $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
| 110 | - $this->assertEquals($status_code, $response->getStatusCode()); |
|
| 111 | - $this->assertEquals($page_content, $response->getContent()); |
|
| 112 | - } |
|
| 9 | + /** |
|
| 10 | + * @var \florinp\messenger\controller\main |
|
| 11 | + */ |
|
| 12 | + protected $controller; |
|
| 13 | + |
|
| 14 | + public function setUp() { |
|
| 15 | + parent::setUp(); |
|
| 16 | + /** |
|
| 17 | + * @var \phpbb\user $user Mock the user class |
|
| 18 | + */ |
|
| 19 | + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var \phpbb\request\request $request |
|
| 23 | + */ |
|
| 24 | + $request = $this->getMockBuilder('\phpbb\request\request') |
|
| 25 | + ->disableOriginalConstructor() |
|
| 26 | + ->getMock(); |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var \florinp\messenger\models\main_model $model |
|
| 30 | + */ |
|
| 31 | + $model = $this->getMockBuilder('\florinp\messenger\models\main_model') |
|
| 32 | + ->disableOriginalConstructor() |
|
| 33 | + ->getMock(); |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var \phpbb\notification\manager $notification_manager |
|
| 37 | + */ |
|
| 38 | + $notification_manager = $this->getMockBuilder('\phpbb\notification\manager') |
|
| 39 | + ->disableOriginalConstructor() |
|
| 40 | + ->getMock(); |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var \florinp\messenger\libs\emojione $emojione |
|
| 44 | + */ |
|
| 45 | + $emojione = $this->getMockBuilder('\florinp\messenger\libs\emojione') |
|
| 46 | + ->disableOriginalConstructor() |
|
| 47 | + ->getMock(); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var \florinp\messenger\libs\upload $upload |
|
| 51 | + */ |
|
| 52 | + $upload = $this->getMockBuilder('\florinp\messenger\libs\upload') |
|
| 53 | + ->disableOriginalConstructor() |
|
| 54 | + ->getMock(); |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var \florinp\messenger\libs\download $download |
|
| 58 | + */ |
|
| 59 | + $download = $this->getMockBuilder('\florinp\messenger\libs\download') |
|
| 60 | + ->disableOriginalConstructor() |
|
| 61 | + ->getMock(); |
|
| 62 | + |
|
| 63 | + $this->controller = new \florinp\messenger\controller\main( |
|
| 64 | + $request, |
|
| 65 | + $user, |
|
| 66 | + $model, |
|
| 67 | + $notification_manager, |
|
| 68 | + $emojione, |
|
| 69 | + $upload, |
|
| 70 | + $download |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + public function tearDown() { |
|
| 75 | + $this->controller = null; |
|
| 76 | + parent::tearDown(); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function publish_data() { |
|
| 80 | + return array( |
|
| 81 | + array(200, json_encode(array())) |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @dataProvider publish_data |
|
| 87 | + */ |
|
| 88 | + public function test_publish($status_code, $page_content) { |
|
| 89 | + $response = $this->controller->publish(); |
|
| 90 | + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
| 91 | + $this->assertEquals($status_code, $response->getStatusCode()); |
|
| 92 | + $this->assertEquals($page_content, $response->getContent()); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function load_data() { |
|
| 96 | + return array( |
|
| 97 | + array(200, json_encode(array( |
|
| 98 | + 'success' => false, |
|
| 99 | + 'error' => 'The request is invalid' |
|
| 100 | + ))) |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @dataProvider load_data |
|
| 106 | + */ |
|
| 107 | + public function test_load($status_code, $page_content) { |
|
| 108 | + $response = $this->controller->load(); |
|
| 109 | + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
| 110 | + $this->assertEquals($status_code, $response->getStatusCode()); |
|
| 111 | + $this->assertEquals($page_content, $response->getContent()); |
|
| 112 | + } |
|
| 113 | 113 | } |
| 114 | 114 | \ No newline at end of file |