403Webshell
Server IP : 54.94.228.101  /  Your IP : 172.28.20.13
Web Server : Apache
System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/vinumday2_0/vendor/dimsav/laravel-translatable/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/vinumday2_0/vendor/dimsav/laravel-translatable/tests/ScopesTest.php
<?php

use Dimsav\Translatable\Test\Model\Country;

class ScopesTest extends TestsBase
{
    public function test_translated_in_scope_returns_only_translated_records_for_this_locale()
    {
        $translatedCountries = Country::translatedIn('fr')->get();
        $this->assertEquals($translatedCountries->count(), 1);
    }

    public function test_translated_in_scope_works_with_default_locale()
    {
        App::setLocale('de');
        $translatedCountries = Country::translatedIn()->get();

        $this->assertSame($translatedCountries->count(), 1);
        $this->assertSame('Griechenland', $translatedCountries->first()->name);
    }

    public function test_not_translated_in_scope_returns_only_not_translated_records_for_this_locale()
    {
        $notTranslatedCountries = Country::notTranslatedIn('en')->get();
        $this->assertCount(2, $notTranslatedCountries);

        foreach ($notTranslatedCountries as $notTranslatedCountry) {
            $this->assertFalse($notTranslatedCountry->hasTranslation('en'));
        }
    }

    public function test_not_translated_in_scope_works_with_default_locale()
    {
        App::setLocale('en');
        $notTranslatedCountries = Country::notTranslatedIn()->get();
        $this->assertCount(2, $notTranslatedCountries);

        foreach ($notTranslatedCountries as $notTranslatedCountry) {
            $this->assertFalse($notTranslatedCountry->hasTranslation('en'));
        }
    }

    public function test_translated_scope_returns_records_with_at_least_one_translation()
    {
        $translatedCountries = Country::translated()->get();
        $this->assertEquals($translatedCountries->count(), 2);
    }

    public function test_lists_of_translated_fields()
    {
        App::setLocale('de');
        $list = [[
            'id'   => '1',
            'name' => 'Griechenland',
        ]];
        $this->assertEquals($list, Country::listsTranslations('name')->get()->toArray());
    }

    public function test_lists_of_translated_fields_with_fallback()
    {
        App::make('config')->set('translatable.fallback_locale', 'en');
        App::setLocale('de');
        $country = new Country();
        $country->useTranslationFallback = true;
        $list = [[
            'id'   => '1',
            'name' => 'Griechenland',
        ], [
            'id'   => '2',
            'name' => 'France',
        ]];
        $this->assertEquals($list, $country->listsTranslations('name')->get()->toArray());
    }

    public function test_scope_withTranslation_without_fallback()
    {
        $result = Country::withTranslation()->first();
        $loadedTranslations = $result->toArray()['translations'];
        $this->assertCount(1, $loadedTranslations);
        $this->assertSame('Greece', $loadedTranslations[0]['name']);
    }

    public function test_scope_withTranslation_with_fallback()
    {
        App::make('config')->set('translatable.fallback_locale', 'de');
        App::make('config')->set('translatable.use_fallback', true);

        $result = Country::withTranslation()->first();
        $loadedTranslations = $result->toArray()['translations'];
        $this->assertCount(2, $loadedTranslations);
        $this->assertSame('Greece', $loadedTranslations[0]['name']);
        $this->assertSame('Griechenland', $loadedTranslations[1]['name']);
    }

    public function test_whereTranslation_filters_by_translation()
    {
        /** @var Country $country */
        $country = Country::whereTranslation('name', 'Greece')->first();
        $this->assertSame('gr', $country->code);
    }

    public function test_orWhereTranslation_filters_by_translation()
    {
        $result = Country::whereTranslation('name', 'Greece')->orWhereTranslation('name', 'France')->get();
        $this->assertCount(2, $result);
        $this->assertSame('Greece', $result[0]->name);
        $this->assertSame('France', $result[1]->name);
    }

    public function test_whereTranslation_filters_by_translation_and_locale()
    {
        Country::create(['code' => 'some-code', 'name' => 'Griechenland']);

        $this->assertSame(2, Country::whereTranslation('name', 'Griechenland')->count());

        $result = Country::whereTranslation('name', 'Griechenland', 'de')->get();
        $this->assertSame(1, $result->count());
        $this->assertSame('gr', $result->first()->code);
    }

    public function test_whereTranslationLike_filters_by_translation()
    {
        /** @var Country $country */
        $country = Country::whereTranslationLike('name', '%Greec%')->first();
        $this->assertSame('gr', $country->code);
    }

    public function test_orWhereTranslationLike_filters_by_translation()
    {
        $result = Country::whereTranslationLike('name', '%eece%')->orWhereTranslationLike('name', '%ance%')->get();
        $this->assertCount(2, $result);
        $this->assertSame('Greece', $result[0]->name);
        $this->assertSame('France', $result[1]->name);
    }

    public function test_whereTranslationLike_filters_by_translation_and_locale()
    {
        Country::create(['code' => 'some-code', 'name' => 'Griechenland']);

        $this->assertSame(2, Country::whereTranslationLike('name', 'Griechen%')->count());

        $result = Country::whereTranslationLike('name', '%riechenlan%', 'de')->get();
        $this->assertSame(1, $result->count());
        $this->assertSame('gr', $result->first()->code);
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit