diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-03-22 19:16:35 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-04-03 19:24:55 +0200 |
commit | ae3aa96898834ce3992790e1622541ce48fd78d3 (patch) | |
tree | eaedb30e45748b11a3b5bcf0224ee797c2f341bb /tests/TimeZoneTest.php | |
parent | c84379478621303b186f50d647e90079727b6062 (diff) | |
download | Shaarli-ae3aa96898834ce3992790e1622541ce48fd78d3.tar.gz Shaarli-ae3aa96898834ce3992790e1622541ce48fd78d3.tar.zst Shaarli-ae3aa96898834ce3992790e1622541ce48fd78d3.zip |
Change timezone data structure send to the templates
The goal of this is to be able to adapt the timezone form
in template without hacking the HTML already rendered.
* there are two arrays available:
* `continents` which contains only a list of available continents
* `cities` which contains a list of available timezone cities, associated with their continent
Note: there are two distinct array because RainTPL doesn't support nested loop very well.
Diffstat (limited to 'tests/TimeZoneTest.php')
-rw-r--r-- | tests/TimeZoneTest.php | 83 |
1 files changed, 51 insertions, 32 deletions
diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php index 2976d116..127fdc19 100644 --- a/tests/TimeZoneTest.php +++ b/tests/TimeZoneTest.php | |||
@@ -11,24 +11,45 @@ require_once 'application/TimeZone.php'; | |||
11 | class TimeZoneTest extends PHPUnit_Framework_TestCase | 11 | class TimeZoneTest extends PHPUnit_Framework_TestCase |
12 | { | 12 | { |
13 | /** | 13 | /** |
14 | * @var array of timezones | ||
15 | */ | ||
16 | protected $installedTimezones; | ||
17 | |||
18 | public function setUp() | ||
19 | { | ||
20 | $this->installedTimezones = [ | ||
21 | 'Antarctica/Syowa', | ||
22 | 'Europe/London', | ||
23 | 'Europe/Paris', | ||
24 | 'UTC' | ||
25 | ]; | ||
26 | } | ||
27 | |||
28 | /** | ||
14 | * Generate a timezone selection form | 29 | * Generate a timezone selection form |
15 | */ | 30 | */ |
16 | public function testGenerateTimeZoneForm() | 31 | public function testGenerateTimeZoneForm() |
17 | { | 32 | { |
18 | $generated = generateTimeZoneForm(); | 33 | $expected = [ |
34 | 'continents' => [ | ||
35 | 'Antarctica', | ||
36 | 'Europe', | ||
37 | 'UTC', | ||
38 | 'selected' => '', | ||
39 | ], | ||
40 | 'cities' => [ | ||
41 | ['continent' => 'Antarctica', 'city' => 'Syowa'], | ||
42 | ['continent' => 'Europe', 'city' => 'London'], | ||
43 | ['continent' => 'Europe', 'city' => 'Paris'], | ||
44 | ['continent' => 'UTC', 'city' => 'UTC'], | ||
45 | 'selected' => '', | ||
46 | ] | ||
47 | ]; | ||
19 | 48 | ||
20 | // HTML form | 49 | list($continents, $cities) = generateTimeZoneData($this->installedTimezones); |
21 | $this->assertStringStartsWith('Continent:<select', $generated[0]); | ||
22 | $this->assertContains('selected="selected"', $generated[0]); | ||
23 | $this->assertStringEndsWith('</select><br />', $generated[0]); | ||
24 | 50 | ||
25 | // Javascript handler | 51 | $this->assertEquals($expected['continents'], $continents); |
26 | $this->assertStringStartsWith('<script>', $generated[1]); | 52 | $this->assertEquals($expected['cities'], $cities); |
27 | $this->assertContains( | ||
28 | '<option value=\"Bermuda\">Bermuda<\/option>', | ||
29 | $generated[1] | ||
30 | ); | ||
31 | $this->assertStringEndsWith('</script>', $generated[1]); | ||
32 | } | 53 | } |
33 | 54 | ||
34 | /** | 55 | /** |
@@ -36,28 +57,26 @@ class TimeZoneTest extends PHPUnit_Framework_TestCase | |||
36 | */ | 57 | */ |
37 | public function testGenerateTimeZoneFormPreselected() | 58 | public function testGenerateTimeZoneFormPreselected() |
38 | { | 59 | { |
39 | $generated = generateTimeZoneForm('Antarctica/Syowa'); | 60 | $expected = [ |
40 | 61 | 'continents' => [ | |
41 | // HTML form | 62 | 'Antarctica', |
42 | $this->assertStringStartsWith('Continent:<select', $generated[0]); | 63 | 'Europe', |
43 | $this->assertContains( | 64 | 'UTC', |
44 | 'value="Antarctica" selected="selected"', | 65 | 'selected' => 'Antarctica', |
45 | $generated[0] | 66 | ], |
46 | ); | 67 | 'cities' => [ |
47 | $this->assertContains( | 68 | ['continent' => 'Antarctica', 'city' => 'Syowa'], |
48 | 'value="Syowa" selected="selected"', | 69 | ['continent' => 'Europe', 'city' => 'London'], |
49 | $generated[0] | 70 | ['continent' => 'Europe', 'city' => 'Paris'], |
50 | ); | 71 | ['continent' => 'UTC', 'city' => 'UTC'], |
51 | $this->assertStringEndsWith('</select><br />', $generated[0]); | 72 | 'selected' => 'Syowa', |
73 | ] | ||
74 | ]; | ||
52 | 75 | ||
76 | list($continents, $cities) = generateTimeZoneData($this->installedTimezones, 'Antarctica/Syowa'); | ||
53 | 77 | ||
54 | // Javascript handler | 78 | $this->assertEquals($expected['continents'], $continents); |
55 | $this->assertStringStartsWith('<script>', $generated[1]); | 79 | $this->assertEquals($expected['cities'], $cities); |
56 | $this->assertContains( | ||
57 | '<option value=\"Bermuda\">Bermuda<\/option>', | ||
58 | $generated[1] | ||
59 | ); | ||
60 | $this->assertStringEndsWith('</script>', $generated[1]); | ||
61 | } | 80 | } |
62 | 81 | ||
63 | /** | 82 | /** |