GooglLibTest.php 2.3 KB

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