BxDolPrivacyTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. use PHPUnit\Framework\Attributes\DataProvider;
  3. class BxDolPrivacyTestDouble extends BxDolPrivacy
  4. {
  5. public function __construct()
  6. {
  7. }
  8. public function convertActionToFieldPublic($sAction)
  9. {
  10. return $this->convertActionToField($sAction);
  11. }
  12. public function getCheckMethodPublic($s)
  13. {
  14. return $this->getCheckMethod($s);
  15. }
  16. }
  17. /**
  18. * Privacy field and check-method naming.
  19. */
  20. class BxDolPrivacyTest extends \PHPUnit\Framework\TestCase
  21. {
  22. #[DataProvider('providerForConvertActionToField')]
  23. public function testConvertActionToField($sAction, $sField)
  24. {
  25. $o = new BxDolPrivacyTestDouble();
  26. $this->assertSame($sField, $o->convertActionToFieldPublic($sAction));
  27. }
  28. static public function providerForConvertActionToField()
  29. {
  30. return [
  31. ['view', 'allow_view_to'],
  32. ['comment', 'allow_comment_to'],
  33. ['view comments', 'allow_view-comments_to'],
  34. ['View', 'allow_view_to'],
  35. ];
  36. }
  37. #[DataProvider('providerForGetCheckMethod')]
  38. public function testGetCheckMethod($s, $mixedOut)
  39. {
  40. $o = new BxDolPrivacyTestDouble();
  41. $this->assertSame($mixedOut, $o->getCheckMethodPublic($s));
  42. }
  43. static public function providerForGetCheckMethod()
  44. {
  45. return [
  46. ['@foo', 'CheckFoo'],
  47. ['@foo_bar', 'CheckFooBar'],
  48. ['foo', false],
  49. ['check_foo', false],
  50. ];
  51. }
  52. }