UserRightsTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
  3. print "This script must be run from the command line\n";
  4. exit();
  5. }
  6. define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
  7. define('GNUSOCIAL', true);
  8. define('STATUSNET', true); // compatibility
  9. require_once INSTALLDIR . '/lib/common.php';
  10. class UserRightsTest extends PHPUnit_Framework_TestCase
  11. {
  12. protected $user = null;
  13. function setUp()
  14. {
  15. $user = User::getKV('nickname', 'userrightstestuser');
  16. if ($user) {
  17. // Leftover from a broken test run?
  18. $profile = $user->getProfile();
  19. $user->delete();
  20. $profile->delete();
  21. }
  22. $this->user = User::register(array('nickname' => 'userrightstestuser'));
  23. if (!$this->user) {
  24. throw new Exception("Couldn't register userrightstestuser");
  25. }
  26. }
  27. function tearDown()
  28. {
  29. if ($this->user) {
  30. $profile = $this->user->getProfile();
  31. $this->user->delete();
  32. $profile->delete();
  33. }
  34. }
  35. function testInvalidRole()
  36. {
  37. $this->assertFalse($this->user->hasRole('invalidrole'));
  38. }
  39. function standardRoles()
  40. {
  41. return array(array('admin'),
  42. array('moderator'));
  43. }
  44. /**
  45. * @dataProvider standardRoles
  46. *
  47. */
  48. function testUngrantedRole($role)
  49. {
  50. $this->assertFalse($this->user->hasRole($role));
  51. }
  52. /**
  53. * @dataProvider standardRoles
  54. *
  55. */
  56. function testGrantedRole($role)
  57. {
  58. $this->user->grantRole($role);
  59. $this->assertTrue($this->user->hasRole($role));
  60. }
  61. }