forked from laravel-notification-channels/onesignal
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
232 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace NotificationChannels\OneSignal\Test; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Mockery; | ||
use Berkayk\OneSignal\OneSignalClient; | ||
use NotificationChannels\OneSignal\Exceptions\CouldNotSendNotification; | ||
use NotificationChannels\OneSignal\OneSignalChannel; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class ChannelTest extends TestCase | ||
{ | ||
/** @var Mockery\Mock */ | ||
protected $oneSignal; | ||
|
||
/** @var \NotificationChannels\OneSignal\OneSignalChannel */ | ||
protected $channel; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->oneSignal = Mockery::mock(OneSignalClient::class); | ||
|
||
$this->channel = new OneSignalChannel($this->oneSignal); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
Mockery::close(); | ||
parent::tearDown(); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_send_a_notification() | ||
{ | ||
$response = new Response(200); | ||
|
||
$this->oneSignal->shouldReceive('sendNotificationCustom') | ||
->once() | ||
->with([ | ||
'contents' => ['en' => 'Body'], | ||
'headings' => ['en' => 'Subject'], | ||
'url' => 'URL', | ||
'buttons' => [], | ||
'web_buttons' => [], | ||
'chrome_web_icon' => 'Icon', | ||
'chrome_icon' => 'Icon', | ||
'adm_small_icon' => 'Icon', | ||
'small_icon' => 'Icon', | ||
'include_player_ids' => collect('player_id') | ||
]) | ||
->andReturn($response); | ||
|
||
$this->channel->send(new Notifiable(), new TestNotification()); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_an_exception_when_it_could_not_send_the_notification() | ||
{ | ||
$response = new Response(500,[],'ResponseBody'); | ||
|
||
$this->oneSignal->shouldReceive('sendNotificationCustom') | ||
->once() | ||
->with([ | ||
'contents' => ['en' => 'Body'], | ||
'headings' => ['en' => 'Subject'], | ||
'url' => 'URL', | ||
'buttons' => [], | ||
'web_buttons' => [], | ||
'chrome_web_icon' => 'Icon', | ||
'chrome_icon' => 'Icon', | ||
'adm_small_icon' => 'Icon', | ||
'small_icon' => 'Icon', | ||
'include_player_ids' => collect('player_id') | ||
]) | ||
->andReturn($response); | ||
|
||
$this->setExpectedException(CouldNotSendNotification::class); | ||
|
||
$this->channel->send(new Notifiable(), new TestNotification()); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace NotificationChannels\OneSignal\Test; | ||
|
||
use Illuminate\Support\Arr; | ||
use NotificationChannels\OneSignal\OneSignalButton; | ||
use NotificationChannels\OneSignal\OneSignalMessage; | ||
use NotificationChannels\OneSignal\OneSignalWebButton; | ||
|
||
class MessageTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var \NotificationChannels\OneSignal\OneSignalMessage */ | ||
protected $message; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->message = new OneSignalMessage(); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_accept_a_message_when_constructing_a_message() | ||
{ | ||
$message = new OneSignalMessage('Message body'); | ||
|
||
$this->assertEquals('Message body', Arr::get($message->toArray(), 'contents.en')); | ||
} | ||
|
||
/** @test */ | ||
public function it_provides_a_create_method() | ||
{ | ||
$message = OneSignalMessage::create('Message body'); | ||
|
||
$this->assertEquals('Message body', Arr::get($message->toArray(), 'contents.en')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_the_body() | ||
{ | ||
$this->message->body('myBody'); | ||
|
||
$this->assertEquals('myBody', Arr::get($this->message->toArray(), 'contents.en')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_the_subject() | ||
{ | ||
$this->message->subject('mySubject'); | ||
|
||
$this->assertEquals('mySubject', Arr::get($this->message->toArray(), 'headings.en')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_the_url() | ||
{ | ||
$this->message->url('myURL'); | ||
|
||
$this->assertEquals('myURL', Arr::get($this->message->toArray(), 'url')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_additional_data() | ||
{ | ||
$this->message->setData('key_one', 'value_one'); | ||
$this->message->setData('key_two', 'value_two'); | ||
|
||
$this->assertEquals('value_one', Arr::get($this->message->toArray(), 'data.key_one')); | ||
$this->assertEquals('value_two', Arr::get($this->message->toArray(), 'data.key_two')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_the_icon() | ||
{ | ||
$this->message->icon('myIcon'); | ||
|
||
$this->assertEquals('myIcon', Arr::get($this->message->toArray(), 'chrome_web_icon')); | ||
$this->assertEquals('myIcon', Arr::get($this->message->toArray(), 'chrome_icon')); | ||
$this->assertEquals('myIcon', Arr::get($this->message->toArray(), 'adm_small_icon')); | ||
$this->assertEquals('myIcon', Arr::get($this->message->toArray(), 'small_icon')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_a_web_button() | ||
{ | ||
$this->message->webButton( | ||
OneSignalWebButton::create('buttonID') | ||
->text('buttonText') | ||
->url('buttonURL') | ||
->icon('buttonIcon') | ||
); | ||
|
||
$this->assertEquals('buttonID', Arr::get($this->message->toArray(), 'web_buttons.0.id')); | ||
$this->assertEquals('buttonText', Arr::get($this->message->toArray(), 'web_buttons.0.text')); | ||
$this->assertEquals('buttonURL', Arr::get($this->message->toArray(), 'web_buttons.0.url')); | ||
$this->assertEquals('buttonIcon', Arr::get($this->message->toArray(), 'web_buttons.0.icon')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_a_button() | ||
{ | ||
$this->message->button( | ||
OneSignalButton::create('buttonID') | ||
->text('buttonText') | ||
->icon('buttonIcon') | ||
); | ||
|
||
$this->assertEquals('buttonID', Arr::get($this->message->toArray(), 'buttons.0.id')); | ||
$this->assertEquals('buttonText', Arr::get($this->message->toArray(), 'buttons.0.text')); | ||
$this->assertEquals('buttonIcon', Arr::get($this->message->toArray(), 'buttons.0.icon')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace NotificationChannels\OneSignal\Test; | ||
|
||
class Notifiable | ||
{ | ||
use \Illuminate\Notifications\Notifiable; | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function routeNotificationForOneSignal() | ||
{ | ||
return 'player_id'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace NotificationChannels\OneSignal\Test; | ||
|
||
use Illuminate\Notifications\Notification; | ||
use NotificationChannels\OneSignal\OneSignalMessage; | ||
|
||
class TestNotification extends Notification | ||
{ | ||
public function toOneSignal($notifiable) | ||
{ | ||
return (new OneSignalMessage('Body')) | ||
->subject('Subject') | ||
->icon('Icon') | ||
->url('URL'); | ||
} | ||
} |