BxPersonsConfigTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. use PHPUnit\Framework\Attributes\DataProvider;
  3. /**
  4. * Profile-module config as implemented by Persons (CNF, roles, friends, connections).
  5. */
  6. class BxPersonsConfigTest extends BxPersonsTestCase
  7. {
  8. public function testCnfKeysForProfileModule()
  9. {
  10. $CNF = $this->_oModule->_oConfig->CNF;
  11. $this->assertSame('bx_persons_data', $CNF['TABLE_ENTRIES']);
  12. $this->assertSame('id', $CNF['FIELD_ID']);
  13. $this->assertSame('author', $CNF['FIELD_AUTHOR']);
  14. $this->assertSame('fullname', $CNF['FIELD_NAME']);
  15. $this->assertSame('last_name', $CNF['FIELD_LAST_NAME']);
  16. $this->assertSame('fullname', $CNF['FIELD_TITLE']);
  17. $this->assertSame('description', $CNF['FIELD_TEXT']);
  18. $this->assertSame('picture', $CNF['FIELD_PICTURE']);
  19. $this->assertSame('cover', $CNF['FIELD_COVER']);
  20. $this->assertSame('cover_data', $CNF['FIELD_COVER_POSITION']);
  21. $this->assertSame('badge', $CNF['FIELD_BADGE']);
  22. $this->assertSame('badge_link', $CNF['FIELD_BADGE_LINK']);
  23. $this->assertSame('allow_view_to', $CNF['FIELD_ALLOW_VIEW_TO']);
  24. $this->assertSame('allow_post_to', $CNF['FIELD_ALLOW_POST_TO']);
  25. $this->assertSame('allow_contact_to', $CNF['FIELD_ALLOW_CONTACT_TO']);
  26. $this->assertSame(['fullname', 'last_name'], $CNF['FIELDS_QUICK_SEARCH']);
  27. $this->assertSame('view-persons-profile', $CNF['URI_VIEW_ENTRY']);
  28. $this->assertSame('create-persons-profile', $CNF['URI_ADD_ENTRY']);
  29. $this->assertSame('edit-persons-profile', $CNF['URI_EDIT_ENTRY']);
  30. $this->assertSame('persons-profile-friends', $CNF['URI_VIEW_FRIENDS']);
  31. $this->assertTrue($CNF['BADGES_AVALIABLE']);
  32. }
  33. public function testPrefixesAndJsObjects()
  34. {
  35. $oConfig = $this->_oModule->_oConfig;
  36. $this->assertSame('BxPersonsManageTools', $oConfig->getJsClass('manage_tools'));
  37. $this->assertSame('oBxPersonsManageTools', $oConfig->getJsObject('manage_tools'));
  38. $this->assertSame('bx_persons_common', $oConfig->getGridObject('common'));
  39. $this->assertSame('bx_persons_administration', $oConfig->getGridObject('administration'));
  40. $this->assertSame('', $oConfig->getGridObject('missing'));
  41. }
  42. public function testFriendsFlagMatchesParam()
  43. {
  44. $sKey = $this->_oModule->_oConfig->CNF['PARAM_FRIENDS'];
  45. $this->assertSame(getParam($sKey) == 'on', $this->_oModule->_oConfig->isFriends());
  46. $this->assertSame($this->_oModule->_oConfig->isFriends(), $this->_oModule->serviceIsEnableFriends());
  47. }
  48. public function testRolesDisabledWithoutPreList()
  49. {
  50. $oConfig = $this->_oModule->_oConfig;
  51. $this->assertArrayNotHasKey('OBJECT_PRE_LIST_ROLES', $oConfig->CNF);
  52. $this->assertFalse($oConfig->isRoles());
  53. $this->assertFalse($oConfig->isMultiRoles());
  54. $this->assertFalse($oConfig->getRoles());
  55. }
  56. #[DataProvider('providerForRoleId')]
  57. public function testRoleIdConversion($iId, $sId)
  58. {
  59. $oConfig = $this->_oModule->_oConfig;
  60. $this->assertSame($sId, $oConfig->roleIdI2S($iId));
  61. $this->assertSame($iId, $oConfig->roleIdS2I($sId));
  62. }
  63. static public function providerForRoleId()
  64. {
  65. return [
  66. [1, 'r1'],
  67. [12, 'r12'],
  68. [0, 'r0'],
  69. ];
  70. }
  71. public function testConnectionToFunctionCheck()
  72. {
  73. $a = $this->_oModule->_oConfig->getConnectionToFunctionCheck();
  74. $this->assertSame('checkAllowedFriends', $a['sys_profiles_friends']['friends']);
  75. $this->assertSame('checkAllowedFriendAdd', $a['sys_profiles_friends']['add']);
  76. $this->assertSame('checkAllowedFriendRemove', $a['sys_profiles_friends']['remove']);
  77. $this->assertSame('checkAllowedSubscriptions', $a['sys_profiles_subscriptions']['subscriptions']);
  78. $this->assertSame('checkAllowedSubscribeAdd', $a['sys_profiles_subscriptions']['add']);
  79. $this->assertSame('checkAllowedSubscribeRemove', $a['sys_profiles_subscriptions']['remove']);
  80. }
  81. public function testMenuItemToMethodIncludesProfileActions()
  82. {
  83. $CNF = $this->_oModule->_oConfig->CNF;
  84. $this->assertSame('checkAllowedView', $CNF['MENU_ITEM_TO_METHOD']['bx_persons_view_actions']['view-persons-profile']);
  85. $this->assertSame('checkAllowedEdit', $CNF['MENU_ITEM_TO_METHOD']['bx_persons_view_actions']['edit-persons-profile']);
  86. $this->assertSame('checkAllowedChangeCover', $CNF['MENU_ITEM_TO_METHOD']['bx_persons_view_actions']['edit-persons-cover']);
  87. $this->assertSame('checkAllowedFriendsView', $CNF['MENU_ITEM_TO_METHOD']['bx_persons_view_submenu']['persons-profile-friends']);
  88. }
  89. #[DataProvider('providerForEntryUri')]
  90. public function testGetEntryUri($sAction, $sUri)
  91. {
  92. $this->assertSame($sUri, $this->_oModule->_oConfig->getEntryUri($sAction));
  93. }
  94. static public function providerForEntryUri()
  95. {
  96. return [
  97. ['view', 'view-persons-profile'],
  98. ['add', 'create-persons-profile'],
  99. ['edit', 'edit-persons-profile'],
  100. ['missing', ''],
  101. ];
  102. }
  103. }