WeatherHelperTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. App::uses('WeatherHelper', 'Tools.View/Helper');
  3. App::uses('HtmlHelper', 'View/Helper');
  4. App::uses('View', 'View');
  5. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  6. /**
  7. */
  8. class WeatherHelperTest extends MyCakeTestCase {
  9. public function setUp() {
  10. parent::setUp();
  11. $this->Weather = new WeatherHelper(new View(null));
  12. $this->Weather->Html = new HtmlHelper(new View(null));
  13. }
  14. /**
  15. * WeatherHelperTest::testImageUrl()
  16. *
  17. * @return void
  18. */
  19. public function testImageUrl() {
  20. $res = $this->Weather->imageUrl('sunny', 'gif');
  21. $this->assertEquals('http://www.google.com/ig/images/weather/sunny.gif', $res);
  22. Configure::write('Weather.imageUrl', '/img/');
  23. $this->Weather = new WeatherHelper(new View(null));
  24. $this->Weather->Html = new HtmlHelper(new View(null));
  25. $res = $this->Weather->imageUrl('foo', 'jpg');
  26. $this->assertEquals('/img/foo.jpg', $res);
  27. $res = $this->Weather->imageUrl('foo', 'jpg', true);
  28. $this->assertEquals(Configure::read('App.fullBaseUrl') . '/img/foo.jpg', $res);
  29. }
  30. /**
  31. * WeatherHelperTest::testGet()
  32. *
  33. * @return void
  34. */
  35. public function testGet() {
  36. $this->skipIf(!Configure::read('Weather.key'), 'Only for webrunner');
  37. $res = $this->Weather->get('Berlin, Deutschland');
  38. $this->out($res);
  39. }
  40. /**
  41. * WeatherHelperTest::testDisplayDebug()
  42. *
  43. * @return void
  44. */
  45. public function testDisplayDebug() {
  46. $this->skipIf(!Configure::read('Weather.key'), 'Only for webrunner');
  47. $res = $this->Weather->get('51.0872,13.8028');
  48. $res = $this->_displayForecast($res);
  49. $this->out($res);
  50. $this->assertTrue(!empty($res));
  51. $res = $this->Weather->get('Berlin, Deutschland');
  52. $res = $this->_displayForecast($res);
  53. $this->out($res);
  54. $this->assertTrue(!empty($res));
  55. $res = $this->Weather->get('Schwäbisch Hall, Deutschland');
  56. $res = $this->_displayForecast($res);
  57. $this->out($res);
  58. $this->assertTrue(!empty($res));
  59. $res = $this->Weather->get('xxxxx');
  60. $res = $this->_displayForecast($res);
  61. $this->assertTrue(empty($res));
  62. }
  63. protected function _displayForecast($w) {
  64. $res = '';
  65. if (empty($w['request'])) {
  66. return $res;
  67. }
  68. $res .= '<table><tr>';
  69. for ($i = 2; $i < 5; $i++) {
  70. $weather = $w['weather'][$i];
  71. $res .= '<td>';
  72. $res .= '<h1>' . date('D', strtotime($weather['date'])) . '</h1>';
  73. $res .= '<div>' . date('M d, Y', strtotime($weather['date'])) . '</div>';
  74. $res .= '<h1>' . $this->Weather->Html->image($weather['weatherIconUrl']) . '</h1>';
  75. $res .= '<div>' . $weather['tempMinC'] . '° - ' . $weather['tempMaxC'] . '°</div>';
  76. $res .= '<div>' . $weather['weatherDesc'] . '</div>';
  77. $res .= '</td>';
  78. }
  79. $res .= '</tr></table>';
  80. return $res;
  81. }
  82. }