| Server IP : 104.21.1.144 / Your IP : 104.23.243.197 Web Server : nginx/1.26.1 System : Linux HE9229 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/11ph_ph_com/wp-content/plugins/cloudflare/src/Test/API/ |
Upload File : |
<?php
namespace CF\API\Test;
use CF\API\Host;
use CF\API\Request;
use CF\Integration\DefaultIntegration;
class HostTest extends \PHPUnit\Framework\TestCase
{
private $hostAPI;
private $mockConfig;
private $mockAPI;
private $mockDataStore;
private $mockLogger;
private $mockCpanelIntegration;
public function setup(): void
{
$this->mockConfig = $this->getMockBuilder('CF\Integration\DefaultConfig')
->disableOriginalConstructor()
->getMock();
$this->mockAPI = $this->getMockBuilder('CF\Integration\IntegrationAPIInterface')
->disableOriginalConstructor()
->getMock();
$this->mockDataStore = $this->getMockBuilder('CF\Integration\DataStoreInterface')
->disableOriginalConstructor()
->getMock();
$this->mockLogger = $this->getMockBuilder('CF\Integration\DefaultLogger')
->disableOriginalConstructor()
->getMock();
$this->mockCpanelIntegration = new DefaultIntegration($this->mockConfig, $this->mockAPI, $this->mockDataStore, $this->mockLogger);
$this->hostAPI = new Host($this->mockCpanelIntegration);
}
public function testBeforeSendSetsCorrectPath()
{
$request = new Request(null, null, null, null);
$request = $this->hostAPI->beforeSend($request);
$this->assertEquals(Host::ENDPOINT_PATH, $request->getUrl());
}
public function testBeforeSendSetsIntegrationHeaders()
{
$integrationName = 'integrationName';
$version = 'version';
$this->mockConfig->method('getValue')->will(
$this->returnValueMap(
array(
array($integrationName, $integrationName),
array($version, $version),
)
)
);
$request = new Request(null, null, null, null);
$request = $this->hostAPI->beforeSend($request);
$requestHeaders = $request->getHeaders();
$this->assertEquals($integrationName, $requestHeaders[Host::CF_INTEGRATION_HEADER]);
$this->assertEquals($version, $requestHeaders[Host::CF_INTEGRTATION_VERSION_HEADER]);
}
public function testBeforeSendSetsUserKeyforActZoneSet()
{
$userKey = 'userKey';
$this->mockDataStore->method('getHostAPIUserKey')->willReturn($userKey);
$request = new Request(null, null, null, array('act' => 'zone_set'));
$request = $this->hostAPI->beforeSend($request);
$requestBody = $request->getBody();
$this->assertEquals($userKey, $requestBody['user_key']);
}
public function testBeforeSendSetsUserKeyforActFullZoneSet()
{
$userKey = 'userKey';
$this->mockDataStore->method('getHostAPIUserKey')->willReturn($userKey);
$request = new Request(null, null, null, array('act' => 'full_zone_set'));
$request = $this->hostAPI->beforeSend($request);
$requestBody = $request->getBody();
$this->assertEquals($userKey, $requestBody['user_key']);
}
public function testBeforeSendSetsHostKey()
{
$hostKey = 'hostKey';
$this->mockAPI->method('getHostAPIKey')->willReturn($hostKey);
$request = new Request(null, null, null, null);
$request = $this->hostAPI->beforeSend($request);
$requestBody = $request->getBody();
$this->assertEquals($hostKey, $requestBody['host_key']);
}
public function testResponseOkReturnsTrueForValidResponse()
{
$hostAPIResponse = array(
'result' => 'success',
);
$this->assertTrue($this->hostAPI->responseOk($hostAPIResponse));
}
public function testClientApiErrorReturnsValidStructure()
{
$message = 'message';
$errorResponse = $this->hostAPI->createAPIError($message);
$this->assertEquals($message, $errorResponse['msg']);
$this->assertEquals('error', $errorResponse['result']);
}
public function testGetPathReturnsBodyActParameter()
{
$act = 'act';
$request = new Request(null, null, null, array($act => $act));
$this->assertEquals($act, $this->hostAPI->getPath($request));
}
public function testShouldRouteRequestReturnsTrueIfUrlsAreEqual()
{
$request = new Request(null, Host::ENDPOINT, null, null);
$this->assertTrue($this->hostAPI->shouldRouteRequest($request));
}
}