Merge pull request #830 from ArthurHoaro/theme/timezone
Change timezone data structure send to the templates
This commit is contained in:
commit
4c7045229c
12 changed files with 289 additions and 144 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