<commit_before><?php

namespace Frontend\Modules\Profiles\Tests\Engine;

use Frontend\Modules\Profiles\Engine\Model;
use Common\WebTestCase;
use Frontend\Modules\Profiles\Engine\Profile;

final class ProfileTest extends WebTestCase
{
    public function setUp(): void
    {
        parent::setUp();

        if (!defined('APPLICATION')) {
            define('APPLICATION', 'Frontend');
        }

        if (!defined('LANGUAGE')) {
            define('LANGUAGE', 'en');
        }

        $client = self::createClient();
        $this->loadFixtures($client);
    }

    public function testCreatingProfile(): void
    {
        $profile = new Profile();

        $profile->setDisplayName('Fork CMS');
        $this->assertEquals('Fork CMS', $profile->getDisplayName());

        $profile->setEmail('<EMAIL>');
        $this->assertEquals('<EMAIL>', $profile->getEmail());

        $profile->setRegisteredOn(1234567890);
        $this->assertEquals(1234567890, $profile->getRegisteredOn());

        $profile->setStatus('random_status');
        $this->assertEquals('random_status', $profile->getStatus());

        $profile->setUrl('fork-cms');
        $this->assertEquals('fork-cms', $profile->getUrl());

        // @TODO These settings setters don't work because the profile doesn't have an ID, this should be fixed
        /*$profile->setSettings(
            [
                'my_first_setting' => 'My first value',
                'my_second_setting' => 'My second value',
            ]
        );
        $this->assertEquals(
            [
                'my_first_setting' => 'My first value',
                'my_second_setting' => 'My second value',
            ],
            $profile->getSettings()
        );
        $this->assertEquals('My first value', $profile->getSetting('my_first_setting'));

        $profile->setSetting('my_second_setting', 'My updated value');
        $this->assertEquals('My updated value', $profile->getSetting('my_second_setting'));

        $profileArray = $profile->toArray();
        $this->assertArrayHasKey('display_name', $profileArray);
        $this->assertEquals('Fork CMS', $profileArray['display_name']);
        $this->assertArrayHasKey('registered_on', $profileArray);
        $this->assertEquals(1234567890, $profileArray['registered_on']);*/
    }

    public function testLoadingOfProfile()
    {
        $profileId = $this->addProfile();

        $profile = new Profile($profileId);

        $this->assertEquals('Fork CMS', $profile->getDisplayName());
        $this->assertEquals('<EMAIL>', $profile->getEmail());
        $this->assertEquals(1520243112, $profile->getRegisteredOn());
        $this->assertEquals('active', $profile->getStatus());
        $this->assertEquals('fork-cms', $profile->getUrl());

        $profile->setSettings(
            [
                'my_first_setting' => 'My first value',
                'my_second_setting' => 'My second value',
            ]
        );
        $this->assertEquals(
            [
                'my_first_setting' => 'My first value',
                'my_second_setting' => 'My second value',
            ],
            $profile->getSettings()
        );
        $this->assertEquals('My first value', $profile->getSetting('my_first_setting'));

        $profile->setSetting('my_second_setting', 'My updated value');
        $this->assertEquals('My updated value', $profile->getSetting('my_second_setting'));

        $profileArray = $profile->toArray();
        $this->assertArrayHasKey('display_name', $profileArray);
        $this->assertEquals('Fork CMS', $profileArray['display_name']);
        $this->assertArrayHasKey('registered_on', $profileArray);
        $this->assertEquals(1520243112, $profileArray['registered_on']);
    }

    public function addProfile(): int
    {
        return Model::insert($this->getProfileData());
    }

    public function getProfileData(): array
    {
        return [
            'email' => '<EMAIL>',
            'password' => <PASSWORD>',
            'status' => 'active',
            'display_name' => 'Fork CMS',
            'url' => 'fork-cms',
            'registered_on' => '2018-03-05 09:45:12',
            'last_login' => '1970-01-01 00:00:00',
        ];
    }<commit_msg>Fix frontend profile tests<commit_after><?php

namespace Frontend\Modules\Profiles\Tests\Engine;

use Backend\Modules\Profiles\Domain\Profile\Profile;
use Backend\Modules\Profiles\Domain\Profile\Status;
use Frontend\Modules\Profiles\Engine\Model;
use Common\WebTestCase;

final class ProfileTest extends WebTestCase
{
    public function setUp(): void
    {
        parent::setUp();

        if (!defined('APPLICATION')) {
            define('APPLICATION', 'Frontend');
        }

        if (!defined('LANGUAGE')) {
            define('LANGUAGE', 'en');
        }

        $client = self::createClient();
        $this->loadFixtures($client);
    }

    public function testCreatingProfile(): void
    {
        $profile = new Profile(
            '<EMAIL>',
            'forkcms',
            Status::active(),
            'Fork CMS',
            'fork-cms'
        );

        $this->assertEquals('Fork CMS', $profile->getDisplayName());
        $this->assertEquals('<EMAIL>', $profile->getEmail());
        $this->assertEquals('active', $profile->getStatus());
        $this->assertEquals('fork-cms', $profile->getUrl());

        $profile->setSettings(
            [
                'my_first_setting' => 'My first value',
                'my_second_setting' => 'My second value',
            ]
        );

        $settings = [];
        foreach ($profile->getSettings()->toArray() as $profileSetting) {
            $settings[$profileSetting->getName()] = $profileSetting->getValue();
        }
        $this->assertEquals(
            [
                'my_first_setting' => 'My first value',
                'my_second_setting' => 'My second value',
            ],
            $settings
        );
        $this->assertEquals('My first value', $profile->getSetting('my_first_setting'));

        $profile->setSetting('my_second_setting', 'My updated value');
        $this->assertEquals('My updated value', $profile->getSetting('my_second_setting'));

        // @TODO The toArray will not work because the profile doesn't have an ID, this should be fixed?
        /*$profileArray = $profile->toArray();
        $this->assertArrayHasKey('display_name', $profileArray);
        $this->assertEquals('Fork CMS', $profileArray['display_name']);
        $this->assertArrayHasKey('registered_on', $profileArray);
        $this->assertEquals(1234567890, $profileArray['registered_on']);*/
    }

    public function testLoadingOfProfile(): void
    {
        $profileId = $this->addProfile();

        $profile = Model::get($profileId);

        $this->assertEquals('Fork CMS', $profile->getDisplayName());
        $this->assertEquals('<EMAIL>', $profile->getEmail());
        $this->assertEquals('active', $profile->getStatus());
        $this->assertEquals('fork-cms', $profile->getUrl());

        $profile->setSettings(
            [
                'my_first_setting' => 'My first value',
                'my_second_setting' => 'My second value',
            ]
        );

        $settings = [];
        foreach ($profile->getSettings()->toArray() as $profileSetting) {
            $settings[$profileSetting->getName()] = $profileSetting->getValue();
        }
        $this->assertEquals(
            [
                'my_first_setting' => 'My first value',
                'my_second_setting' => 'My second value',
            ],
            $settings
        );
        $this->assertEquals('My first value', $profile->getSetting('my_first_setting'));

        $profile->setSetting('my_second_setting', 'My updated value');
        $this->assertEquals('My updated value', $profile->getSetting('my_second_setting'));

        $profileArray = $profile->toArray();
        $this->assertArrayHasKey('display_name', $profileArray);
        $this->assertEquals('Fork CMS', $profileArray['display_name']);
    }

    public function addProfile(): int
    {
        return Model::insert($this->getProfileData());
    }

    public function getProfileData(): array
    {
        return [
            'email' => '<EMAIL>',
            'password' => <PASSWORD>$1Ev9QQNYZBjdU1ELKjKNqelcV.j2l3CgtVkHl0aMvbNpg1g73S5lC',
            'status' => 'active',
            'display_name' => 'Fork CMS',
            'url' => 'fork-cms',
            'registered_on' => '2018-03-05 09:45:12',
            'last_login' => '1970-01-01 00:00:00',
        ];
    }
{'fraction_non_alphanumeric': 0.15878928987194413, 'fraction_numerical': 0.014668218859138533, 'mean_word_length': 2.465510286405809, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 146, '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': '2273370', 'n_tokens_mistral': 2490, 'n_tokens_neox': 2335, 'n_words': 415}