|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Created by PhpStorm. |
| 4 | + * User: junade |
| 5 | + * Date: 18/03/2018 |
| 6 | + * Time: 22:23 |
| 7 | + */ |
| 8 | + |
| 9 | +use Cloudflare\API\Endpoints\CustomHostnames; |
| 10 | + |
| 11 | +class CustomHostnamesTest extends TestCase |
| 12 | +{ |
| 13 | + public function testAddHostname() |
| 14 | + { |
| 15 | + $response = $this->getPsr7JsonResponseForFixture('Endpoints/createCustomHostname.json'); |
| 16 | + |
| 17 | + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); |
| 18 | + $mock->method('post')->willReturn($response); |
| 19 | + |
| 20 | + $mock->expects($this->once()) |
| 21 | + ->method('post') |
| 22 | + ->with( |
| 23 | + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'), |
| 24 | + $this->equalTo([]), |
| 25 | + $this->equalTo([ |
| 26 | + 'hostname' => 'app.example.com', |
| 27 | + 'ssl' => (object)[ |
| 28 | + 'method' => 'http', |
| 29 | + 'type' => 'dv' |
| 30 | + ] |
| 31 | + ]) |
| 32 | + ); |
| 33 | + |
| 34 | + $hostname = new CustomHostnames($mock); |
| 35 | + $hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv'); |
| 36 | + } |
| 37 | + |
| 38 | + public function testListHostnames() |
| 39 | + { |
| 40 | + $response = $this->getPsr7JsonResponseForFixture('Endpoints/listHostnames.json'); |
| 41 | + |
| 42 | + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); |
| 43 | + $mock->method('get')->willReturn($response); |
| 44 | + |
| 45 | + $mock->expects($this->once()) |
| 46 | + ->method('get') |
| 47 | + ->with( |
| 48 | + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'), |
| 49 | + $this->equalTo([ |
| 50 | + 'hostname' => 'app.example.com', |
| 51 | + 'id' => '0d89c70d-ad9f-4843-b99f-6cc0252067e9', |
| 52 | + 'page' => 1, |
| 53 | + 'per_page' => 20, |
| 54 | + 'order' => 'ssl', |
| 55 | + 'direction' => 'desc', |
| 56 | + 'ssl' => 0 |
| 57 | + ]), |
| 58 | + $this->equalTo([]) |
| 59 | + ); |
| 60 | + |
| 61 | + $zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock); |
| 62 | + $result = $zones->listHostnames('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 1, 20, 'ssl', 'desc', 0); |
| 63 | + |
| 64 | + $this->assertObjectHasAttribute('result', $result); |
| 65 | + $this->assertObjectHasAttribute('result_info', $result); |
| 66 | + |
| 67 | + $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->result[0]->id); |
| 68 | + $this->assertEquals(1, $result->result_info->page); |
| 69 | + } |
| 70 | + |
| 71 | + public function testGetHostname() |
| 72 | + { |
| 73 | + $response = $this->getPsr7JsonResponseForFixture('Endpoints/getHostname.json'); |
| 74 | + |
| 75 | + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); |
| 76 | + $mock->method('get')->willReturn($response); |
| 77 | + |
| 78 | + $mock->expects($this->once()) |
| 79 | + ->method('get') |
| 80 | + ->with( |
| 81 | + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'), |
| 82 | + $this->equalTo([]), |
| 83 | + $this->equalTo([]) |
| 84 | + ); |
| 85 | + |
| 86 | + $zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock); |
| 87 | + $result = $zones->getHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', '0d89c70d-ad9f-4843-b99f-6cc0252067e9'); |
| 88 | + |
| 89 | + $this->assertObjectHasAttribute('id', $result); |
| 90 | + $this->assertObjectHasAttribute('hostname', $result); |
| 91 | + } |
| 92 | + |
| 93 | + public function testUpdateHostname() |
| 94 | + { |
| 95 | + $response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHostname.json'); |
| 96 | + |
| 97 | + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); |
| 98 | + $mock->method('patch')->willReturn($response); |
| 99 | + |
| 100 | + $mock->expects($this->once()) |
| 101 | + ->method('patch') |
| 102 | + ->with( |
| 103 | + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'), |
| 104 | + $this->equalTo([]), |
| 105 | + $this->equalTo([ |
| 106 | + 'ssl' => (object)[ |
| 107 | + 'method' => 'http', |
| 108 | + 'type' => 'dv' |
| 109 | + ] |
| 110 | + ]) |
| 111 | + ); |
| 112 | + |
| 113 | + $zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock); |
| 114 | + $result = $zones->updateHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 'http', 'dv'); |
| 115 | + |
| 116 | + $this->assertObjectHasAttribute('id', $result); |
| 117 | + $this->assertObjectHasAttribute('hostname', $result); |
| 118 | + } |
| 119 | + |
| 120 | + public function testDeleteHostname() |
| 121 | + { |
| 122 | + $response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteHostname.json'); |
| 123 | + |
| 124 | + $mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock(); |
| 125 | + $mock->method('delete')->willReturn($response); |
| 126 | + |
| 127 | + $mock->expects($this->once()) |
| 128 | + ->method('delete') |
| 129 | + ->with( |
| 130 | + $this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'), |
| 131 | + $this->equalTo([]), |
| 132 | + $this->equalTo([]) |
| 133 | + ); |
| 134 | + |
| 135 | + $zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock); |
| 136 | + $result = $zones->deleteHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9'); |
| 137 | + |
| 138 | + $this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->id); |
| 139 | + } |
| 140 | +} |
0 commit comments