PrivacyCheckGroupIdTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. use PHPUnit\Framework\Attributes\Group;
  3. /**
  4. * BxDolPrivacy::_check() with stored privacy values that are not a valid group.
  5. * An empty value used to reach checkSpace(), where negating '' throws a TypeError
  6. * under PHP 8 and took down every page that checked it (the timeline feed among them).
  7. */
  8. #[Group('integration')]
  9. class PrivacyCheckGroupIdTest extends BxDolIntegrationTestCase
  10. {
  11. private const OWNER_ID = 2147483000;
  12. private function privacy(): BxDolPrivacy
  13. {
  14. $sObject = BxDolDb::getInstance()->getOne("SELECT `object` FROM `sys_objects_privacy` ORDER BY `id` LIMIT 1");
  15. if (!$sObject)
  16. $this->markTestSkipped('No privacy objects are installed.');
  17. $oPrivacy = BxDolPrivacy::getObjectInstance($sObject);
  18. if (!$oPrivacy)
  19. $this->markTestSkipped('Privacy object ' . $sObject . ' did not load.');
  20. return $oPrivacy;
  21. }
  22. private function check(BxDolPrivacy $oPrivacy, $mixedGroupId): bool
  23. {
  24. $oMethod = new ReflectionMethod($oPrivacy, '_check');
  25. return $oMethod->invoke($oPrivacy, 1, 0, ['group_id' => $mixedGroupId, 'owner_id' => self::OWNER_ID]);
  26. }
  27. public function testEmptyGroupIdDeniesWithoutError(): void
  28. {
  29. $this->assertFalse($this->check($this->privacy(), ''));
  30. }
  31. public function testNonNumericGroupIdDeniesWithoutError(): void
  32. {
  33. $this->assertFalse($this->check($this->privacy(), 'x'));
  34. }
  35. public function testMissingSpaceDenies(): void
  36. {
  37. $this->assertFalse($this->check($this->privacy(), (string)-self::OWNER_ID));
  38. }
  39. public function testPublicGroupAsStringStillAllows(): void
  40. {
  41. $this->assertTrue($this->check($this->privacy(), (string)BX_DOL_PG_ALL));
  42. }
  43. }