ZoneCacheTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. class ZoneCacheTest extends TestCase
  3. {
  4. public function testCachePurgeEverything()
  5. {
  6. $response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeEverything.json');
  7. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  8. $mock->method('post')->willReturn($response);
  9. $mock->expects($this->once())
  10. ->method('post')
  11. ->with(
  12. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
  13. $this->equalTo(['purge_everything' => true])
  14. );
  15. $zones = new \Cloudflare\API\Endpoints\Zones($mock);
  16. $result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
  17. $this->assertTrue($result);
  18. $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
  19. }
  20. public function testCachePurgeHost()
  21. {
  22. $response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
  23. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  24. $mock->method('post')->willReturn($response);
  25. $mock->expects($this->once())
  26. ->method('post')
  27. ->with(
  28. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
  29. $this->equalTo(
  30. [
  31. 'files' => [],
  32. 'tags' => [],
  33. 'hosts' => ['dash.cloudflare.com']
  34. ]
  35. )
  36. );
  37. $zones = new \Cloudflare\API\Endpoints\Zones($mock);
  38. $result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
  39. $this->assertTrue($result);
  40. $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
  41. }
  42. public function testCachePurge()
  43. {
  44. $response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurge.json');
  45. $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
  46. $mock->method('post')->willReturn($response);
  47. $mock->expects($this->once())
  48. ->method('post')
  49. ->with(
  50. $this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
  51. $this->equalTo(['files' => [
  52. 'https://example.com/file.jpg',
  53. ]
  54. ])
  55. );
  56. $zones = new \Cloudflare\API\Endpoints\Zones($mock);
  57. $result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [
  58. 'https://example.com/file.jpg',
  59. ]);
  60. $this->assertTrue($result);
  61. $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $zones->getBody()->result->id);
  62. }
  63. }