]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - tests/UserRightsTest.php
user rights
[quix0rs-gnu-social.git] / tests / UserRightsTest.php
diff --git a/tests/UserRightsTest.php b/tests/UserRightsTest.php
new file mode 100644 (file)
index 0000000..6544ee5
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+    print "This script must be run from the command line\n";
+    exit();
+}
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('STATUSNET', true);
+
+require_once INSTALLDIR . '/lib/common.php';
+
+class UserRightsTest extends PHPUnit_Framework_TestCase
+{
+    protected $user = null;
+
+    function setUp()
+    {
+        $this->user = User::register(array('nickname' => 'userrightstestuser'));
+    }
+
+    function tearDown()
+    {
+        $profile = $this->user->getProfile();
+        $this->user->delete();
+        $profile->delete();
+    }
+
+    function testInvalidRole()
+    {
+        $this->assertFalse($this->user->hasRole('invalidrole'));
+    }
+
+    function standardRoles()
+    {
+        return array('admin', 'moderator');
+    }
+
+    /**
+     * @dataProvider standardRoles
+     *
+     */
+
+    function testUngrantedRole($role)
+    {
+        $this->assertFalse($this->user->hasRole($role));
+    }
+
+    /**
+     * @dataProvider standardRoles
+     *
+     */
+
+    function testGrantedRole($role)
+    {
+        $this->user->grantRole($role);
+        $this->assertFalse($this->user->hasRole($role));
+    }
+}
\ No newline at end of file