PluginReadityourselfTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * PluginReadityourselfTest.php.php
  4. */
  5. require_once 'plugins/readityourself/readityourself.php';
  6. /**
  7. * Class PluginWallabagTest
  8. * Unit test for the Wallabag plugin
  9. */
  10. class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
  11. {
  12. /**
  13. * Reset plugin path
  14. */
  15. public function setUp()
  16. {
  17. PluginManager::$PLUGINS_PATH = 'plugins';
  18. }
  19. /**
  20. * Test Readityourself init without errors.
  21. */
  22. public function testReadityourselfInitNoError()
  23. {
  24. $conf = new ConfigManager('');
  25. $conf->set('plugins.READITYOUSELF_URL', 'value');
  26. $errors = readityourself_init($conf);
  27. $this->assertEmpty($errors);
  28. }
  29. /**
  30. * Test Readityourself init with errors.
  31. */
  32. public function testReadityourselfInitError()
  33. {
  34. $conf = new ConfigManager('');
  35. $errors = readityourself_init($conf);
  36. $this->assertNotEmpty($errors);
  37. }
  38. /**
  39. * Test render_linklist hook.
  40. */
  41. public function testReadityourselfLinklist()
  42. {
  43. $conf = new ConfigManager('');
  44. $conf->set('plugins.READITYOUSELF_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_readityourself_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], $str));
  62. }
  63. /**
  64. * Test without config: nothing should happened.
  65. */
  66. public function testReadityourselfLinklistWithoutConfig()
  67. {
  68. $conf = new ConfigManager('');
  69. $conf->set('plugins.READITYOUSELF_URL', null);
  70. $str = 'http://randomstr.com/test';
  71. $data = array(
  72. 'title' => $str,
  73. 'links' => array(
  74. array(
  75. 'url' => $str,
  76. )
  77. )
  78. );
  79. $data = hook_readityourself_render_linklist($data, $conf);
  80. $link = $data['links'][0];
  81. // data shouldn't be altered
  82. $this->assertEquals($str, $data['title']);
  83. $this->assertEquals($str, $link['url']);
  84. // plugin data
  85. $this->assertArrayNotHasKey('link_plugin', $link);
  86. }
  87. }