<commit_before><?php

namespace RcmInstanceConfigTest\Controller;

require_once __DIR__ . '/../../../../../Rcm/test/Base/BaseTestCase.php';
require_once __DIR__ . '/../Mock/PluginStorageMgrMock.php';

use RcmInstanceConfig\Controller\BasePluginController;
use RcmInstanceConfig\Service\PluginStorageMgrMock;
use RcmTest\Base\BaseTestCase;
use Zend\Http\PhpEnvironment\Request;

class BasePluginControllerTest extends BaseTestCase
{

    /** @var  \RcmInstanceConfig\Controller\BasePluginController */
    protected $basePluginController;

    const DEFAULT_HTML = '<h1>hello</h1>';

    /**
     * @var \RcmInstanceConfig\Service\PluginStorageMgrMock
     */
    protected $pluginStorageMgrMock;

    public function setUp()
    {
        $this->addModule('RcmInstanceConfig');
        parent::setUp();

        $this->pluginStorageMgrMock = new PluginStorageMgrMock(
            array('html' => self::DEFAULT_HTML)
        );

        $this->basePluginController = new BasePluginController(
            $this->pluginStorageMgrMock,
            array(
                'rcmPlugin' => array(
                    'RcmInstanceConfig' => array(
                        'defaultInstanceConfig' => array(
                            'html' => self::DEFAULT_HTML
                        )
                    )
                )
            )
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testSetGetRequest()
    {
        $request = new Request();
        $this->basePluginController->setRequest(new Request());
        $this->assertEquals(
            $request, $this->basePluginController->getRequest()
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testRenderInstance()
    {
        $personName = 'bob';
        $viewModel = $this->basePluginController->renderInstance(
            1,
            array('personName' => $personName)
        );
        $this->assertInstanceOf('\Zend\View\Model\ViewModel', $viewModel);
        $this->assertEquals(
            $viewModel->getVariable('personName'),
            $personName
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testRenderDefaultInstance()
    {
        $personName = 'bob';
        $viewModel = $this->basePluginController->renderDefaultInstance(
            -1,
            array('personName' => $personName)
        );
        $this->assertInstanceOf('\Zend\View\Model\ViewModel', $viewModel);
        $this->assertEquals(
            $viewModel->getVariable('personName'),
            $personName
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testGetNewInstanceConfig()
    {
        $instanceConfig = $this->basePluginController->getDefaultInstanceConfig();
        $this->assertEquals($instanceConfig['html'], self::DEFAULT_HTML);
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testSaveInstance()
    {
        $newHtml = '<b>hi</b>';
        $id = 349857;
        $config = array('html' => $newHtml);
        $this->basePluginController->saveInstance(
            $id,
            $config
        );
        $this->assertEquals(
            $id,
            $this->pluginStorageMgrMock->lastSavedInstanceId
        );
        $this->assertEquals(
            $config,
            $this->pluginStorageMgrMock->lastSavedConfig
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testGetInstanceConfig()
    {
        $instanceConfig = $this
            ->basePluginController->getInstanceConfig(1);
        $this->assertEquals($instanceConfig['html'], self::DEFAULT_HTML);

        $defaultInstanceConfig = $this->basePluginController
            ->getInstanceConfig(-1);
        $this->assertEquals($defaultInstanceConfig['html'], self::DEFAULT_HTML);
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    public function testPostIsForThisPlugin()
    {
        $pluginName = 'RcmJDPluginStorage';
        $this->basePluginController->setPluginName($pluginName);
        $_POST['rcmPluginName'] = $pluginName;<commit_msg>fix unit tests -  WEBCART-200 Get checkout working in zend form to make checkout testable<commit_after><?php

namespace RcmInstanceConfigTest\Controller;

require_once __DIR__ . '/../../../../../Rcm/test/Base/BaseTestCase.php';
require_once __DIR__ . '/../Mock/PluginStorageMgrMock.php';

use RcmInstanceConfig\Controller\BasePluginController;
use RcmInstanceConfig\Service\PluginStorageMgrMock;
use RcmTest\Base\BaseTestCase;
use Zend\Http\PhpEnvironment\Request;

class BasePluginControllerTest extends BaseTestCase
{

    /** @var  \RcmInstanceConfig\Controller\BasePluginController */
    protected $basePluginController;

    const DEFAULT_HTML = '<h1>hello</h1>';

    /**
     * @var \RcmInstanceConfig\Service\PluginStorageMgrMock
     */
    protected $pluginStorageMgrMock;

    public function setUp()
    {
        $this->addModule('RcmInstanceConfig');
        parent::setUp();

        $this->pluginStorageMgrMock = new PluginStorageMgrMock(
            array('html' => self::DEFAULT_HTML)
        );

        $this->basePluginController = new BasePluginController(
            $this->pluginStorageMgrMock,
            array(
                'rcmPlugin' => array(
                    'RcmInstanceConfig' => array(
                        'defaultInstanceConfig' => array(
                            'html' => self::DEFAULT_HTML
                        )
                    )
                )
            )
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testSetGetRequest()
    {
        $request = new Request();
        $this->basePluginController->setRequest(new Request());
        $this->assertEquals(
            $request, $this->basePluginController->getRequest()
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testRenderInstance()
    {
        $personName = 'bob';
        $viewModel = $this->basePluginController->renderInstance(
            1,
            array('personName' => $personName)
        );
        $this->assertInstanceOf('\Zend\View\Model\ViewModel', $viewModel);
        $this->assertEquals(
            $viewModel->getVariable('personName'),
            $personName
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testRenderDefaultInstance()
    {
        $personName = 'bob';
        $viewModel = $this->basePluginController->renderDefaultInstance(
            -1,
            array('personName' => $personName)
        );
        $this->assertInstanceOf('\Zend\View\Model\ViewModel', $viewModel);
        $this->assertEquals(
            $viewModel->getVariable('personName'),
            $personName
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testGetNewInstanceConfig()
    {
        $instanceConfig = $this->basePluginController->getDefaultInstanceConfig();
        $this->assertEquals($instanceConfig['html'], self::DEFAULT_HTML);
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testSaveInstance()
    {
        $newHtml = '<b>hi</b>';
        $id = 349857;
        $config = array('html' => $newHtml);
        $this->basePluginController->saveInstance(
            $id,
            $config
        );
        $this->assertEquals(
            $id,
            $this->pluginStorageMgrMock->lastSavedInstanceId
        );
        $this->assertEquals(
            $config,
            $this->pluginStorageMgrMock->lastSavedConfig
        );
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    function testGetInstanceConfig()
    {
        $instanceConfig = $this
            ->basePluginController->getInstanceConfig(1);
        $this->assertEquals($instanceConfig['html'], self::DEFAULT_HTML);

        $defaultInstanceConfig = $this->basePluginController
            ->getInstanceConfig(-1);
        $this->assertEquals($defaultInstanceConfig['html'], self::DEFAULT_HTML);
    }

    /**
     * @covers\RcmInstanceConfig\Controller\BasePluginController
     */
    public function testPostIsForThisPlugin()
    {
        $this->basePluginController->setPluginName('RcmJDPluginStorage');
        $_POST['rcmPluginName'] =  $this->basePluginController->getPluginName();
{'fraction_non_alphanumeric': 0.1257934218118869, 'fraction_numerical': 0.0031159838430467397, 'mean_word_length': 2.277609682299546, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7394965', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2288, 'n_words': 298}