| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Test\Unit; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Notifications\Push\Subscription; |
| 6 |
use MediaWikiUnitTestCase; |
| 7 |
use Wikimedia\Timestamp\ConvertibleTimestamp; |
| 8 |
|
| 9 |
|
| 10 |
class SubscriptionTest extends MediaWikiUnitTestCase { |
| 11 |
|
| 12 |
public function testNewFromRow(): void { |
| 13 |
$row = (object)[ |
| 14 |
'eps_token' => 'AABC123', |
| 15 |
'epp_name' => 'fcm', |
| 16 |
'eps_data' => null, |
| 17 |
'ept_text' => null, |
| 18 |
'eps_updated' => '2020-01-01 10:10:10', |
| 19 |
]; |
| 20 |
|
| 21 |
$subscription = Subscription::newFromRow( $row ); |
| 22 |
$this->assertSame( 'AABC123', $subscription->getToken() ); |
| 23 |
$this->assertSame( 'fcm', $subscription->getProvider() ); |
| 24 |
$this->assertNull( $subscription->getTopic() ); |
| 25 |
$this->assertInstanceOf( ConvertibleTimestamp::class, $subscription->getUpdated() ); |
| 26 |
$this->assertSame( '1577873410', $subscription->getUpdated()->getTimestamp() ); |
| 27 |
} |
| 28 |
|
| 29 |
public function testNewFromRowWithTopic(): void { |
| 30 |
$row = (object)[ |
| 31 |
'eps_token' => 'DEF456', |
| 32 |
'epp_name' => 'apns', |
| 33 |
'eps_data' => null, |
| 34 |
'ept_text' => 'test', |
| 35 |
'eps_updated' => '2020-01-01 10:10:10', |
| 36 |
]; |
| 37 |
|
| 38 |
$subscription = Subscription::newFromRow( $row ); |
| 39 |
$this->assertSame( 'DEF456', $subscription->getToken() ); |
| 40 |
$this->assertSame( 'apns', $subscription->getProvider() ); |
| 41 |
$this->assertSame( 'test', $subscription->getTopic() ); |
| 42 |
$this->assertInstanceOf( ConvertibleTimestamp::class, $subscription->getUpdated() ); |
| 43 |
$this->assertSame( '1577873410', $subscription->getUpdated()->getTimestamp() ); |
| 44 |
} |
| 45 |
|
| 46 |
} |