| Server IP : 104.21.1.144 / Your IP : 104.23.197.96 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\Client;
use CF\Integration\DefaultIntegration;
class ClientTest extends \PHPUnit\Framework\TestCase
{
private $mockConfig;
private $mockClientAPI;
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')
->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->mockClientAPI = new Client($this->mockCpanelIntegration);
}
public function testBeforeSendAddsRequestHeaders()
{
$apiKey = '41db178adf2ef1c82c84db6ca455457646d33';
$email = '[email protected]';
$this->mockDataStore->method('getClientV4APIKey')->willReturn($apiKey);
$this->mockDataStore->method('getCloudFlareEmail')->willReturn($email);
$request = new \CF\API\Request(null, null, null, null);
$beforeSendRequest = $this->mockClientAPI->beforeSend($request);
$actualRequestHeaders = $beforeSendRequest->getHeaders();
$expectedRequestHeaders = array(
Client::X_AUTH_KEY => $apiKey,
Client::X_AUTH_EMAIL => $email,
Client::CONTENT_TYPE_KEY => Client::APPLICATION_JSON_KEY,
);
$this->assertEquals($expectedRequestHeaders[Client::X_AUTH_KEY], $actualRequestHeaders[Client::X_AUTH_KEY]);
$this->assertEquals($expectedRequestHeaders[Client::X_AUTH_EMAIL], $actualRequestHeaders[Client::X_AUTH_EMAIL]);
$this->assertEquals($expectedRequestHeaders[Client::CONTENT_TYPE_KEY], $actualRequestHeaders[Client::CONTENT_TYPE_KEY]);
}
public function testClientApiErrorReturnsValidStructure()
{
$expectedErrorResponse = array(
'result' => null,
'success' => false,
'errors' => array(
array(
'code' => '',
'message' => 'Test Message',
),
),
'messages' => array(),
);
$errorResponse = $this->mockClientAPI->createAPIError('Test Message');
$this->assertEquals($errorResponse, $expectedErrorResponse);
}
public function testResponseOkReturnsTrueForValidResponse()
{
$v4APIResponse = array(
'success' => true,
);
$this->assertTrue($this->mockClientAPI->responseOk($v4APIResponse));
}
public function testGetErrorMessageSuccess()
{
$errorMessage = 'I am an error message';
$error = $this->getMockBuilder('\Guzzle\Http\Exception\BadResponseException')
->disableOriginalConstructor()
->setMethods(array('getResponse', 'getBody', 'getMessage'))
->getMock();
$errorJSON = json_encode(
array(
'success' => false,
'errors' => array(
array(
'message' => $errorMessage,
),
),
)
);
$error->expects($this->any())
->method('getMessage')
->will($this->returnValue('Not this message'));
$error->expects($this->any())
->method('getResponse')
->will($this->returnSelf());
$error->expects($this->any())
->method('getBody')
->will($this->returnValue($errorJSON));
$this->assertEquals($errorMessage, $this->mockClientAPI->getErrorMessage($error));
}
}