|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2018 Ross Mitchell |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of RossMitchell/UpdateCloudFlare. |
|
8
|
|
|
* |
|
9
|
|
|
* RossMitchell/UpdateCloudFlare is free software: you can redistribute |
|
10
|
|
|
* it and/or modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace RossMitchell\UpdateCloudFlare\Tests\Requests; |
|
24
|
|
|
|
|
25
|
|
|
use RossMitchell\UpdateCloudFlare\Data\IpType; |
|
26
|
|
|
use RossMitchell\UpdateCloudFlare\Data\SubDomainInfo; |
|
27
|
|
|
use RossMitchell\UpdateCloudFlare\Factories\Data\SubDomainInfoFactory; |
|
28
|
|
|
use RossMitchell\UpdateCloudFlare\Factories\Requests\UpdateDnsRecordFactory; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Class UpdateDnsRecordTest |
|
32
|
|
|
* @testdox RossMitchell\UpdateCloudFlare\Model\Requests\UpdateDnsRecord |
|
33
|
|
|
* @package RossMitchell\UpdateCloudFlare\Tests\Requests |
|
34
|
|
|
*/ |
|
35
|
|
|
class UpdateDnsRecordTest extends AbstractRequest |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @Inject |
|
39
|
|
|
* @var UpdateDnsRecordFactory |
|
40
|
|
|
*/ |
|
41
|
|
|
private $factory; |
|
42
|
|
|
/** |
|
43
|
|
|
* @Inject |
|
44
|
|
|
* @var SubDomainInfoFactory |
|
45
|
|
|
*/ |
|
46
|
|
|
private $subDomainFactory; |
|
47
|
|
|
/** |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
private $subDomain = 'www'; |
|
51
|
|
|
/** |
|
52
|
|
|
* @var string |
|
53
|
|
|
*/ |
|
54
|
|
|
private $subDomainId = '98765'; |
|
55
|
|
|
/** |
|
56
|
|
|
* @var string |
|
57
|
|
|
*/ |
|
58
|
|
|
private $type = IpType::IP_V4; |
|
59
|
|
|
/** |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
private $zoneId = '12345'; |
|
63
|
|
|
/** |
|
64
|
|
|
* @var string |
|
65
|
|
|
*/ |
|
66
|
|
|
private $ipAddress = '9.8.7.6'; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return mixed |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getRequest() |
|
72
|
|
|
{ |
|
73
|
|
|
$subDomain = $this->subDomainFactory->create($this->subDomain, $this->type); |
|
74
|
|
|
$subDomain->setSubDomainId($this->subDomainId); |
|
75
|
|
|
$subDomain->setIpAddress($this->ipAddress); |
|
76
|
|
|
$subDomain->setZoneId($this->zoneId); |
|
77
|
|
|
|
|
78
|
|
|
return $this->factory->create($subDomain); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return array |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getHeaders(): array |
|
85
|
|
|
{ |
|
86
|
|
|
return [ |
|
87
|
|
|
'X-Auth-Email: [email protected]', |
|
88
|
|
|
'X-Auth-Key: 123456789', |
|
89
|
|
|
'Content-Type: application/json', |
|
90
|
|
|
]; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return string |
|
95
|
|
|
*/ |
|
96
|
|
|
public function getRequestType(): string |
|
97
|
|
|
{ |
|
98
|
|
|
return 'PUT'; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return array |
|
103
|
|
|
*/ |
|
104
|
|
|
public function getFields(): array |
|
105
|
|
|
{ |
|
106
|
|
|
return [ |
|
107
|
|
|
'type' => $this->type, |
|
108
|
|
|
'name' => $this->subDomain . '.example.com', |
|
109
|
|
|
'content' => $this->ipAddress, |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getUrl(): string |
|
117
|
|
|
{ |
|
118
|
|
|
$zoneId = $this->zoneId; |
|
119
|
|
|
$subDomainId = $this->subDomainId; |
|
120
|
|
|
|
|
121
|
|
|
return "https://api.cloudflare.com/client/v4/zones/${zoneId}/dns_records/${subDomainId}"; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @test |
|
126
|
|
|
*/ |
|
127
|
|
|
public function itCanReturnTheSubDomainInfo(): void |
|
128
|
|
|
{ |
|
129
|
|
|
$request = $this->getRequest(); |
|
130
|
|
|
$this->assertInstanceOf(SubDomainInfo::class, $request->getSubDomainInfo()); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|