<commit_before><?php

/*
 * This file is part of the ONGR package.
 *
 * (c) NFQ Technologies UAB <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ONGR\SettingsBundle\Tests\Functional\Controller;

use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase;
use ONGR\SettingsBundle\Settings\Common\Provider\ManagerAwareSettingProvider;
use ONGR\SettingsBundle\Settings\Common\SettingsContainer;
use ONGR\SettingsBundle\Tests\Fixtures\Security\LoginTestHelper;
use Symfony\Bundle\FrameworkBundle\Client;

/**
 * Tests for SettingsManagerController.
 */
class SettingsManagerControllerTest extends AbstractElasticsearchTestCase
{
    /**
     * @var Client.
     */
    private $client;

    /**
     * @var LoginTestHelper.
     */
    private $loginHelper;

    /**
     * @var Container
     */
    private $container;

    /**
     * {@inheritdoc}
     */
    public function setUp()
    {
        parent::setUp();

        $this->loginHelper = new LoginTestHelper(static::createClient());
        $this->client = $this->loginHelper->loginAction();

        $this->container = $this->client->getContainer();
    }

    /**
     * Data provider for testCopyAction.
     *
     * @return array
     */
    public function copyActionData()
    {
        // Case #0 non existing profile, existing item passed.
        $out[] = [500, '/settings/setting/name0/copy/foo/newProfile'];

        // Case #1 existing profile set, existing item passed.
        $out[] = [200, '/settings/setting/name0/copy/default/newProfile'];

        // Case #2 non-existent profile and item passed.
        $out[] = [500, '/settings/setting/foo/copy/foo/newProfile'];

        // Case #3 existent profile, non-existing item passed.
        $out[] = [500, '/settings/setting/foo/copy/default/newProfile'];

        return $out;
    }

    /**
     * Create setting.
     */
    public function createSetting()
    {
        $requestContent = json_encode(['setting' => ['data' => ['value' => 'name0']]]);
        $this->client->request('POST', '/settings/setting/ng/name0/edit/default', [], [], [], $requestContent);
    }

    /**
     * Test for createAction().
     */
    public function testCreateSetting()
    {
        $requestContent = json_encode(['setting' => ['data' => ['value' => 'foo']]]);
        $this->client->request('POST', '/settings/setting/ng/setting_foo/edit/domain_foo', [], [], [], $requestContent);
        $response = $this->client->getResponse();
        $this->assertTrue($response->isOk());
    }

    /**
     * Test for copyAction.
     *<commit_msg>Full coverage for SettingsManagerController<commit_after><?php

/*
 * This file is part of the ONGR package.
 *
 * (c) NFQ Technologies UAB <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ONGR\SettingsBundle\Tests\Functional\Controller;

use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase;
use ONGR\SettingsBundle\Settings\Common\Provider\ManagerAwareSettingProvider;
use ONGR\SettingsBundle\Settings\Common\SettingsContainer;
use ONGR\SettingsBundle\Tests\Fixtures\Security\LoginTestHelper;
use Symfony\Bundle\FrameworkBundle\Client;

/**
 * Tests for SettingsManagerController.
 */
class SettingsManagerControllerTest extends AbstractElasticsearchTestCase
{
    /**
     * @var Client.
     */
    private $client;

    /**
     * @var LoginTestHelper.
     */
    private $loginHelper;

    /**
     * @var Container
     */
    private $container;

    /**
     * {@inheritdoc}
     */
    public function setUp()
    {
        parent::setUp();

        $this->loginHelper = new LoginTestHelper(static::createClient());
        $this->client = $this->loginHelper->loginAction();

        $this->container = $this->client->getContainer();
    }

    /**
     * Data provider for testCopyAction.
     *
     * @return array
     */
    public function copyActionData()
    {
        // Case #0 non existing profile, existing item passed.
        $out[] = [500, '/settings/setting/name0/copy/foo/newProfile'];

        // Case #1 existing profile set, existing item passed.
        $out[] = [200, '/settings/setting/name0/copy/default/newProfile'];

        // Case #2 non-existent profile and item passed.
        $out[] = [500, '/settings/setting/foo/copy/foo/newProfile'];

        // Case #3 existent profile, non-existing item passed.
        $out[] = [500, '/settings/setting/foo/copy/default/newProfile'];

        return $out;
    }

    /**
     * Create setting.
     */
    public function createSetting()
    {
        $requestContent = json_encode(['setting' => ['data' => ['value' => 'name0']]]);
        $this->client->request('POST', '/settings/setting/ng/name0/edit/default', [], [], [], $requestContent);
    }

    /**
     * Data provider for testCreateAction().
     *
     * @return array
     */
    public function createActionData()
    {
        // case #0 create setting with valid request content
        $out[] = [json_encode(['setting' => ['data' => ['value' => 'foo'], 'description' => 'description0']]), 200];

        // case #1 create setting with blank request content
        $out[] = [json_encode([]), 400];

        // case #2 create setting with no request content
        $out[] = [null, 400];

        return $out;
    }

    /**
     * Test for createAction().
     *
     * @param string $requestContent
     * @param int    $statusCode
     *
     * @dataProvider createActionData()
     */
    public function testCreateAction($requestContent, $statusCode)
    {
        $this->client->request('POST', '/settings/setting/ng/setting_foo/edit/domain_foo', [], [], [], $requestContent);
        $this->assertEquals($statusCode, $this->client->getResponse()->getStatusCode());
    }

    /**
     * Test for copyAction.
     *
{'fraction_non_alphanumeric': 0.14844668345927792, 'fraction_numerical': 0.008900083963056256, 'mean_word_length': 2.6993788819875775, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 50, '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': '6200934', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1657, 'n_words': 379}