WeatherLibTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. App::uses('WeatherLib', 'Tools.Lib');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. class WeatherLibTest extends MyCakeTestCase {
  5. public function setUp() {
  6. parent::setUp();
  7. $this->Weather = new WeatherLib();
  8. $this->skipIf(!Configure::read('Weather.key'));
  9. }
  10. public function testUrl() {
  11. $Weather = new ReflectionMethod('WeatherLib', '_url');
  12. $Weather->setAccessible(true);
  13. $res = $Weather->invoke($this->Weather, 'x.xml');
  14. //$res = $this->Weather->_url('x.xml');
  15. $this->assertEquals(WeatherLib::API_URL_FREE . 'x.xml', $res);
  16. $res = $Weather->invoke($this->Weather, 'x.xml', ['y' => 'z']);
  17. //$res = $this->Weather->_url('x.xml', ['y' => 'z']);
  18. $this->assertEquals(WeatherLib::API_URL_FREE . 'x.xml?y=z', $res);
  19. }
  20. public function testWeatherConditions() {
  21. $res = $this->Weather->conditions();
  22. $this->debug($res);
  23. $this->assertTrue(empty($res));
  24. }
  25. public function testWeather() {
  26. $res = $this->Weather->get('Berlin');
  27. $this->debug($res);
  28. $this->assertTrue(!empty($res));
  29. $this->assertSame('City', $res['request']['type']);
  30. }
  31. public function testWeatherCoords() {
  32. $res = $this->Weather->get('48.2,11.1');
  33. $this->debug($res);
  34. $this->assertTrue(!empty($res));
  35. $this->assertSame('LatLon', $res['request']['type']);
  36. }
  37. }