GooglLibTest.php 2.3 KB

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