<commit_before><?php

class TestCRUD extends IntegrationTestCase
{
    public function testModelCanBeStoredAndRetrieved()
    {
        User::forceCreate([
            'name' => '<NAME>',
            'bio' => 'Lorem ipsum'
        ]);

        $user = User::first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum', $user->bio);
    }

    public function testModelCanBeStoredAndRetrievedInDifferentLocales()
    {
        $user = User::forceCreate([
            'name' => '<NAME>',
            'bio'  => 'Lorem ipsum'
        ]);

        $user->forceSaveTranslation('de', [
            'bio' => 'DE Lorem ipsum'
        ]);

        $user = User::first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum', $user->bio);

        $user = User::translateInto('de')->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('DE Lorem ipsum', $user->bio);
    }

    public function testFallbackLocaleIsUsedWhenNoMatchingLocaleIsFound()
    {
        User::forceCreate([
            'name' => '<NAME>',
            'bio' => 'Lorem ipsum'
        ]);

        $user = User::translateInto('de')->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum', $user->bio);
    }

    public function testFallbackCanBeDisabled()
    {
        User::forceCreate([
            'name' => '<NAME>',
            'bio' => 'Lorem ipsum'
        ]);

        $user = User::translateInto('de')->withoutFallback()->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertNull($user->bio);
    }

    public function testModelCanBeUpdated()
    {
        $user = User::forceCreate([
            'name' => '<NAME>',
            'bio' => 'Lorem ipsum'
        ]);

        $user->name = '<NAME>';
        $user->save();

        $user->bio = 'Lorem ipsum 2';
        $user->save();

        $user = $user->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum 2', $user->bio);

        $user->name = '<NAME>';
        $user->bio = 'Lorem ipsum';
        $user->save();

        $user = $user->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum', $user->bio);
    }

    public function testWhereTranslated()
    {
        Post::forceCreate(['title' => 'Title 1']);
        Post::forceCreate(['title' => 'Title 2']);

        $this->assertEquals(1, Post::where('title', 'Title 1')->count());
    }

    public function testWhereTranslatedWithFallback()
    {
        Post::forceCreateInLocale('de', ['title'  => 'Title']);
        Post::forceCreateInLocale('en', ['title'  => 'Title']);

        $queryWithFallback = Post::translateInto('de')->where('title', 'Title');
        $queryWithoutFallback = Post::translateInto('de')->withoutFallback()->where('title', 'Title');

        $this->assertEquals(2, $queryWithFallback->count());
        $this->assertEquals(1, $queryWithoutFallback->count());
    }

    public function testOrderByTranslated()
    {
        Post::forceCreate(['title' => 'Title 1']);
        Post::forceCreate(['title' => 'Title 2']);

        $this->assertEquals('Title 2', Post::orderBy('title', 'desc')->first()->title);
    }

    public function testOrderByTranslatedWithFallback()
    {
        Post::forceCreateInLocale('de', ['title'  => 'Title 1']);
        Post::forceCreateInLocale('en', ['title'  => 'Title 2']);

        $queryWithFallback = Post::translateInto('de')->orderBy('title', 'desc');
        $queryWithoutFallback = Post::translateInto('de')->withoutFallback()->orderBy('title', 'desc');

        $this->assertEquals('Title 2', $queryWithFallback->first()->title);
        $this->assertEquals('Title 1', $queryWithoutFallback->first()->title);
    }

    public function testMacros()
    {<commit_msg>Add another test for array where conditions<commit_after><?php

class TestCRUD extends IntegrationTestCase
{
    public function testModelCanBeStoredAndRetrieved()
    {
        User::forceCreate([
            'name' => '<NAME>',
            'bio' => 'Lorem ipsum'
        ]);

        $user = User::first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum', $user->bio);
    }

    public function testModelCanBeStoredAndRetrievedInDifferentLocales()
    {
        $user = User::forceCreate([
            'name' => '<NAME>',
            'bio'  => 'Lorem ipsum'
        ]);

        $user->forceSaveTranslation('de', [
            'bio' => 'DE Lorem ipsum'
        ]);

        $user = User::first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum', $user->bio);

        $user = User::translateInto('de')->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('DE Lorem ipsum', $user->bio);
    }

    public function testFallbackLocaleIsUsedWhenNoMatchingLocaleIsFound()
    {
        User::forceCreate([
            'name' => '<NAME>',
            'bio' => 'Lorem ipsum'
        ]);

        $user = User::translateInto('de')->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum', $user->bio);
    }

    public function testFallbackCanBeDisabled()
    {
        User::forceCreate([
            'name' => '<NAME>',
            'bio' => 'Lorem ipsum'
        ]);

        $user = User::translateInto('de')->withoutFallback()->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertNull($user->bio);
    }

    public function testModelCanBeUpdated()
    {
        $user = User::forceCreate([
            'name' => '<NAME>',
            'bio' => 'Lorem ipsum'
        ]);

        $user->name = '<NAME>';
        $user->save();

        $user->bio = 'Lorem ipsum 2';
        $user->save();

        $user = $user->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum 2', $user->bio);

        $user->name = '<NAME>';
        $user->bio = 'Lorem ipsum';
        $user->save();

        $user = $user->first();
        $this->assertEquals('<NAME>', $user->name);
        $this->assertEquals('Lorem ipsum', $user->bio);
    }

    public function testWhereTranslated()
    {
        Post::forceCreate(['title' => 'Title 1']);
        Post::forceCreate(['title' => 'Title 2']);

        $this->assertEquals(1, Post::where('title', 'Title 1')->count());
    }

    public function testWhereTranslatedWithFallback()
    {
        Post::forceCreateInLocale('de', ['title'  => 'Title']);
        Post::forceCreateInLocale('en', ['title'  => 'Title']);

        $queryWithFallback = Post::translateInto('de')->where('title', 'Title');
        $queryWithoutFallback = Post::translateInto('de')->withoutFallback()->where('title', 'Title');

        $this->assertEquals(2, $queryWithFallback->count());
        $this->assertEquals(1, $queryWithoutFallback->count());
    }

    public function testWhereTranslatedWithArray()
    {
        Post::forceCreateInLocale('de', ['title'  => 'Title']);
        Post::forceCreateInLocale('en', ['title'  => 'Title']);

        $result = Post::translateInto('de')->where(['title' => 'Title'])->get();

        $this->assertEquals(2, $result->count());
    }

    public function testOrderByTranslated()
    {
        Post::forceCreate(['title' => 'Title 1']);
        Post::forceCreate(['title' => 'Title 2']);

        $this->assertEquals('Title 2', Post::orderBy('title', 'desc')->first()->title);
    }

    public function testOrderByTranslatedWithFallback()
    {
        Post::forceCreateInLocale('de', ['title'  => 'Title 1']);
        Post::forceCreateInLocale('en', ['title'  => 'Title 2']);

        $queryWithFallback = Post::translateInto('de')->orderBy('title', 'desc');
        $queryWithoutFallback = Post::translateInto('de')->withoutFallback()->orderBy('title', 'desc');

        $this->assertEquals('Title 2', $queryWithFallback->first()->title);
        $this->assertEquals('Title 1', $queryWithoutFallback->first()->title);
    }

    public function testMacros()
    {
{'fraction_non_alphanumeric': 0.19804520464263897, 'fraction_numerical': 0.0037874160048869884, 'mean_word_length': 2.7209090909090907, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 202, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7177164', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2338, 'n_words': 402}