|
| 1 | +<?php |
| 2 | + |
| 3 | +use ElaborateCode\JigsawLocalization\Mocks\PageMock; |
| 4 | + |
| 5 | +test('path es => ar', function () { |
| 6 | + $this->app->config = collect(['baseUrl' => 'https://elaboratecode.com/packages']); |
| 7 | + |
| 8 | + $page = (new PageMock)->setPath('/es/blog'); |
| 9 | + |
| 10 | + expect(translate_url($page, 'ar'))->toBe('https://elaboratecode.com/packages/ar/blog'); |
| 11 | +}); |
| 12 | + |
| 13 | +test('path ar <=> fr-CA', function () { |
| 14 | + $this->app->config = collect(['baseUrl' => 'https://elaboratecode.com/packages']); |
| 15 | + |
| 16 | + expect(translate_url((new PageMock)->setPath('/ar/blog'), 'fr-CA'))->toBe('https://elaboratecode.com/packages/fr-CA/blog'); |
| 17 | + expect(translate_url((new PageMock)->setPath('/fr-CA/blog'), 'fr-CA'))->toBe('https://elaboratecode.com/packages/fr-CA/blog'); |
| 18 | +}); |
| 19 | + |
| 20 | +test('path ar <=> haw-US', function () { |
| 21 | + $this->app->config = collect(['baseUrl' => 'https://elaboratecode.com/packages']); |
| 22 | + |
| 23 | + expect(translate_url((new PageMock)->setPath('/ar/blog'), 'haw-US'))->toBe('https://elaboratecode.com/packages/haw-US/blog'); |
| 24 | + expect(translate_url((new PageMock)->setPath('/haw-US/blog'), 'haw-US'))->toBe('https://elaboratecode.com/packages/haw-US/blog'); |
| 25 | +}); |
| 26 | + |
| 27 | +test('path haw-US <=> fr-CA', function () { |
| 28 | + $this->app->config = collect(['baseUrl' => 'https://elaboratecode.com/packages']); |
| 29 | + |
| 30 | + expect(translate_url((new PageMock)->setPath('/fr-CA/blog'), 'haw-US'))->toBe('https://elaboratecode.com/packages/haw-US/blog'); |
| 31 | + expect(translate_url((new PageMock)->setPath('/haw-US/blog'), 'fr-CA'))->toBe('https://elaboratecode.com/packages/fr-CA/blog'); |
| 32 | +}); |
| 33 | + |
| 34 | +test('path from DEFAULT_LOCALE', function () { |
| 35 | + $this->app->config = collect(['baseUrl' => 'https://elaboratecode.com/packages']); |
| 36 | + |
| 37 | + expect(translate_url((new PageMock)->setPath('/blog'), 'ar'))->toBe('https://elaboratecode.com/packages/ar/blog'); |
| 38 | + expect(translate_url((new PageMock)->setPath('/blog'), 'en-UK'))->toBe('https://elaboratecode.com/packages/en-UK/blog'); |
| 39 | + expect(translate_url((new PageMock)->setPath('/blog'), 'haw-US'))->toBe('https://elaboratecode.com/packages/haw-US/blog'); |
| 40 | + expect(translate_url((new PageMock)->setPath('/blog'), packageDefaultLocale()))->toBe('https://elaboratecode.com/packages/blog'); |
| 41 | +}); |
| 42 | + |
| 43 | +test('path to DEFAULT_LOCALE', function () { |
| 44 | + $this->app->config = collect(['baseUrl' => 'https://elaboratecode.com/packages']); |
| 45 | + |
| 46 | + expect([ |
| 47 | + translate_url((new PageMock)->setPath('/ar/blog')), |
| 48 | + translate_url((new PageMock)->setPath('/en-UK/blog')), |
| 49 | + translate_url((new PageMock)->setPath('/haw-US/blog')), |
| 50 | + translate_url((new PageMock)->setPath('/blog')), |
| 51 | + ]) |
| 52 | + ->each |
| 53 | + ->toBe('https://elaboratecode.com/packages/blog'); |
| 54 | +}); |
0 commit comments