From ae3aa96898834ce3992790e1622541ce48fd78d3 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 22 Mar 2017 19:16:35 +0100 Subject: 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. --- tests/TimeZoneTest.php | 83 +++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php index 2976d116..127fdc19 100644 --- a/tests/TimeZoneTest.php +++ b/tests/TimeZoneTest.php @@ -10,25 +10,46 @@ require_once 'application/TimeZone.php'; */ class TimeZoneTest extends PHPUnit_Framework_TestCase { + /** + * @var array of timezones + */ + protected $installedTimezones; + + public function setUp() + { + $this->installedTimezones = [ + 'Antarctica/Syowa', + 'Europe/London', + 'Europe/Paris', + 'UTC' + ]; + } + /** * Generate a timezone selection form */ public function testGenerateTimeZoneForm() { - $generated = generateTimeZoneForm(); + $expected = [ + 'continents' => [ + 'Antarctica', + 'Europe', + 'UTC', + 'selected' => '', + ], + 'cities' => [ + ['continent' => 'Antarctica', 'city' => 'Syowa'], + ['continent' => 'Europe', 'city' => 'London'], + ['continent' => 'Europe', 'city' => 'Paris'], + ['continent' => 'UTC', 'city' => 'UTC'], + 'selected' => '', + ] + ]; - // HTML form - $this->assertStringStartsWith('Continent:assertContains('selected="selected"', $generated[0]); - $this->assertStringEndsWith('
', $generated[0]); + list($continents, $cities) = generateTimeZoneData($this->installedTimezones); - // Javascript handler - $this->assertStringStartsWith('', $generated[1]); + $this->assertEquals($expected['continents'], $continents); + $this->assertEquals($expected['cities'], $cities); } /** @@ -36,28 +57,26 @@ class TimeZoneTest extends PHPUnit_Framework_TestCase */ public function testGenerateTimeZoneFormPreselected() { - $generated = generateTimeZoneForm('Antarctica/Syowa'); - - // HTML form - $this->assertStringStartsWith('Continent:assertContains( - 'value="Antarctica" selected="selected"', - $generated[0] - ); - $this->assertContains( - 'value="Syowa" selected="selected"', - $generated[0] - ); - $this->assertStringEndsWith('
', $generated[0]); + $expected = [ + 'continents' => [ + 'Antarctica', + 'Europe', + 'UTC', + 'selected' => 'Antarctica', + ], + 'cities' => [ + ['continent' => 'Antarctica', 'city' => 'Syowa'], + ['continent' => 'Europe', 'city' => 'London'], + ['continent' => 'Europe', 'city' => 'Paris'], + ['continent' => 'UTC', 'city' => 'UTC'], + 'selected' => 'Syowa', + ] + ]; + list($continents, $cities) = generateTimeZoneData($this->installedTimezones, 'Antarctica/Syowa'); - // Javascript handler - $this->assertStringStartsWith('', $generated[1]); + $this->assertEquals($expected['continents'], $continents); + $this->assertEquals($expected['cities'], $cities); } /** -- cgit v1.2.3