-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add model json serialization tests
- Loading branch information
Showing
7 changed files
with
246 additions
and
14 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
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,53 @@ | ||
<?php | ||
|
||
namespace WP\Notifications\Test; | ||
|
||
use WP_UnitTestCase; | ||
use WP\Notifications\Model; | ||
|
||
class Test_Model_Channel extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test channel model. | ||
*/ | ||
private ?Model\Channel $model = null; | ||
|
||
/** | ||
* Set up each test method. | ||
*/ | ||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$this->model = new Model\Channel( | ||
'core/test', | ||
'Test channel', | ||
'test', | ||
'A test case channel', | ||
'WordPress' | ||
); | ||
} | ||
|
||
/** | ||
* Tear down each test method. | ||
*/ | ||
public function tear_down() { | ||
$this->model = null; | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* Should be JSON serializable. | ||
*/ | ||
public function test_json_serializable() { | ||
$actual = json_encode( $this->model, JSON_PRETTY_PRINT ); | ||
$expected = '{ | ||
"context": "test", | ||
"description": "A test case channel", | ||
"icon": "WordPress", | ||
"name": "core\/test", | ||
"title": "Test channel" | ||
}'; | ||
$this->assertEquals( $actual, $expected ); | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
namespace WP\Notifications\Test; | ||
|
||
use WP_UnitTestCase; | ||
use WP\Notifications\Model; | ||
|
||
class Test_Model_Message extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test message model. | ||
*/ | ||
private ?Model\Message $model = null; | ||
|
||
/** | ||
* Set up each test method. | ||
*/ | ||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$this->model = new Model\Message( | ||
'Testing, testings... 1, 2, 3... testing', | ||
'Ok', | ||
null, | ||
'Test channel', | ||
null, | ||
'Nope', | ||
null, | ||
'hammer', | ||
null, | ||
true, | ||
'warning', | ||
'Message model test' | ||
); | ||
} | ||
|
||
/** | ||
* Tear down each test method. | ||
*/ | ||
public function tear_down() { | ||
$this->model = null; | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* Should be JSON serializable. | ||
*/ | ||
public function test_json_serializable() { | ||
$actual = json_encode( $this->model, JSON_PRETTY_PRINT ); | ||
$expected = '{ | ||
"accept_label": "Ok", | ||
"channel_title": "Test channel", | ||
"dismiss_label": "Nope", | ||
"icon": "hammer", | ||
"is_dismissible": true, | ||
"severity": "warning", | ||
"created_at": null, | ||
"expires_at": null, | ||
"id": null, | ||
"message": "Testing, testings... 1, 2, 3... testing", | ||
"title": "Message model test" | ||
}'; | ||
$this->assertEquals( $actual, $expected ); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
namespace WP\Notifications\Test; | ||
|
||
use DateTime; | ||
use WP_UnitTestCase; | ||
use WP\Notifications\Model; | ||
|
||
class Test_Model_Notification extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test message model. | ||
*/ | ||
private ?Model\Notification $model = null; | ||
|
||
/** | ||
* Set up each test method. | ||
*/ | ||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$this->model = new Model\Notification( | ||
'core/test', | ||
1, | ||
1, | ||
'adminbar', | ||
null, | ||
null, | ||
null, | ||
new DateTime( '2023-12-31' ) | ||
); | ||
} | ||
|
||
/** | ||
* Tear down each test method. | ||
*/ | ||
public function tear_down() { | ||
$this->model = null; | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* Should be JSON serializable. | ||
*/ | ||
public function test_json_serializable() { | ||
$actual = json_encode( $this->model, JSON_PRETTY_PRINT ); | ||
$expected = '{ | ||
"channel_name": "core\/test", | ||
"context": "adminbar", | ||
"created_at": null, | ||
"dismissed_at": null, | ||
"displayed_at": null, | ||
"expires_at": "2023-12-31T00:00:00+00:00", | ||
"message_id": 1, | ||
"user_id": 1 | ||
}'; | ||
$this->assertEquals( $actual, $expected ); | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
namespace WP\Notifications\Test; | ||
|
||
use DateTime; | ||
use WP_UnitTestCase; | ||
use WP\Notifications\Model; | ||
|
||
class Test_Model_Subscription extends WP_UnitTestCase { | ||
|
||
/** | ||
* Test message model. | ||
*/ | ||
private ?Model\Subscription $model = null; | ||
|
||
/** | ||
* Set up each test method. | ||
*/ | ||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$this->model = new Model\Subscription( | ||
'core/test', | ||
1, | ||
null, | ||
new DateTime( '2023-12-31' ) | ||
); | ||
} | ||
|
||
/** | ||
* Tear down each test method. | ||
*/ | ||
public function tear_down() { | ||
$this->model = null; | ||
|
||
parent::tear_down(); | ||
} | ||
|
||
/** | ||
* Should be JSON serializable. | ||
*/ | ||
public function test_json_serializable() { | ||
$actual = json_encode( $this->model, JSON_PRETTY_PRINT ); | ||
$expected = '{ | ||
"channel_name": "core\/test", | ||
"created_at": null, | ||
"snoozed_until": "2023-12-31T00:00:00+00:00", | ||
"user_id": 1 | ||
}'; | ||
$this->assertEquals( $actual, $expected ); | ||
} | ||
} |