aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndré Noack <noack@data-quest.de>2024-12-12 14:52:00 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2024-12-12 14:52:00 +0000
commit940d2aaa8638b4e0c764579cb3977e7be527c81f (patch)
tree79bd2d7f02359e1bb24931b33513e082f8404a91 /tests
parent3a2a88172ccbe97aaecf4ea32b97cd07b92dcb11 (diff)
StEP 1552 closes #1552
Closes #1552 Merge request studip/studip!1137
Diffstat (limited to 'tests')
-rw-r--r--tests/_support/Helper/Jsonapi.php6
-rw-r--r--tests/jsonapi/SeminarCycleDatesShowTest.php2
-rw-r--r--tests/jsonapi/_bootstrap.php16
-rw-r--r--tests/unit/_bootstrap.php46
-rw-r--r--tests/unit/lib/classes/AvatarClassTest.php2
-rw-r--r--tests/unit/lib/classes/MarkupClassTest.php6
-rw-r--r--tests/unit/lib/classes/MigrationTest.php5
7 files changed, 57 insertions, 26 deletions
diff --git a/tests/_support/Helper/Jsonapi.php b/tests/_support/Helper/Jsonapi.php
index cbb2216..6a31d66 100644
--- a/tests/_support/Helper/Jsonapi.php
+++ b/tests/_support/Helper/Jsonapi.php
@@ -129,12 +129,6 @@ class Jsonapi extends \Codeception\Module
->add(function ($request, $handler) {
$user = $request->getAttribute(Authentication::USER_KEY, null);
- $GLOBALS['auth'] = new \Seminar_Auth();
- $GLOBALS['auth']->auth = [
- 'uid' => $user->id,
- 'uname' => $user->username,
- 'perm' => $user->perms,
- ];
$GLOBALS['user'] = new \Seminar_User($user->id);
$GLOBALS['perm'] = new \Seminar_Perm();
$GLOBALS['MAIL_VALIDATE_BOX'] = false;
diff --git a/tests/jsonapi/SeminarCycleDatesShowTest.php b/tests/jsonapi/SeminarCycleDatesShowTest.php
index 46f8b93..0d2c559 100644
--- a/tests/jsonapi/SeminarCycleDatesShowTest.php
+++ b/tests/jsonapi/SeminarCycleDatesShowTest.php
@@ -51,8 +51,6 @@ class SeminarCycleDatesShowTest extends \Codeception\Test\Unit
$GLOBALS['user'] = new \Seminar_User(
\User::find($credentials['id'])
);
- $GLOBALS['auth'] = new \Seminar_Auth();
- $GLOBALS['auth']->auth = ['uid' => $credentials['id']];
$cycle = \SeminarCycleDate::create(
[
diff --git a/tests/jsonapi/_bootstrap.php b/tests/jsonapi/_bootstrap.php
index 1fc5ba7..5a02ca2 100644
--- a/tests/jsonapi/_bootstrap.php
+++ b/tests/jsonapi/_bootstrap.php
@@ -2,13 +2,14 @@
// Here you can initialize variables that will be available to your tests
-global $STUDIP_BASE_PATH, $ABSOLUTE_URI_STUDIP, $CACHING_ENABLE, $CACHING_FILECACHE_PATH, $SYMBOL_SHORT, $TMP_PATH, $UPLOAD_PATH, $DYNAMIC_CONTENT_PATH, $DYNAMIC_CONTENT_URL;
+global $STUDIP_BASE_PATH, $ABSOLUTE_URI_STUDIP, $CACHING_ENABLE, $CACHING_FILECACHE_PATH, $SYMBOL_SHORT, $TMP_PATH, $UPLOAD_PATH, $DYNAMIC_CONTENT_PATH, $DYNAMIC_CONTENT_URL, $CANONICAL_RELATIVE_PATH_STUDIP;
// common set-up, usually done by lib/bootstraph.php and
// config/config_local.inc.php when run on web server
if (!isset($STUDIP_BASE_PATH)) {
$STUDIP_BASE_PATH = dirname(dirname(__DIR__));
$ABSOLUTE_PATH_STUDIP = $STUDIP_BASE_PATH.'/public/';
+ $CANONICAL_RELATIVE_PATH_STUDIP = '/public/';
$UPLOAD_PATH = $STUDIP_BASE_PATH.'/data/upload_doc';
$TMP_PATH = $TMP_PATH ?: '/tmp';
$DYNAMIC_CONTENT_PATH = '';
@@ -50,17 +51,6 @@ $GLOBALS['_fullname_sql']['full_rev_username'] = "TRIM(CONCAT(Nachname,', ',Vorn
SimpleORMap::expireTableScheme();
-/**
- * @deprecated
- */
-class DB_Seminar extends DB_Sql
-{
- public function __construct($query = false)
- {
- parent::__construct($query);
- }
-}
-
-require_once __DIR__ . '/../../composer/autoload.php';
+require_once __DIR__.'/../../composer/autoload.php';
session_id("test-session");
diff --git a/tests/unit/_bootstrap.php b/tests/unit/_bootstrap.php
index 0cf0f7e..9bc68f5 100644
--- a/tests/unit/_bootstrap.php
+++ b/tests/unit/_bootstrap.php
@@ -51,7 +51,6 @@ require __DIR__ . '/../../composer/autoload.php';
global $STUDIP_BASE_PATH;
$STUDIP_BASE_PATH = realpath(dirname(__DIR__) . '/..');
-require 'lib/helpers.php';
require 'lib/functions.php';
require 'lib/visual.inc.php';
@@ -125,3 +124,48 @@ if (!class_exists('StudipTestHelper')) {
}
}
}
+
+//fake DI
+class StudipFakeDIContainer
+{
+ private $storage;
+ private static $instance;
+
+ public static function getInstance()
+ {
+ if (is_null(self::$instance)) {
+ self::$instance = new self();
+ }
+ return self::$instance;
+ }
+
+ public function get($name)
+ {
+ return $this->storage[$name] ?? null;
+ }
+
+ public function set($name, $object)
+ {
+ $this->storage[$name] = $object;
+ }
+
+ public function make($name, $parameters)
+ {
+ return $this->get($name);
+ }
+}
+
+function app($entryId = null, $parameters = [])
+{
+ $container = StudipFakeDIContainer::getInstance();
+ if (is_null($entryId)) {
+ return $container;
+ }
+
+ return $container->make($entryId, $parameters);
+}
+
+function sess()
+{
+ return app()->get('Studip\Session\Manager');
+}
diff --git a/tests/unit/lib/classes/AvatarClassTest.php b/tests/unit/lib/classes/AvatarClassTest.php
index e09a3c2..51bfab8 100644
--- a/tests/unit/lib/classes/AvatarClassTest.php
+++ b/tests/unit/lib/classes/AvatarClassTest.php
@@ -9,7 +9,7 @@
* the License, or (at your option) any later version.
*/
-require_once 'lib/phplib/Seminar_Perm.php';
+require_once 'lib/classes/Seminar_Perm.php';
abstract class AvatarTest extends \Codeception\Test\Unit
{
diff --git a/tests/unit/lib/classes/MarkupClassTest.php b/tests/unit/lib/classes/MarkupClassTest.php
index 8dad6e9..7342a4a 100644
--- a/tests/unit/lib/classes/MarkupClassTest.php
+++ b/tests/unit/lib/classes/MarkupClassTest.php
@@ -33,9 +33,9 @@ require_once 'lib/classes/Markup.php';
# completely unneeded for testing the Markup class.
# Instead, create a fake class.
# => But note, this will fail if another test case does the same thing!
-class Seminar_Session
+class StudipSessionManager
{
- public static function is_current_session_authenticated()
+ public static function isCurrentSessionAuthenticated()
{
return true;
}
@@ -77,7 +77,7 @@ class MarkupClassTest extends \Codeception\Test\Unit
}));
Config::set($configStub);
-
+ app()->set('Studip\Session\Manager', new StudipSessionManager());
# exceptions
$namespace = 'Studip\MarkupPrivate\MediaProxy\\';
$invalidInternalLink = $namespace . 'InvalidInternalLinkException';
diff --git a/tests/unit/lib/classes/MigrationTest.php b/tests/unit/lib/classes/MigrationTest.php
index 12df120..2e9db08 100644
--- a/tests/unit/lib/classes/MigrationTest.php
+++ b/tests/unit/lib/classes/MigrationTest.php
@@ -19,6 +19,11 @@ class MigrationTest extends \Codeception\Test\Unit
require_once 'lib/migrations/Migration.php';
require_once 'lib/migrations/Migrator.php';
require_once 'lib/migrations/SchemaVersion.php';
+
+ $testconfig = new Config([
+ 'LOG_ENABLE' => false,
+ ]);
+ Config::set($testconfig);
}
public function tearDown(): void