<commit_before><?php
use LazyRecord\Testing\ModelTestCase;

class NameModelTest extends ModelTestCase
{
    public $driver = 'sqlite';

    public function getModels()
    {
        return array('TestApp\Model\\NameSchema');
    }

    public function nameDataProvider()
    {
        return array( 
            array(array(
                'name' => '中文',
                'country' => 'Tokyo',
                'confirmed' => true,
                'date' => new DateTime('2011-01-01 00:00:00'),
            )),
            array(array(
                'name' => 'Test2',
                'country' => 'Taipei',
                'confirmed' => false,
                'date' => '2011-01-01 00:00:00',
            )),
        );
    }

    public function booleanNullTestDataProvider()
    {
        return array(
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => NULL ) ),
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => '' ) ),
        );
    }


    public function booleanFalseTestDataProvider()
    {
        return array(
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => 0 ) ),
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => '0' ) ),
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => false ) ),
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => 'false' ) ),
        );
    }

    public function booleanTrueTestDataProvider()
    {
        return array(
            array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => 1 ) ),
            array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => '1' ) ),
            array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => true ) ),
            array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => 'true' ) ),
        );
    }

    /**
     * @dataProvider booleanFalseTestDataProvider
     */
    public function testCreateWithBooleanFalse(array $args)
    {
        $n = new \TestApp\Model\Name;
        $ret = $n->create($args);
        $this->assertResultSuccess($ret);
        $this->assertFalse($n->confirmed);
    }


    /**
     * @basedata false
     * @dataProvider booleanNullTestDataProvider
     */
    public function testCreateWithBooleanNull(array $args)
    {
        $n = new \TestApp\Model\Name;
        $ret = $n->create($args);
        $this->assertResultSuccess($ret);

        ok($n->id);
        $this->assertNull($n->confirmed);

        $ret = $n->load($n->id);
        $this->assertResultSuccess($ret);
        $this->assertNull($n->confirmed);
        $this->successfulDelete($n);
    }


    /**
     * @basedata false
     * @dataProvider booleanTrueTestDataProvider
     */
    public function testCreateWithBooleanTrue(array $args)
    {
        $n = new \TestApp\Model\Name;
        $ret = $n->create($args);
        $this->assertResultSuccess($ret);
        ok($n->id);

        $this->assertTrue($n->confirmed, 'Confirmed value should be TRUE.');

        $ret = $n->load($n->id);
        $this->assertResultSuccess($ret);

        $this->assertTrue($n->confirmed, 'Confirmed value should be TRUE.');
        $this->successfulDelete($n);
    }

    /**
     * @rebuild false
     */
    public function testModelClone()
    {
        $test1 = new \TestApp\Model\Name;
        $test2 = clone $test1;
        $this->assertNotSame($test1, $test2);
    }


    /**
     * @basedata false
     */
    public function testModelColumnFilter()
    {
        $name = new \TestApp\Model\Name;
        $ret = $name->create(array('name' => 'Foo' , 'country' => 'Taiwan' , 'address' => 'John'));
        $this->assertResultSuccess($ret);
        is('XXXX' , $name->address , 'Should be canonicalized' );
    }

    public function testBooleanFromStringZero()
    {
        $n = new \TestApp\Model\Name;

        /** confirmed will be cast to true **/
        $ret = $n->create(array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => '0' ));
        $this->assertResultSuccess( $ret );
        ok( $n->id );

        $this->assertFalse($n->confirmed);
        $this->successfulDelete($n);
    }


    /**
     * @rebuild false
     */
    public function testValueTypeConstraint()
    {
        // if it's a str type , we should not accept types not str.
        $n = new \TestApp\Model\Name;

        /**
         * name column is required, after type casting, it's NULL, so
         * create should fail.
         */
        $ret = $n->create(array( 'name' => false , 'country' => 'Type' ));
        $this->assertResultFail($ret);
        ok(! $n->id );
    }

    public function testModelColumnDefaultValueBuilder()
    {
        $name = new \TestApp\Model\Name;
        $ret = $name->create(array(  'name' => 'Foo' , 'country' => 'Taiwan' ));

        $this->assertResultSuccess($ret);

        $this->assertNotEmpty($ret->validations);

        $this->assertTrue(isset($ret->validations['address']));
        $this->assertTrue($ret->validations['address']['valid']);

        ok( $vlds = $ret->getSuccessValidations() );
        count_ok( 1, $vlds );

        ok( $name->id );
        ok( $name->address );

        $ret = $name->create(array(  'name' => 'Foo', 'address' => 'fuck' , 'country' => 'Tokyo' ));
        ok( $ret->validations );

        foreach( $ret->getErrorValidations() as $vld ) {
            $this->assertFalse($vld['valid']);
            $this->assertEquals('Please don\'t',  $vld['message']);
        }
    }

    public function testLoadFromContstructor()
    {
        $name = new \TestApp\Model\Name;
        $ret = $name->create(array( 
            'name' => 'John',
            'country' => 'Taiwan',
            'type' => 'type-a',
        ));
        $this->assertResultSuccess($ret);
        ok( $name->id );

        $name2 = new \TestApp\Model\Name( $name->id );
        is( $name2->id , $name->id );
    }

    public function testValidValueBuilder()
    {
        $name = new \TestApp\Model\Name;
        $ret = $name->create(array( 
            'name' => 'John',
            'country' => 'Taiwan',
            'type' => 'type-a',
        ));
        $this->assertResultSuccess($ret);
        $this->assertEquals( 'Type Name A', $name->display( 'type' ) );

        $xml = $name->toXml();
        $dom = new DOMDocument;
        $dom->loadXml($xml);

        if (extension_loaded('yaml')) {
            $yaml = $name->toYaml();
            yaml_parse($yaml);
        }

        $json = $name->toJson();
        $this->assertNotEmpty($json);
        $this->assertNotEmpty(json_decode($json));
        $this->assertResultSuccess($name->delete());
    }

    public function testDeflator()
    {
        $n = new \TestApp\Model\Name;
        $ret = $n->create(array( 
            'name' => '<NAME>' , 
            'country' => 'Tokyo', 
            'confirmed' => '0',
            'date' => '2011-01-01'
        ));
        $this->assertResultSuccess($ret);

        $d = $n->date;
        $this->assertNotNull($d);
        $this->assertInstanceOf('DateTime', $d);
        $this->assertEquals('20110101' , $d->format( 'Ymd' ));

        $ret = $n->delete();<commit_msg>Add more rebuild false flag on NameModelTest<commit_after><?php
use LazyRecord\Testing\ModelTestCase;

class NameModelTest extends ModelTestCase
{
    public $driver = 'sqlite';

    public function getModels()
    {
        return array('TestApp\Model\\NameSchema');
    }

    public function nameDataProvider()
    {
        return array( 
            array(array(
                'name' => '中文',
                'country' => 'Tokyo',
                'confirmed' => true,
                'date' => new DateTime('2011-01-01 00:00:00'),
            )),
            array(array(
                'name' => 'Test2',
                'country' => 'Taipei',
                'confirmed' => false,
                'date' => '2011-01-01 00:00:00',
            )),
        );
    }

    public function booleanNullTestDataProvider()
    {
        return array(
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => NULL ) ),
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => '' ) ),
        );
    }


    public function booleanFalseTestDataProvider()
    {
        return array(
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => 0 ) ),
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => '0' ) ),
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => false ) ),
              array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => 'false' ) ),
        );
    }

    public function booleanTrueTestDataProvider()
    {
        return array(
            array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => 1 ) ),
            array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => '1' ) ),
            array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => true ) ),
            array( array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => 'true' ) ),
        );
    }

    /**
     * @dataProvider booleanFalseTestDataProvider
     */
    public function testCreateWithBooleanFalse(array $args)
    {
        $n = new \TestApp\Model\Name;
        $ret = $n->create($args);
        $this->assertResultSuccess($ret);
        $this->assertFalse($n->confirmed);
    }


    /**
     * @basedata false
     * @dataProvider booleanNullTestDataProvider
     */
    public function testCreateWithBooleanNull(array $args)
    {
        $n = new \TestApp\Model\Name;
        $ret = $n->create($args);
        $this->assertResultSuccess($ret);

        ok($n->id);
        $this->assertNull($n->confirmed);

        $ret = $n->load($n->id);
        $this->assertResultSuccess($ret);
        $this->assertNull($n->confirmed);
        $this->successfulDelete($n);
    }


    /**
     * @basedata false
     * @dataProvider booleanTrueTestDataProvider
     */
    public function testCreateWithBooleanTrue(array $args)
    {
        $n = new \TestApp\Model\Name;
        $ret = $n->create($args);
        $this->assertResultSuccess($ret);
        ok($n->id);

        $this->assertTrue($n->confirmed, 'Confirmed value should be TRUE.');

        $ret = $n->load($n->id);
        $this->assertResultSuccess($ret);

        $this->assertTrue($n->confirmed, 'Confirmed value should be TRUE.');
        $this->successfulDelete($n);
    }

    /**
     * @rebuild false
     */
    public function testModelClone()
    {
        $test1 = new \TestApp\Model\Name;
        $test2 = clone $test1;
        $this->assertNotSame($test1, $test2);
    }


    /**
     * @basedata false
     */
    public function testModelColumnFilter()
    {
        $name = new \TestApp\Model\Name;
        $ret = $name->create(array('name' => 'Foo' , 'country' => 'Taiwan' , 'address' => 'John'));
        $this->assertResultSuccess($ret);
        is('XXXX' , $name->address , 'Should be canonicalized' );
    }

    public function testBooleanFromStringZero()
    {
        $n = new \TestApp\Model\Name;

        /** confirmed will be cast to true **/
        $ret = $n->create(array( 'name' => 'Foo' , 'country' => 'Tokyo', 'confirmed' => '0' ));
        $this->assertResultSuccess( $ret );
        ok( $n->id );

        $this->assertFalse($n->confirmed);
        $this->successfulDelete($n);
    }


    /**
     * @rebuild false
     */
    public function testValueTypeConstraint()
    {
        // if it's a str type , we should not accept types not str.
        $n = new \TestApp\Model\Name;

        /**
         * name column is required, after type casting, it's NULL, so
         * create should fail.
         */
        $ret = $n->create(array( 'name' => false , 'country' => 'Type' ));
        $this->assertResultFail($ret);
        ok(! $n->id );
    }

    public function testModelColumnDefaultValueBuilder()
    {
        $name = new \TestApp\Model\Name;
        $ret = $name->create(array(  'name' => 'Foo' , 'country' => 'Taiwan' ));

        $this->assertResultSuccess($ret);

        $this->assertNotEmpty($ret->validations);

        $this->assertTrue(isset($ret->validations['address']));
        $this->assertTrue($ret->validations['address']['valid']);

        ok( $vlds = $ret->getSuccessValidations() );
        count_ok( 1, $vlds );

        ok( $name->id );
        ok( $name->address );

        $ret = $name->create(array(  'name' => 'Foo', 'address' => 'fuck' , 'country' => 'Tokyo' ));
        ok( $ret->validations );

        foreach( $ret->getErrorValidations() as $vld ) {
            $this->assertFalse($vld['valid']);
            $this->assertEquals('Please don\'t',  $vld['message']);
        }
    }

    public function testLoadFromContstructor()
    {
        $name = new \TestApp\Model\Name;
        $ret = $name->create(array( 
            'name' => 'John',
            'country' => 'Taiwan',
            'type' => 'type-a',
        ));
        $this->assertResultSuccess($ret);
        ok( $name->id );

        $name2 = new \TestApp\Model\Name( $name->id );
        is( $name2->id , $name->id );
    }

    /**
     * @rebuild false
     */
    public function testValidValueBuilder()
    {
        $name = new \TestApp\Model\Name;
        $ret = $name->create(array( 
            'name' => 'John',
            'country' => 'Taiwan',
            'type' => 'type-a',
        ));
        $this->assertResultSuccess($ret);
        $this->assertEquals( 'Type Name A', $name->display( 'type' ) );

        $xml = $name->toXml();
        $dom = new DOMDocument;
        $dom->loadXml($xml);

        if (extension_loaded('yaml')) {
            $yaml = $name->toYaml();
            yaml_parse($yaml);
        }

        $json = $name->toJson();
        $this->assertNotEmpty($json);
        $this->assertNotEmpty(json_decode($json));
        $this->assertResultSuccess($name->delete());
    }

    /**
     * @rebuild false
     */
    public function testDeflator()
    {
        $n = new \TestApp\Model\Name;
        $ret = $n->create(array( 
            'name' => '<NAME>' , 
            'country' => 'Tokyo', 
            'confirmed' => '0',
            'date' => '2011-01-01'
        ));
        $this->assertResultSuccess($ret);

        $d = $n->date;
        $this->assertNotNull($d);
        $this->assertInstanceOf('DateTime', $d);
        $this->assertEquals('20110101' , $d->format( 'Ymd' ));

        $ret = $n->delete();
{'fraction_non_alphanumeric': 0.18264026854833185, 'fraction_numerical': 0.008083852846475304, 'mean_word_length': 1.9895556010649191, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 289, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5002508', 'n_tokens_mistral': 4668, 'n_tokens_neox': 4432, 'n_words': 877}