PluginIssoTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. $date = '20161118_100001';
  45. $data = array(
  46. 'title' => $str,
  47. 'links' => array(
  48. array(
  49. 'id' => 12,
  50. 'url' => $str,
  51. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
  52. )
  53. )
  54. );
  55. $data = hook_isso_render_linklist($data, $conf);
  56. // data shouldn't be altered
  57. $this->assertEquals($str, $data['title']);
  58. $this->assertEquals($str, $data['links'][0]['url']);
  59. // plugin data
  60. $this->assertEquals(1, count($data['plugin_end_zone']));
  61. $this->assertNotFalse(strpos(
  62. $data['plugin_end_zone'][0],
  63. 'data-isso-id="'. $data['links'][0]['id'] .'"'
  64. ));
  65. $this->assertNotFalse(strpos(
  66. $data['plugin_end_zone'][0],
  67. 'data-title="'. $data['links'][0]['id'] .'"'
  68. ));
  69. $this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
  70. }
  71. /**
  72. * Test isso plugin when multiple links are displayed (shouldn't be displayed).
  73. */
  74. function testIssoMultipleLinks()
  75. {
  76. $conf = new ConfigManager('');
  77. $conf->set('plugins.ISSO_SERVER', 'value');
  78. $str = 'http://randomstr.com/test';
  79. $date1 = '20161118_100001';
  80. $date2 = '20161118_100002';
  81. $data = array(
  82. 'title' => $str,
  83. 'links' => array(
  84. array(
  85. 'id' => 12,
  86. 'url' => $str,
  87. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1),
  88. ),
  89. array(
  90. 'id' => 13,
  91. 'url' => $str . '2',
  92. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2),
  93. ),
  94. )
  95. );
  96. $processed = hook_isso_render_linklist($data, $conf);
  97. // data shouldn't be altered
  98. $this->assertEquals($data, $processed);
  99. }
  100. /**
  101. * Test isso plugin when using search (shouldn't be displayed).
  102. */
  103. function testIssoNotDisplayedWhenSearch()
  104. {
  105. $conf = new ConfigManager('');
  106. $conf->set('plugins.ISSO_SERVER', 'value');
  107. $str = 'http://randomstr.com/test';
  108. $date = '20161118_100001';
  109. $data = array(
  110. 'title' => $str,
  111. 'links' => array(
  112. array(
  113. 'id' => 12,
  114. 'url' => $str,
  115. 'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
  116. )
  117. ),
  118. 'search_term' => $str
  119. );
  120. $processed = hook_isso_render_linklist($data, $conf);
  121. // data shouldn't be altered
  122. $this->assertEquals($data, $processed);
  123. }
  124. /**
  125. * Test isso plugin without server configuration (shouldn't be displayed).
  126. */
  127. function testIssoWithoutConf()
  128. {
  129. $data = 'abc';
  130. $conf = new ConfigManager('');
  131. $processed = hook_isso_render_linklist($data, $conf);
  132. $this->assertEquals($data, $processed);
  133. }
  134. }