|
| 1 | +<?php |
| 2 | + |
| 3 | +use Krisell\LaravelTranslationJsonCache\Tests\TestCase; |
| 4 | + |
| 5 | +class TranslationJsonCacheTest extends TestCase |
| 6 | +{ |
| 7 | + /** @test */ |
| 8 | + function the_cache_file_is_created_when_the_env_variable_is_true() |
| 9 | + { |
| 10 | + config(['translation-json-cache.active' => true]); |
| 11 | + |
| 12 | + __("Test"); |
| 13 | + |
| 14 | + $this->assertTrue(Storage::exists('translation-cache-en.php')); |
| 15 | + } |
| 16 | + |
| 17 | + /** @test */ |
| 18 | + function the_cache_file_is_not_created_when_the_env_variable_is_false () |
| 19 | + { |
| 20 | + config(['translation-json-cache.active' => false]); |
| 21 | + |
| 22 | + __("Test"); |
| 23 | + |
| 24 | + $this->assertFalse(Storage::exists('translation-cache-en.php')); |
| 25 | + } |
| 26 | + |
| 27 | + /** @test */ |
| 28 | + function the_cache_file_is_not_created_when_the_env_variable_is_missing () |
| 29 | + { |
| 30 | + config(['translation-json-cache.active' => null]); |
| 31 | + |
| 32 | + __("Test"); |
| 33 | + |
| 34 | + $this->assertFalse(Storage::exists('translation-cache-en.php')); |
| 35 | + } |
| 36 | + |
| 37 | + /** @test */ |
| 38 | + function the_cache_file_is_used_when_the_env_variable_is_set_to_true () |
| 39 | + { |
| 40 | + Storage::put('translation-cache-en.php', '<?php return ["Test" => "Testing"];'); |
| 41 | + config(['translation-json-cache.active' => true]); |
| 42 | + |
| 43 | + $this->assertEquals("Testing", __("Test")); |
| 44 | + } |
| 45 | + |
| 46 | + /** @test */ |
| 47 | + function the_cache_file_is_not_used_when_the_env_variable_is_set_to_false () |
| 48 | + { |
| 49 | + Storage::put('translation-cache-en.php', '<?php return ["Test" => "Testing"];'); |
| 50 | + config(['translation-json-cache.active' => false]); |
| 51 | + |
| 52 | + $this->assertEquals("Test", __("Test")); |
| 53 | + } |
| 54 | + |
| 55 | + /** @test */ |
| 56 | + function the_cache_file_is_not_used_when_the_env_variable_is_missing () |
| 57 | + { |
| 58 | + Storage::put('translation-cache-en.php', '<?php return ["Test" => "Testing"];'); |
| 59 | + config(['translation-json-cache.active' => null]); |
| 60 | + |
| 61 | + $this->assertEquals("Test", __("Test")); |
| 62 | + } |
| 63 | + |
| 64 | + /** @test */ |
| 65 | + function the_data_in_the_cached_file_corresponds_to_the_json_file () |
| 66 | + { |
| 67 | + file_put_contents(base_path() . '/resources/lang/en.json', '{"Test":"Testing"}'); |
| 68 | + config(['translation-json-cache.active' => true]); |
| 69 | + |
| 70 | + $this->assertEquals("Testing", __("Test")); |
| 71 | + |
| 72 | + $data = require storage_path() . '/app/translation-cache-en.php'; |
| 73 | + $this->assertEquals('Testing', $data['Test']); |
| 74 | + } |
| 75 | + |
| 76 | + /** @test */ |
| 77 | + function the_cached_file_takes_presendece_if_it_differs_from_the_json_file () |
| 78 | + { |
| 79 | + file_put_contents(base_path() . '/resources/lang/en.json', '{"Test":"Testing"}'); |
| 80 | + file_put_contents(storage_path() . '/app/translation-cache-en.php', '<?php return ["Test" => "Testing2"];'); |
| 81 | + config(['translation-json-cache.active' => true]); |
| 82 | + |
| 83 | + $this->assertEquals("Testing2", __("Test")); |
| 84 | + } |
| 85 | +} |
0 commit comments