<commit_before><?php
/**
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 * @link          https://cakephp.org CakePHP(tm) Project
 * @since         3.0.0
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 */
namespace Cake\Test\TestCase\ORM;

use Cake\Datasource\ConnectionManager;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Cake\Utility\Text;

/**
 * Integration tests for Table class with uuid primary keys.
 */
class TableUuidTest extends TestCase
{

    /**
     * Fixtures
     *
     * @var array
     */
    public $fixtures = [
        'core.binary_uuiditems',
        'core.uuiditems',
    ];

    /**
     * setup
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
        $this->connection = ConnectionManager::get('test');
        static::setAppNamespace();
    }

    /**
     * teardown
     *
     * @return void
     */
    public function tearDown()
    {
        parent::tearDown();
        TableRegistry::clear();
    }

    /**
     * Provider for testing that string and binary uuids work the same
     *
     * @return array
     */
    public function uuidTableProvider()
    {
        return [['uuiditems'], ['binary_uuiditems']];
    }

    /**
     * Test saving new records sets uuids
     *
     * @dataProvider uuidTableProvider
     * @return void
     */
    public function testSaveNew($tableName)
    {
        $entity = new Entity([
            'name' => '<NAME>',
            'published' => true,
        ]);
        $table = TableRegistry::get($tableName);
        $this->assertSame($entity, $table->save($entity));
        $this->assertRegExp('/^[a-f0-9-]{36}$/', $entity->id, 'Should be 36 characters');

        $row = $table->find('all')->where(['id' => $entity->id])->first();
        $row->id = strtolower($row->id);
        $this->assertEquals($entity->toArray(), $row->toArray());
    }

    /**
     * Test saving new records allows manual uuids
     *
     * @dataProvider uuidTableProvider
     * @return void
     */
    public function testSaveNewSpecificId($tableName)
    {
        $id = Text::uuid();
        $entity = new Entity([
            'id' => $id,
            'name' => '<NAME>',
            'published' => true,
        ]);
        $table = TableRegistry::get($tableName);
        $this->assertSame($entity, $table->save($entity));
        $this->assertSame($id, $entity->id);

        $row = $table->find('all')->where(['id' => $id])->first();
        $this->assertNotEmpty($row);
        $this->assertSame($id, strtolower($row->id));
        $this->assertSame($entity->name, $row->name);
    }

    /**
     * Test saving existing records works
     *
     * @dataProvider uuidTableProvider
     * @return void
     */
    public function testSaveUpdate($tableName)
    {
        $id = '481fc6d0-b920-43e0-a40d-6d1740cf8569';
        $entity = new Entity([
            'id' => $id,
            'name' => '<NAME>',
            'published' => true,
        ]);

        $table = TableRegistry::get($tableName);
        $this->assertSame($entity, $table->save($entity));
        $this->assertEquals($id, $entity->id, 'Should be 36 characters');

        $row = $table->find('all')->where(['id' => $entity->id])->first();
        $row->id = strtolower($row->id);
        $this->assertEquals($entity->toArray(), $row->toArray());
    }

    /**
     * Test delete with string pk.
     *
     * @dataProvider uuidTableProvider
     * @return void
     */<commit_msg>Add additional test for get() with uuid.<commit_after><?php
/**
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 * @link          https://cakephp.org CakePHP(tm) Project
 * @since         3.0.0
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 */
namespace Cake\Test\TestCase\ORM;

use Cake\Datasource\ConnectionManager;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Cake\Utility\Text;

/**
 * Integration tests for Table class with uuid primary keys.
 */
class TableUuidTest extends TestCase
{

    /**
     * Fixtures
     *
     * @var array
     */
    public $fixtures = [
        'core.binary_uuiditems',
        'core.uuiditems',
    ];

    /**
     * setup
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();
        $this->connection = ConnectionManager::get('test');
        static::setAppNamespace();
    }

    /**
     * teardown
     *
     * @return void
     */
    public function tearDown()
    {
        parent::tearDown();
        TableRegistry::clear();
    }

    /**
     * Provider for testing that string and binary uuids work the same
     *
     * @return array
     */
    public function uuidTableProvider()
    {
        return [['uuiditems'], ['binary_uuiditems']];
    }

    /**
     * Test saving new records sets uuids
     *
     * @dataProvider uuidTableProvider
     * @return void
     */
    public function testSaveNew($tableName)
    {
        $entity = new Entity([
            'name' => 'shiny new',
            'published' => true,
        ]);
        $table = TableRegistry::get($tableName);
        $this->assertSame($entity, $table->save($entity));
        $this->assertRegExp('/^[a-f0-9-]{36}$/', $entity->id, 'Should be 36 characters');

        $row = $table->find('all')->where(['id' => $entity->id])->first();
        $row->id = strtolower($row->id);
        $this->assertEquals($entity->toArray(), $row->toArray());
    }

    /**
     * Test saving new records allows manual uuids
     *
     * @dataProvider uuidTableProvider
     * @return void
     */
    public function testSaveNewSpecificId($tableName)
    {
        $id = Text::uuid();
        $entity = new Entity([
            'id' => $id,
            'name' => '<NAME>',
            'published' => true,
        ]);
        $table = TableRegistry::get($tableName);
        $this->assertSame($entity, $table->save($entity));
        $this->assertSame($id, $entity->id);

        $row = $table->find('all')->where(['id' => $id])->first();
        $this->assertNotEmpty($row);
        $this->assertSame($id, strtolower($row->id));
        $this->assertSame($entity->name, $row->name);
    }

    /**
     * Test saving existing records works
     *
     * @dataProvider uuidTableProvider
     * @return void
     */
    public function testSaveUpdate($tableName)
    {
        $id = '481fc6d0-b920-43e0-a40d-6d1740cf8569';
        $entity = new Entity([
            'id' => $id,
            'name' => '<NAME>',
            'published' => true,
        ]);

        $table = TableRegistry::get($tableName);
        $this->assertSame($entity, $table->save($entity));
        $this->assertEquals($id, $entity->id, 'Should be 36 characters');

        $row = $table->find('all')->where(['id' => $entity->id])->first();
        $row->id = strtolower($row->id);
        $this->assertEquals($entity->toArray(), $row->toArray());
    }

    /**
     * Test delete with string pk.
     *
     * @dataProvider uuidTableProvider
     * @return void
     */
    public function testGetById($tableName)
    {
        $table = TableRegistry::get($tableName);
        $entity = $table->find('all')->firstOrFail();

        $result = $table->get($entity->id);
        $this->assertSame($result->id, $entity->id);
    }

    /**
     * Test delete with string pk.
     *
     * @dataProvider uuidTableProvider
     * @return void
     */
{'fraction_non_alphanumeric': 0.1631162507608034, 'fraction_numerical': 0.008034083992696287, 'mean_word_length': 2.2877150860344138, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 117, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5145256', 'n_tokens_mistral': 2501, 'n_tokens_neox': 2425, 'n_words': 525}