<commit_before><?php

namespace Oro\Bundle\TrackingBundle\Tests\Functional\Command;

use Symfony\Component\Filesystem\Filesystem;

use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;

/**
 * @dbIsolation
 */
class UpdateSchemaListenerTest extends WebTestCase
{
    /**
     * @var Filesystem
     */
    protected $fs;

    /**
     * @var string
     */
    protected $directory;

    /**
     * @var string
     */
    protected $logsDir;

    protected function setUp()
    {
        $this->initClient();

        $this->fs = new Filesystem();

        $this->directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . time();
    }

    protected function tearDown()
    {
        $this->fs->remove($this->directory);
    }

    public function testDirectoryEmpty()
    {
        $this->assertFalse($this->fs->exists($this->directory));

        $result = $this->runCommand(
            'oro:cron:import-tracking',
            ['--directory' => $this->directory]
        );
        $this->assertContains('Logs not found', $result);
    }

    public function testFileProcessed()
    {
        $date = new \DateTime();
        $file = $date->modify('-1 day')->format('Ymd-H') . '-60-1.log';

        $this->fs->dumpFile(
            $this->directory . DIRECTORY_SEPARATOR . $file,
            json_encode(['prop' => 'value'])
        );

        $result = $this->runCommand(
            'oro:cron:import-tracking',
            ['--directory' => $this->directory]
        );
        $this->assertContains(sprintf('Successful: "%s"', $file), $result);
    }

    public function testCurrentFileNotProcessed()
    {
        $date = new \DateTime();
        $file = $date->format('Ymd-H') . '-60-1.log';

        $this->fs->dumpFile(
            $this->directory . DIRECTORY_SEPARATOR . $file,
            json_encode(['prop' => 'value'])
        );

        $result = $this->runCommand(
            'oro:cron:import-tracking',
            ['--directory' => $this->directory]
        );
        $this->assertNotContains(sprintf('Successful: "%s"', $file), $result);
    }
}<commit_msg>CRM-1405: Tracking of user website behavior - CR changes<commit_after><?php

namespace Oro\Bundle\TrackingBundle\Tests\Functional\Command;

use Symfony\Component\Filesystem\Filesystem;

use Oro\Bundle\TestFrameworkBundle\Test\WebTestCase;

/**
 * @dbIsolation
 */
class UpdateSchemaListenerTest extends WebTestCase
{
    /**
     * @var Filesystem
     */
    protected $fs;

    /**
     * @var string
     */
    protected $directory;

    /**
     * @var string
     */
    protected $logsDir;

    protected function setUp()
    {
        $this->initClient();

        $this->fs = new Filesystem();

        $this->directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . time();
    }

    protected function tearDown()
    {
        $this->fs->remove($this->directory);
    }

    public function testDirectoryEmpty()
    {
        $this->assertFalse($this->fs->exists($this->directory));

        $result = $this->runCommand(
            'oro:cron:import-tracking',
            ['--directory' => $this->directory]
        );
        $this->assertTrue($this->fs->exists($this->directory));
        $this->assertContains('Logs not found', $result);
    }

    public function testFileProcessed()
    {
        $date = new \DateTime();
        $file = $date->modify('-1 day')->format('Ymd-H') . '-60-1.log';

        $this->fs->dumpFile(
            $this->directory . DIRECTORY_SEPARATOR . $file,
            json_encode(['prop' => 'value'])
        );

        $result = $this->runCommand(
            'oro:cron:import-tracking',
            ['--directory' => $this->directory]
        );
        $this->assertFileNotExists($this->directory . DIRECTORY_SEPARATOR . $file);
        $this->assertContains(sprintf('Successful: "%s"', $file), $result);
    }

    public function testCurrentFileNotProcessed()
    {
        $date = new \DateTime();
        $file = $date->format('Ymd-H') . '-60-1.log';

        $this->fs->dumpFile(
            $this->directory . DIRECTORY_SEPARATOR . $file,
            json_encode(['prop' => 'value'])
        );

        $result = $this->runCommand(
            'oro:cron:import-tracking',
            ['--directory' => $this->directory]
        );
        $this->assertFileExists($this->directory . DIRECTORY_SEPARATOR . $file);
        $this->assertNotContains(sprintf('Successful: "%s"', $file), $result);
    }
}
{'fraction_non_alphanumeric': 0.16801984663960307, 'fraction_numerical': 0.0040595399188092015, 'mean_word_length': 2.2325072886297375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, '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': '7153957', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1320, 'n_words': 216}