WeatherHelperTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * 2010-06-24 ms
  8. */
  9. class WeatherHelperTest extends MyCakeTestCase {
  10. public function setUp() {
  11. parent::setUp();
  12. if (!Configure::read('Weather.key')) {
  13. Configure::write('Weather.key', '598dfbdaeb121715111208');
  14. }
  15. $this->Weather = new WeatherHelper(new View(null));
  16. $this->Weather->Html = new HtmlHelper(new View(null));
  17. }
  18. /** TODO **/
  19. public function testDisplay() {
  20. $res = $this->Weather->get('51.0872,13.8028');
  21. $res = $this->_displayForecast($res);
  22. $this->out($res);
  23. $this->assertTrue(!empty($res));
  24. $res = $this->Weather->get('Berlin, Deutschland');
  25. $res = $this->_displayForecast($res);
  26. $this->out($res);
  27. $this->assertTrue(!empty($res));
  28. $res = $this->Weather->get('Schwäbisch Hall, Deutschland');
  29. $res = $this->_displayForecast($res);
  30. $this->out($res);
  31. $this->assertTrue(!empty($res));
  32. $res = $this->Weather->get('xxxxx');
  33. $res = $this->_displayForecast($res);
  34. $this->assertTrue(empty($res));
  35. }
  36. public function _displayForecast($w) {
  37. $res = '';
  38. if (empty($w['request'])) {
  39. return $res;
  40. }
  41. $res .= '<table><tr>';
  42. for ($i = 2; $i < 5; $i++) {
  43. $weather = $w['weather'][$i];
  44. $res .= '<td>';
  45. $res .= '<h1>'.date('D', strtotime($weather['date'])).'</h1>';
  46. $res .= '<div>'.date('M d, Y', strtotime($weather['date'])).'</div>';
  47. $res .= '<h1>'.$this->Weather->Html->image($weather['weatherIconUrl']).'</h1>';
  48. $res .= '<div>'.$weather['tempMinC'].'° - '.$weather['tempMaxC'].'°</div>';
  49. $res .= '<div>'.$weather['weatherDesc'].'</div>';
  50. $res .= '</td>';
  51. }
  52. $res .= '</tr></table>';
  53. return $res;
  54. }
  55. }