You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. namespace p3k\WebSub\Tests;
  3. use PHPUnit\Framework\TestCase;
  4. use p3k\WebSub\Client;
  5. class SubscribeTest extends TestCase {
  6. public function testSubscribePostsFormEncodedRequest() {
  7. $http = new FakeHTTP(['POST' => ['code' => 202]]);
  8. $client = new Client($http);
  9. $response = $client->subscribe('https://hub.example/', 'https://example.com/feed', 'https://reader.example/callback');
  10. $this->assertSame(202, $response['code']);
  11. $this->assertCount(1, $http->requests);
  12. $this->assertSame('https://hub.example/', $http->requests[0]['url']);
  13. parse_str($http->requests[0]['body'], $params);
  14. $this->assertSame([
  15. 'hub_mode' => 'subscribe',
  16. 'hub_topic' => 'https://example.com/feed',
  17. 'hub_callback' => 'https://reader.example/callback',
  18. ], $params);
  19. $this->assertStringContainsString('hub.mode=subscribe', $http->requests[0]['body']);
  20. }
  21. public function testSubscribeIncludesLeaseSecondsAndSecret() {
  22. $http = new FakeHTTP();
  23. $client = new Client($http);
  24. $client->subscribe('https://hub.example/', 'https://example.com/feed', 'https://reader.example/callback', [
  25. 'lease_seconds' => 86400,
  26. 'secret' => 's3cret',
  27. ]);
  28. $body = $http->requests[0]['body'];
  29. $this->assertStringContainsString('hub.lease_seconds=86400', $body);
  30. $this->assertStringContainsString('hub.secret=s3cret', $body);
  31. }
  32. public function testUnsubscribePostsFormEncodedRequest() {
  33. $http = new FakeHTTP();
  34. $client = new Client($http);
  35. $client->unsubscribe('https://hub.example/', 'https://example.com/feed', 'https://reader.example/callback');
  36. $this->assertSame('https://hub.example/', $http->requests[0]['url']);
  37. $this->assertSame(
  38. 'hub.mode=unsubscribe&hub.topic=https%3A%2F%2Fexample.com%2Ffeed&hub.callback=https%3A%2F%2Freader.example%2Fcallback',
  39. $http->requests[0]['body']
  40. );
  41. }
  42. }