PluginWallabagTest.php 1.8 KB

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