summaryrefslogtreecommitdiff
path: root/tests/TestBase.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/TestBase.php')
-rw-r--r--tests/TestBase.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/TestBase.php b/tests/TestBase.php
index 402330b..c0acd58 100644
--- a/tests/TestBase.php
+++ b/tests/TestBase.php
@@ -104,6 +104,34 @@ class TestBase extends PHPUnit_Framework_TestCase
return $uid;
}
+
+
+ /**
+ * Retrieves the UID of an admin user.
+ * If that user does not exist in the database, it is created.
+ *
+ * @return integer UID of admin user
+ */
+ protected function getAdminUser()
+ {
+ if (count($GLOBALS['admin_users']) == 0) {
+ $this->fail('No admin users configured');
+ }
+ $adminUserName = reset($GLOBALS['admin_users']);
+
+ $us = SemanticScuttle_Service_Factory::get('User');
+ $uid = $us->getIdFromUser($adminUserName);
+ if ($uid === null) {
+ //that user does not exist in the database; create it
+ $uid = $us->addUser(
+ $adminUserName,
+ rand(),
+ 'unittest-admin-' . $adminUserName . '@example.org'
+ );
+ }
+
+ return $uid;
+ }
}
?> \ No newline at end of file