-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Subscription::create when not giving every keys (#163)
- Loading branch information
1 parent
74bc0ac
commit 5c2d2a5
Showing
2 changed files
with
101 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
use Minishlink\WebPush\Subscription; | ||
|
||
class SubscriptionTest extends PHPUnit\Framework\TestCase | ||
{ | ||
|
||
public function testCreateMinimal() | ||
{ | ||
$subscriptionArray = array( | ||
"endpoint" => "http://toto.com" | ||
); | ||
$subscription = Subscription::create($subscriptionArray); | ||
$this->assertEquals("http://toto.com", $subscription->getEndpoint()); | ||
$this->assertEquals(null, $subscription->getPublicKey()); | ||
$this->assertEquals(null, $subscription->getAuthToken()); | ||
$this->assertEquals(null, $subscription->getContentEncoding()); | ||
} | ||
|
||
public function testConstructMinimal() | ||
{ | ||
$subscription = new Subscription("http://toto.com"); | ||
$this->assertEquals("http://toto.com", $subscription->getEndpoint()); | ||
$this->assertEquals(null, $subscription->getPublicKey()); | ||
$this->assertEquals(null, $subscription->getAuthToken()); | ||
$this->assertEquals(null, $subscription->getContentEncoding()); | ||
} | ||
|
||
public function testCreatePartial() | ||
{ | ||
$subscriptionArray = array( | ||
"endpoint" => "http://toto.com", | ||
"publicKey" => "publicKey", | ||
"authToken" => "authToken", | ||
); | ||
$subscription = Subscription::create($subscriptionArray); | ||
$this->assertEquals("http://toto.com", $subscription->getEndpoint()); | ||
$this->assertEquals("publicKey", $subscription->getPublicKey()); | ||
$this->assertEquals("authToken", $subscription->getAuthToken()); | ||
$this->assertEquals("aesgcm", $subscription->getContentEncoding()); | ||
} | ||
|
||
public function testConstructPartial() | ||
{ | ||
$subscription = new Subscription("http://toto.com", "publicKey", "authToken"); | ||
$this->assertEquals("http://toto.com", $subscription->getEndpoint()); | ||
$this->assertEquals("publicKey", $subscription->getPublicKey()); | ||
$this->assertEquals("authToken", $subscription->getAuthToken()); | ||
$this->assertEquals("aesgcm", $subscription->getContentEncoding()); | ||
} | ||
|
||
public function testCreateFull() | ||
{ | ||
$subscriptionArray = array( | ||
"endpoint" => "http://toto.com", | ||
"publicKey" => "publicKey", | ||
"authToken" => "authToken", | ||
"contentEncoding" => "aes128gcm", | ||
); | ||
$subscription = Subscription::create($subscriptionArray); | ||
$this->assertEquals("http://toto.com", $subscription->getEndpoint()); | ||
$this->assertEquals("publicKey", $subscription->getPublicKey()); | ||
$this->assertEquals("authToken", $subscription->getAuthToken()); | ||
$this->assertEquals("aes128gcm", $subscription->getContentEncoding()); | ||
} | ||
|
||
public function testConstructFull() | ||
{ | ||
$subscription = new Subscription("http://toto.com", "publicKey", "authToken", "aes128gcm"); | ||
$this->assertEquals("http://toto.com", $subscription->getEndpoint()); | ||
$this->assertEquals("publicKey", $subscription->getPublicKey()); | ||
$this->assertEquals("authToken", $subscription->getAuthToken()); | ||
$this->assertEquals("aes128gcm", $subscription->getContentEncoding()); | ||
} | ||
} |