BxPostsConfigTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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->assertTrue($CNF['PARAM_LINKS_ENABLED']);
  22. $this->assertTrue($CNF['PARAM_MULTICAT_ENABLED']);
  23. $this->assertTrue($CNF['PARAM_POLL_ENABLED']);
  24. }
  25. public function testAttachLinksAndTimelineAttachments()
  26. {
  27. $oConfig = $this->_oModule->_oConfig;
  28. $this->assertTrue($oConfig->isAttachLinks());
  29. $this->assertTrue($oConfig->isAttachmentsInTimeline());
  30. $this->assertTrue($oConfig->isAutoApprove());
  31. $this->assertSame(3600, $oConfig->getDpnTime());
  32. }
  33. public function testPrefixesAndJsObjects()
  34. {
  35. $oConfig = $this->_oModule->_oConfig;
  36. $this->assertSame('bx-posts', $oConfig->getPrefix('style'));
  37. $this->assertSame('BxPostsPolls', $oConfig->getJsClass('poll'));
  38. $this->assertSame('oBxPostsPolls', $oConfig->getJsObject('poll'));
  39. $this->assertSame('oBxPostsPollsAdd', $oConfig->getJsObjectPoll(0));
  40. $this->assertSame('oBxPostsPollsEdit12', $oConfig->getJsObjectPoll(12));
  41. $this->assertSame('bx_posts_common', $oConfig->getGridObject('common'));
  42. $this->assertSame('bx_posts_administration', $oConfig->getGridObject('administration'));
  43. $this->assertSame('', $oConfig->getGridObject('missing'));
  44. $this->assertSame('', $oConfig->getJsClass('missing'));
  45. }
  46. public function testHtmlIds()
  47. {
  48. $oConfig = $this->_oModule->_oConfig;
  49. $this->assertSame('bx-posts-attach-link-popup', $oConfig->getHtmlIds('attach_link_popup'));
  50. $this->assertSame('bx-posts-add-poll-popup', $oConfig->getHtmlIds('add_poll_popup'));
  51. $this->assertSame('', $oConfig->getHtmlIds('missing'));
  52. $this->assertIsArray($oConfig->getHtmlIds());
  53. }
  54. #[DataProvider('providerForEqualUrls')]
  55. public function testIsEqualUrls($sLeft, $sRight, $bOut)
  56. {
  57. $this->assertSame($bOut, $this->_oModule->_oConfig->isEqualUrls($sLeft, $sRight));
  58. }
  59. static public function providerForEqualUrls()
  60. {
  61. return [
  62. ['page.php?i=view-post', 'page.php?i=view-post', true],
  63. ['page.php?i=view-post/', 'page.php?i=view-post', true],
  64. ['page.php?i=view-post', 'page.php?i=view-post&id=1', true],
  65. ['page.php?i=view-post', 'page.php?i=posts-home', false],
  66. ];
  67. }
  68. #[DataProvider('providerForEntryUri')]
  69. public function testGetEntryUri($sAction, $sUri)
  70. {
  71. $this->assertSame($sUri, $this->_oModule->_oConfig->getEntryUri($sAction));
  72. }
  73. static public function providerForEntryUri()
  74. {
  75. return [
  76. ['view', 'view-post'],
  77. ['add', 'create-post'],
  78. ['edit', 'edit-post'],
  79. ['missing', ''],
  80. ];
  81. }
  82. public function testGetViewEntryUrl()
  83. {
  84. $oConfig = $this->_oModule->_oConfig;
  85. $this->assertSame('', $oConfig->getViewEntryUrl('x'));
  86. $this->assertSame('', $oConfig->getViewEntryUrl([]));
  87. $sFromId = $oConfig->getViewEntryUrl(15);
  88. $sFromRow = $oConfig->getViewEntryUrl(['id' => 15]);
  89. $this->assertNotSame('', $sFromId);
  90. $this->assertSame($sFromId, $sFromRow);
  91. }
  92. public function testGetImageUrlEmpty()
  93. {
  94. $this->assertSame('', $this->_oModule->_oConfig->getImageUrl(0, ['OBJECT_IMAGES_TRANSCODER_PREVIEW']));
  95. $this->assertSame('', $this->_oModule->_oConfig->getImageUrl(1, []));
  96. }
  97. public function testPregPatterns()
  98. {
  99. $oConfig = $this->_oModule->_oConfig;
  100. $this->assertSame(1, preg_match($oConfig->getPregPattern('meta_title'), '<title>Hello</title>', $a));
  101. $this->assertSame('Hello', $a[1]);
  102. $this->assertSame(1, preg_match($oConfig->getPregPattern('url'), 'https://example.com/path?q=1'));
  103. }
  104. }