PluginIssoTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. require_once 'plugins/isso/isso.php';
  3. /**
  4. * Class PluginIssoTest
  5. *
  6. * Test the Isso plugin (comment system).
  7. */
  8. class PluginIssoTest extends PHPUnit_Framework_TestCase
  9. {
  10. /**
  11. * Reset plugin path
  12. */
  13. function setUp()
  14. {
  15. PluginManager::$PLUGINS_PATH = 'plugins';
  16. }
  17. /**
  18. * Test Isso init without errors.
  19. */
  20. function testWallabagInitNoError()
  21. {
  22. $conf = new ConfigManager('');
  23. $conf->set('plugins.ISSO_SERVER', 'value');
  24. $errors = isso_init($conf);
  25. $this->assertEmpty($errors);
  26. }
  27. /**
  28. * Test Isso init with errors.
  29. */
  30. function testWallabagInitError()
  31. {
  32. $conf = new ConfigManager('');
  33. $errors = isso_init($conf);
  34. $this->assertNotEmpty($errors);
  35. }
  36. /**
  37. * Test render_linklist hook with valid settings to display the comment form.
  38. */
  39. function testIssoDisplayed()
  40. {
  41. $conf = new ConfigManager('');
  42. $conf->set('plugins.ISSO_SERVER', 'value');
  43. $str = 'http://randomstr.com/test';
  44. $data = array(
  45. 'title' => $str,
  46. 'links' => array(
  47. array(
  48. 'url' => $str,
  49. 'linkdate' => 'abc',
  50. )
  51. )
  52. );
  53. $data = hook_isso_render_linklist($data, $conf);
  54. // data shouldn't be altered
  55. $this->assertEquals($str, $data['title']);
  56. $this->assertEquals($str, $data['links'][0]['url']);
  57. // plugin data
  58. $this->assertEquals(1, count($data['plugin_end_zone']));
  59. $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'abc'));
  60. $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
  61. }
  62. /**
  63. * Test isso plugin when multiple links are displayed (shouldn't be displayed).
  64. */
  65. function testIssoMultipleLinks()
  66. {
  67. $conf = new ConfigManager('');
  68. $conf->set('plugins.ISSO_SERVER', 'value');
  69. $str = 'http://randomstr.com/test';
  70. $data = array(
  71. 'title' => $str,
  72. 'links' => array(
  73. array(
  74. 'url' => $str,
  75. 'linkdate' => 'abc',
  76. ),
  77. array(
  78. 'url' => $str . '2',
  79. 'linkdate' => 'abc2',
  80. ),
  81. )
  82. );
  83. $processed = hook_isso_render_linklist($data, $conf);
  84. // data shouldn't be altered
  85. $this->assertEquals($data, $processed);
  86. }
  87. /**
  88. * Test isso plugin when using search (shouldn't be displayed).
  89. */
  90. function testIssoNotDisplayedWhenSearch()
  91. {
  92. $conf = new ConfigManager('');
  93. $conf->set('plugins.ISSO_SERVER', 'value');
  94. $str = 'http://randomstr.com/test';
  95. $data = array(
  96. 'title' => $str,
  97. 'links' => array(
  98. array(
  99. 'url' => $str,
  100. 'linkdate' => 'abc',
  101. )
  102. ),
  103. 'search_term' => $str
  104. );
  105. $processed = hook_isso_render_linklist($data, $conf);
  106. // data shouldn't be altered
  107. $this->assertEquals($data, $processed);
  108. }
  109. /**
  110. * Test isso plugin without server configuration (shouldn't be displayed).
  111. */
  112. function testIssoWithoutConf()
  113. {
  114. $data = 'abc';
  115. $conf = new ConfigManager('');
  116. $processed = hook_isso_render_linklist($data, $conf);
  117. $this->assertEquals($data, $processed);
  118. }
  119. }