Skip to content

Commit 2bb5827

Browse files
author
Andy Wermke
committed
Added testing for backward compatibility.
1 parent a8e4bd4 commit 2bb5827

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

tests/JsLocalizationControllerTest.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Mockery as m;
4+
35
class JsLocalizationControllerTest extends TestCase
46
{
57
public function testCreateJsMessages ()
@@ -12,7 +14,7 @@ public function testCreateJsMessages ()
1214

1315
$response = $this->action('GET', 'JsLocalizationController@createJsMessages');
1416
$content = $response->getContent();
15-
17+
1618
$this->assertTrue($response->isOk());
1719

1820
// Test for Lang.setLocale()
@@ -24,6 +26,35 @@ public function testCreateJsMessages ()
2426
$this->assertLangAddMessages($content, $this->testMessages);
2527
}
2628

29+
public function testBackwardsCompatibility ()
30+
{
31+
// Prepare & Request
32+
33+
$this->mockLang($locale = 'en');
34+
$this->mockCachingService($this->testMessages['en']);
35+
36+
$response = $this->action('GET', 'JsLocalizationController@createJsMessages');
37+
$content = $response->getContent();
38+
39+
$this->assertTrue($response->isOk());
40+
41+
// Test for Lang.addMessages()
42+
43+
$this->assertLangAddMessages($content, $this->testMessages);
44+
}
45+
46+
private function mockCachingService (array $messages)
47+
{
48+
$service = m::mock('CachingServiceMock');
49+
JsLocalization\Facades\CachingService::swap($service);
50+
51+
$service->shouldReceive('getMessagesJson')
52+
->andReturn(json_encode($messages));
53+
54+
$service->shouldReceive('getLastRefreshTimestamp')
55+
->andReturn(time());
56+
}
57+
2758
private function assertLangAddMessages ($jsContent, array $expectedMessages)
2859
{
2960
$addMessagesRegex = '/Lang\.addMessages\( (\{.*?\}) \);/x';
@@ -38,4 +69,4 @@ private function assertLangAddMessages ($jsContent, array $expectedMessages)
3869
$this->assertEquals($expectedMessages, $messages);
3970
}
4071

41-
}
72+
}

0 commit comments

Comments
 (0)