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.
This commit is contained in:
parent
c843794786
commit
ae3aa96898
4 changed files with 106 additions and 101 deletions
tests
|
@ -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:<select', $generated[0]);
|
||||
$this->assertContains('selected="selected"', $generated[0]);
|
||||
$this->assertStringEndsWith('</select><br />', $generated[0]);
|
||||
list($continents, $cities) = generateTimeZoneData($this->installedTimezones);
|
||||
|
||||
// Javascript handler
|
||||
$this->assertStringStartsWith('<script>', $generated[1]);
|
||||
$this->assertContains(
|
||||
'<option value=\"Bermuda\">Bermuda<\/option>',
|
||||
$generated[1]
|
||||
);
|
||||
$this->assertStringEndsWith('</script>', $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');
|
||||
$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',
|
||||
]
|
||||
];
|
||||
|
||||
// HTML form
|
||||
$this->assertStringStartsWith('Continent:<select', $generated[0]);
|
||||
$this->assertContains(
|
||||
'value="Antarctica" selected="selected"',
|
||||
$generated[0]
|
||||
);
|
||||
$this->assertContains(
|
||||
'value="Syowa" selected="selected"',
|
||||
$generated[0]
|
||||
);
|
||||
$this->assertStringEndsWith('</select><br />', $generated[0]);
|
||||
list($continents, $cities) = generateTimeZoneData($this->installedTimezones, 'Antarctica/Syowa');
|
||||
|
||||
|
||||
// Javascript handler
|
||||
$this->assertStringStartsWith('<script>', $generated[1]);
|
||||
$this->assertContains(
|
||||
'<option value=\"Bermuda\">Bermuda<\/option>',
|
||||
$generated[1]
|
||||
);
|
||||
$this->assertStringEndsWith('</script>', $generated[1]);
|
||||
$this->assertEquals($expected['continents'], $continents);
|
||||
$this->assertEquals($expected['cities'], $cities);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue