<commit_before><?php
namespace CsvMigrations\Test\TestCase\Model\Table;

use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use CsvMigrations\Model\Table\DblistsTable;

/**
 * CsvMigrations\Model\Table\DblistsTable Test Case
 */
class DblistsTableTest extends TestCase
{

    /**
     * Fixtures
     *
     * @var array
     */
    public $fixtures = [
        'plugin.CsvMigrations.Dblists',
        'plugin.CsvMigrations.DblistItems',
    ];

    /**
     * Test subject
     *
     * @var \CsvMigrations\Model\Table\DblistsTable
     */
    public $Dblists;

    /**
     * setUp method
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
        $config = TableRegistry::exists('Dblists') ? [] : ['className' => 'CsvMigrations\Model\Table\DblistsTable'];
        $this->Dblists = TableRegistry::get('Dblists', $config);
    }

    /**
     * Test initialize method
     *
     * @return void
     */
    public function testInitialize()
    {
        $this->assertTrue($this->Dblists->hasBehavior('Timestamp'), 'Missing behavior Timestamp.');
        $assoc = $this->Dblists->association('DblistItems');
        $this->assertFalse(is_null($assoc), 'DblistItems cannot be found');
        $this->assertInstanceOf('Cake\ORM\Association\HasMany', $assoc, 'Dblists\'s association with DblistItems should be hasMany');
    }

    /**
     * Test validationDefault method
     *
     * @return void
     */
    public function testValidationDefault()
    {
        $validator = $this->Dblists->validator();
        $this->assertTrue($validator->hasField('id'), 'Missing validation for id');
        $this->assertTrue($validator->hasField('name'), 'Missing validation for name');
    }

    /**
     * Test Options query.
     *
     * @return void
     */
    public function testOptions()
    {
        $list = 'categories';
        $query = $this->Dblists->find('options', ['name' => $list]);
        $this->assertInstanceOf('Cake\ORM\Query', $query);
        $this->assertFalse($query->isEmpty());

        $list = null;
        $result = $this->Dblists->find('options', ['name' => $list]);
        $this->assertTrue(is_array($result), 'Return shouold be an empty array on wrong name lists');
    }

    /**
     * tearDown method
     *
     * @return void
     */
    public function tearDown()
    {
        unset($this->Dblists);

        parent::tearDown();
    }
}
<commit_msg>Extended unit tests for Dblists table custom finder method (task #8246)<commit_after><?php
namespace CsvMigrations\Test\TestCase\Model\Table;

use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use CsvMigrations\Model\Table\DblistsTable;

/**
 * CsvMigrations\Model\Table\DblistsTable Test Case
 */
class DblistsTableTest extends TestCase
{

    /**
     * Fixtures
     *
     * @var array
     */
    public $fixtures = [
        'plugin.CsvMigrations.Dblists',
        'plugin.CsvMigrations.DblistItems',
    ];

    /**
     * Test subject
     *
     * @var \CsvMigrations\Model\Table\DblistsTable
     */
    public $Dblists;

    /**
     * setUp method
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
        $config = TableRegistry::exists('Dblists') ? [] : ['className' => 'CsvMigrations\Model\Table\DblistsTable'];
        $this->Dblists = TableRegistry::get('Dblists', $config);
    }

    /**
     * Test initialize method
     *
     * @return void
     */
    public function testInitialize()
    {
        $this->assertTrue($this->Dblists->hasBehavior('Timestamp'), 'Missing behavior Timestamp.');
        $assoc = $this->Dblists->association('DblistItems');
        $this->assertFalse(is_null($assoc), 'DblistItems cannot be found');
        $this->assertInstanceOf('Cake\ORM\Association\HasMany', $assoc, 'Dblists\'s association with DblistItems should be hasMany');
    }

    /**
     * Test validationDefault method
     *
     * @return void
     */
    public function testValidationDefault()
    {
        $validator = $this->Dblists->validator();
        $this->assertTrue($validator->hasField('id'), 'Missing validation for id');
        $this->assertTrue($validator->hasField('name'), 'Missing validation for name');
    }

    /**
     * Test Options query.
     *
     * @return void
     */
    public function testOptions()
    {
        $expected = [
            'corporate' => 'Corporate',
            'leonid' => ' - Leonid',
            'individual' => 'Individual',
            'antonis' => ' - Antonis',
            'george' => ' - George'
        ];
        $list = 'categories';

        $this->assertSame($expected, $this->Dblists->find('options', ['name' => $list]));
    }

    /**
     * Test Options query.
     *
     * @return void
     */
    public function testOptionsWithInvalidListName()
    {
        $expected = [];
        $list = 'some-invalid-list-name';

        $this->assertSame($expected, $this->Dblists->find('options', ['name' => $list]));
    }

    /**
     * tearDown method
     *
     * @return void
     */
    public function tearDown()
    {
        unset($this->Dblists);

        parent::tearDown();
    }
}

{'fraction_non_alphanumeric': 0.1537270087124879, 'fraction_numerical': 0.0007744433688286545, 'mean_word_length': 2.3742651861528414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, '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': '5899550', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1590, 'n_words': 288}