GooglLibTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. App::uses('GooglLib', 'Tools.Lib');
  3. /**
  4. * 2010-09-10 ms
  5. */
  6. class GooglLibTest extends CakeTestCase {
  7. public function setUp() {
  8. parent::setUp();
  9. //Configure::write('Googl.key', 'YOUR KEY');
  10. $this->Googl = new GooglLib();
  11. }
  12. public function tearDown() {
  13. parent::tearDown();
  14. unset($this->Googl);
  15. }
  16. //TODO
  17. public function testOAuth() {
  18. }
  19. public function testHistory() {
  20. $this->skipIf(true);
  21. $is = $this->Googl->getHistory();
  22. //pr($is);
  23. die();
  24. }
  25. public function testShortenAndUnshorten() {
  26. //echo '<h2>Shorten without key (publically)</h2>';
  27. Configure::write('Googl.key', '');
  28. $url = 'http://www.spiegel.de';
  29. $is = $this->Googl->getShort($url);
  30. //pr($is);
  31. $res = $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['longUrl'] == $url.'/');
  32. //echo '<h2>Unshorten</h2>';
  33. $shortUrl = $is['id'];
  34. $is = $this->Googl->getLong($shortUrl);
  35. //pr($is);
  36. $res = $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['status'] === 'OK' && $is['longUrl'] == $url.'/');
  37. }
  38. public function testApi() {
  39. $this->skipIf(!Configure::write('Googl.key'), 'No Api Key found');
  40. //echo '<h2>Shorten with key</h2>';
  41. $url = 'http://www.gmx.de';
  42. $is = $this->Googl->getShort($url);
  43. //pr($is);
  44. $res = $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['longUrl'] == $url.'/');
  45. //echo '<h2>Unshorten</h2>';
  46. $shortUrl = $is['id'];
  47. $is = $this->Googl->getLong($shortUrl);
  48. //pr($is);
  49. $res = $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['status'] === 'OK' && $is['longUrl'] == $url.'/');
  50. //echo '<h2>FULL INFOS</h2>';
  51. $url = 'http://www.web.de#123456';
  52. $is = $this->Googl->getShort($url);
  53. //debug($is);
  54. $res = $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['longUrl'] === 'http://www.web.de/#123456');
  55. $shortUrl = $is['id'];
  56. $is = $this->Googl->getLong($shortUrl, GooglLib::PROJECTION_CLICKS);
  57. //debug($is);
  58. $res = $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['status'] === 'OK' && $is['longUrl'] === 'http://www.web.de/#123456');
  59. }
  60. }