BxPostsConfigTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. use PHPUnit\Framework\Attributes\DataProvider;
  3. /**
  4. * Content-module config as implemented by Posts (CNF, prefixes, URLs, attach flags).
  5. */
  6. class BxPostsConfigTest extends BxPostsTestCase
  7. {
  8. public function testCnfKeysForContentModule()
  9. {
  10. $CNF = $this->_oModule->_oConfig->CNF;
  11. $this->assertSame('bx_posts_posts', $CNF['TABLE_ENTRIES']);
  12. $this->assertSame('id', $CNF['FIELD_ID']);
  13. $this->assertSame('author', $CNF['FIELD_AUTHOR']);
  14. $this->assertSame('title', $CNF['FIELD_TITLE']);
  15. $this->assertSame('text', $CNF['FIELD_TEXT']);
  16. $this->assertSame('published', $CNF['FIELD_PUBLISHED']);
  17. $this->assertSame('allow_comments', $CNF['FIELD_ALLOW_COMMENTS']);
  18. $this->assertSame('view-post', $CNF['URI_VIEW_ENTRY']);
  19. $this->assertSame('create-post', $CNF['URI_ADD_ENTRY']);
  20. $this->assertSame('edit-post', $CNF['URI_EDIT_ENTRY']);
  21. $this->assertSame('file-alt', $CNF['ICON']);
  22. $this->assertTrue($CNF['PARAM_LINKS_ENABLED']);
  23. $this->assertTrue($CNF['PARAM_MULTICAT_ENABLED']);
  24. $this->assertTrue($CNF['PARAM_POLL_ENABLED']);
  25. }
  26. public function testAttachLinksAndTimelineAttachments()
  27. {
  28. $oConfig = $this->_oModule->_oConfig;
  29. $this->assertTrue($oConfig->isAttachLinks());
  30. $this->assertTrue($oConfig->isAttachmentsInTimeline());
  31. $this->assertTrue($oConfig->isAutoApprove());
  32. $this->assertSame(3600, $oConfig->getDpnTime());
  33. }
  34. public function testPrefixesAndJsObjects()
  35. {
  36. $oConfig = $this->_oModule->_oConfig;
  37. $this->assertSame('bx-posts', $oConfig->getPrefix('style'));
  38. $this->assertSame('BxPostsPolls', $oConfig->getJsClass('poll'));
  39. $this->assertSame('oBxPostsPolls', $oConfig->getJsObject('poll'));
  40. $this->assertSame('oBxPostsPollsAdd', $oConfig->getJsObjectPoll(0));
  41. $this->assertSame('oBxPostsPollsEdit12', $oConfig->getJsObjectPoll(12));
  42. $this->assertSame('bx_posts_common', $oConfig->getGridObject('common'));
  43. $this->assertSame('bx_posts_administration', $oConfig->getGridObject('administration'));
  44. $this->assertSame('', $oConfig->getGridObject('missing'));
  45. $this->assertSame('', $oConfig->getJsClass('missing'));
  46. }
  47. public function testHtmlIds()
  48. {
  49. $oConfig = $this->_oModule->_oConfig;
  50. $this->assertSame('bx-posts-attach-link-popup', $oConfig->getHtmlIds('attach_link_popup'));
  51. $this->assertSame('bx-posts-add-poll-popup', $oConfig->getHtmlIds('add_poll_popup'));
  52. $this->assertSame('', $oConfig->getHtmlIds('missing'));
  53. $this->assertIsArray($oConfig->getHtmlIds());
  54. }
  55. #[DataProvider('providerForEqualUrls')]
  56. public function testIsEqualUrls($sLeft, $sRight, $bOut)
  57. {
  58. $this->assertSame($bOut, $this->_oModule->_oConfig->isEqualUrls($sLeft, $sRight));
  59. }
  60. static public function providerForEqualUrls()
  61. {
  62. return [
  63. ['page.php?i=view-post', 'page.php?i=view-post', true],
  64. ['page.php?i=view-post/', 'page.php?i=view-post', true],
  65. ['page.php?i=view-post', 'page.php?i=view-post&id=1', true],
  66. ['page.php?i=view-post', 'page.php?i=posts-home', false],
  67. ];
  68. }
  69. #[DataProvider('providerForEntryUri')]
  70. public function testGetEntryUri($sAction, $sUri)
  71. {
  72. $this->assertSame($sUri, $this->_oModule->_oConfig->getEntryUri($sAction));
  73. }
  74. static public function providerForEntryUri()
  75. {
  76. return [
  77. ['view', 'view-post'],
  78. ['add', 'create-post'],
  79. ['edit', 'edit-post'],
  80. ['missing', ''],
  81. ];
  82. }
  83. public function testGetViewEntryUrl()
  84. {
  85. $oConfig = $this->_oModule->_oConfig;
  86. $this->assertSame('', $oConfig->getViewEntryUrl('x'));
  87. $this->assertSame('', $oConfig->getViewEntryUrl([]));
  88. $sFromId = $oConfig->getViewEntryUrl(15);
  89. $sFromRow = $oConfig->getViewEntryUrl(['id' => 15]);
  90. $this->assertNotSame('', $sFromId);
  91. $this->assertSame($sFromId, $sFromRow);
  92. }
  93. public function testGetImageUrlEmpty()
  94. {
  95. $this->assertSame('', $this->_oModule->_oConfig->getImageUrl(0, ['OBJECT_IMAGES_TRANSCODER_PREVIEW']));
  96. $this->assertSame('', $this->_oModule->_oConfig->getImageUrl(1, []));
  97. }
  98. public function testPregPatterns()
  99. {
  100. $oConfig = $this->_oModule->_oConfig;
  101. $this->assertSame(1, preg_match($oConfig->getPregPattern('meta_title'), '<title>Hello</title>', $a));
  102. $this->assertSame('Hello', $a[1]);
  103. $this->assertSame(1, preg_match($oConfig->getPregPattern('url'), 'https://example.com/path?q=1'));
  104. }
  105. }