PluginIssoTest.php 4.2 KB

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