PluginWallabagTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * PluginWallabagTest.php.php
  4. */
  5. require_once 'plugins/wallabag/wallabag.php';
  6. /**
  7. * Class PluginWallabagTest
  8. * Unit test for the Wallabag plugin
  9. */
  10. class PluginWallabagTest extends PHPUnit_Framework_TestCase
  11. {
  12. /**
  13. * Reset plugin path
  14. */
  15. function setUp()
  16. {
  17. PluginManager::$PLUGINS_PATH = 'plugins';
  18. }
  19. /**
  20. * Test wallabag init without errors.
  21. */
  22. function testWallabagInitNoError()
  23. {
  24. $conf = new ConfigManager('');
  25. $conf->set('plugins.WALLABAG_URL', 'value');
  26. $errors = wallabag_init($conf);
  27. $this->assertEmpty($errors);
  28. }
  29. /**
  30. * Test wallabag init with errors.
  31. */
  32. function testWallabagInitError()
  33. {
  34. $conf = new ConfigManager('');
  35. $errors = wallabag_init($conf);
  36. $this->assertNotEmpty($errors);
  37. }
  38. /**
  39. * Test render_linklist hook.
  40. */
  41. function testWallabagLinklist()
  42. {
  43. $conf = new ConfigManager('');
  44. $conf->set('plugins.WALLABAG_URL', 'value');
  45. $str = 'http://randomstr.com/test';
  46. $data = array(
  47. 'title' => $str,
  48. 'links' => array(
  49. array(
  50. 'url' => $str,
  51. )
  52. )
  53. );
  54. $data = hook_wallabag_render_linklist($data, $conf);
  55. $link = $data['links'][0];
  56. // data shouldn't be altered
  57. $this->assertEquals($str, $data['title']);
  58. $this->assertEquals($str, $link['url']);
  59. // plugin data
  60. $this->assertEquals(1, count($link['link_plugin']));
  61. $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str)));
  62. $this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL')));
  63. }
  64. }