<commit_before><?php

namespace Thinktomorrow\Locale\Tests;

use Illuminate\Support\Facades\Route;
use InvalidArgumentException;
use Thinktomorrow\Locale\Parsers\RouteParser;

class RouteParserTest extends TestCase
{
    private $parser;

    public function setUp()
    {
        parent::setUp();

        $this->refreshBindings();

        $this->parser = app()->make(RouteParser::class);
    }

    /** @test */
    public function to_localize_route()
    {
        $this->assertEquals('http://example.com/foz/baz/cow', $this->parser->set('foo.show')->parameters(['slug' => 'cow'])->localize('nl')->get());
        $this->assertEquals('http://example.com/en/foo/bar/cow', $this->parser->set('foo.show')->parameters(['slug' => 'cow'])->localize('en')->get());
    }

    /** @test */
    public function to_localize_route_not_in_translations_takes_default_translation()
    {
        // Uses fallback locale for translation
        $this->assertEquals('http://example.com/fr/foz/baz/cow', $this->parser->set('foo.show')->parameters(['slug' => 'cow'])->localize('fr')->get());
    }

    /** @test */
    public function to_localize_route_not_in_any_translations()
    {
        $this->setExpectedException(InvalidArgumentException::class);
        $this->assertEquals('http://example.com/fr/foo.unknown', $this->parser->set('foo.unknown')->localize('fr')->get());
    }

    /** @test */
    public function to_make_route_secure()
    {
        Route::get('{color}/foo/bar',['as' => 'foo.custom','uses' => function(){}]);

        $this->assertEquals('https://example.com/blue/foo/bar', $this->parser->set('foo.custom')->parameters(['color' => 'blue'])->secure()->get());
    }

}<commit_msg>Rename test methods<commit_after><?php

namespace Thinktomorrow\Locale\Tests;

use Illuminate\Support\Facades\Route;
use InvalidArgumentException;
use Thinktomorrow\Locale\Parsers\RouteParser;

class RouteParserTest extends TestCase
{
    private $parser;

    public function setUp()
    {
        parent::setUp();

        $this->refreshBindings();

        $this->parser = app()->make(RouteParser::class);
    }

    /** @test */
    public function to_localize_translatable_route()
    {
        $this->assertEquals('http://example.com/foz/baz/cow', $this->parser->set('foo.show')->parameters(['slug' => 'cow'])->localize('nl')->get());
        $this->assertEquals('http://example.com/en/foo/bar/cow', $this->parser->set('foo.show')->parameters(['slug' => 'cow'])->localize('en')->get());
    }

    /** @test */
    public function to_take_default_when_given_route_not_found_as_translatable()
    {
        // Uses fallback locale (nl) for translation of routekey
        $this->assertEquals('http://example.com/fr/foz/baz/cow', $this->parser->set('foo.show')->parameters(['slug' => 'cow'])->localize('fr')->get());
    }

    /** @test */
    public function to_halt_execution_when_route_isnt_translatable()
    {
        $this->setExpectedException(InvalidArgumentException::class);
        $this->assertEquals('http://example.com/fr/foo.unknown', $this->parser->set('foo.unknown')->localize('fr')->get());
    }

    /** @test */
    public function to_make_route_secure()
    {
        Route::get('{color}/foo/bar',['as' => 'foo.custom','uses' => function(){}]);

        $this->assertEquals('https://example.com/blue/foo/bar', $this->parser->set('foo.custom')->parameters(['color' => 'blue'])->secure()->get());
    }

}
{'fraction_non_alphanumeric': 0.2091121495327103, 'fraction_numerical': 0.0, 'mean_word_length': 3.7306629834254146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, 'https://': 2, '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': '7228703', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1056, 'n_words': 127}