TimeZoneTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * TimeZone's tests
  4. */
  5. require_once 'application/TimeZone.php';
  6. /**
  7. * Unitary tests for timezone utilities
  8. */
  9. class TimeZoneTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * Generate a timezone selection form
  13. */
  14. public function testGenerateTimeZoneForm()
  15. {
  16. $generated = generateTimeZoneForm();
  17. // HTML form
  18. $this->assertStringStartsWith('Continent:<select', $generated[0]);
  19. $this->assertContains('selected="selected"', $generated[0]);
  20. $this->assertStringEndsWith('</select><br />', $generated[0]);
  21. // Javascript handler
  22. $this->assertStringStartsWith('<script>', $generated[1]);
  23. $this->assertContains(
  24. '<option value=\"Bermuda\">Bermuda<\/option>',
  25. $generated[1]
  26. );
  27. $this->assertStringEndsWith('</script>', $generated[1]);
  28. }
  29. /**
  30. * Generate a timezone selection form, with a preselected timezone
  31. */
  32. public function testGenerateTimeZoneFormPreselected()
  33. {
  34. $generated = generateTimeZoneForm('Antarctica/Syowa');
  35. // HTML form
  36. $this->assertStringStartsWith('Continent:<select', $generated[0]);
  37. $this->assertContains(
  38. 'value="Antarctica" selected="selected"',
  39. $generated[0]
  40. );
  41. $this->assertContains(
  42. 'value="Syowa" selected="selected"',
  43. $generated[0]
  44. );
  45. $this->assertStringEndsWith('</select><br />', $generated[0]);
  46. // Javascript handler
  47. $this->assertStringStartsWith('<script>', $generated[1]);
  48. $this->assertContains(
  49. '<option value=\"Bermuda\">Bermuda<\/option>',
  50. $generated[1]
  51. );
  52. $this->assertStringEndsWith('</script>', $generated[1]);
  53. }
  54. /**
  55. * Check valid timezones
  56. */
  57. public function testValidTimeZone()
  58. {
  59. $this->assertTrue(isTimeZoneValid('America', 'Argentina/Ushuaia'));
  60. $this->assertTrue(isTimeZoneValid('Europe', 'Oslo'));
  61. }
  62. /**
  63. * Check invalid timezones
  64. */
  65. public function testInvalidTimeZone()
  66. {
  67. $this->assertFalse(isTimeZoneValid('CEST', 'CEST'));
  68. $this->assertFalse(isTimeZoneValid('Europe', 'Atlantis'));
  69. $this->assertFalse(isTimeZoneValid('Middle_Earth', 'Moria'));
  70. $this->assertFalse(isTimeZoneValid('UTC', 'UTC'));
  71. }
  72. }