GooglLibTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /**
  25. * GooglLibTest::testShortenAndUnshorten()
  26. *
  27. * @return void
  28. */
  29. public function testShortenAndUnshorten() {
  30. //echo '<h2>Shorten without key (publically)</h2>';
  31. Configure::write('Googl.key', '');
  32. $url = 'http://www.spiegel.de';
  33. $is = $this->Googl->getShort($url);
  34. //pr($is);
  35. $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['longUrl'] == $url . '/');
  36. //echo '<h2>Unshorten</h2>';
  37. $shortUrl = $is['id'];
  38. $is = $this->Googl->getLong($shortUrl);
  39. $this->assertTrue(!empty($is));
  40. $this->assertTrue(!empty($is['id']));
  41. $this->assertSame('urlshortener#url', $is['kind']);
  42. $this->assertSame('OK', $is['status']);
  43. $this->assertSame($url . '/', $is['longUrl']);
  44. }
  45. /**
  46. * GooglLibTest::testApi()
  47. *
  48. * @return void
  49. */
  50. public function testApi() {
  51. $this->skipIf(!Configure::write('Googl.key'), 'No Api Key found');
  52. //echo '<h2>Shorten with key</h2>';
  53. $url = 'http://www.blue.de';
  54. $is = $this->Googl->getShort($url);
  55. $res = $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['longUrl'] == $url . '/');
  56. //echo '<h2>Unshorten</h2>';
  57. $shortUrl = $is['id'];
  58. $is = $this->Googl->getLong($shortUrl);
  59. //pr($is);
  60. $res = $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['status'] === 'OK' && $is['longUrl'] == $url . '/');
  61. //echo '<h2>FULL INFOS</h2>';
  62. $url = 'http://www.web.de#123456';
  63. $is = $this->Googl->getShort($url);
  64. //debug($is);
  65. $res = $this->assertTrue(!empty($is) && is_array($is) && !empty($is['id']) && $is['kind'] === 'urlshortener#url' && $is['longUrl'] === 'http://www.web.de/#123456');
  66. $shortUrl = $is['id'];
  67. $is = $this->Googl->getLong($shortUrl, GooglLib::PROJECTION_CLICKS);
  68. //debug($is);
  69. $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');
  70. }
  71. }