Andreas von Burg 3 ani în urmă
părinte
comite
2f680954b6

+ 42 - 0
src-php/test/iplay/controller/ArticleControllerTest.php

@@ -0,0 +1,42 @@
+<?php
+
+namespace iplay\controller;
+
+use PHPUnit\Framework\TestCase;
+use n2n\test\TestEnv;
+
+
+class ArticleControllerTest extends TestCase {
+
+	function setUp(): void {
+		GeneralTestEnv::tearDown();
+
+		$tx = TestEnv::createTransaction();
+
+		$authUser = AuthTestEnv::setUpAuthUser('testerich@von-testen.ch', 'super');
+		$authUser2 = AuthTestEnv::setUpAuthUser('testerine@von-testen.ch', 'super');
+
+		$subCurrency = SubSettingTestEnv::setUpSubCurrency('CHF');
+		$subCountry = SubSettingTestEnv::setUpSubCountry('CH', $subCurrency);
+
+		$subOrganisation = SubAccountTestEnv::setUpSubOrganisation('Super Organisation', $subCountry);
+		$subOrganisation2 = SubAccountTestEnv::setUpSubOrganisation('Super duper Organisation', $subCountry);
+		$deletedSubOrganisation = SubAccountTestEnv::setUpSubOrganisation('Deleted Organisation', $subCountry);
+		$deletedSubOrganisation->setDeletedDateTime(new DateTime());
+
+		ActivityTestEnv::setUpActivity(PgcPlatformId::EVAGIC, $subOrganisation, $authUser);
+		ActivityTestEnv::setUpActivity(PgcPlatformId::HELFEREINSATZ, $subOrganisation, $authUser);
+		ActivityTestEnv::setUpActivity(PgcPlatformId::EVAGIC, $subOrganisation2, $authUser);
+		ActivityTestEnv::setUpActivity(PgcPlatformId::HELFEREINSATZ, $deletedSubOrganisation, $authUser);
+
+		ActivityTestEnv::setUpActivity(PgcPlatformId::EVAGIC, $subOrganisation, $authUser2);
+
+		$tx->commit();
+
+		$this->authUser1PgcId = $authUser->getPgcId();
+		$this->authUser2PgcId = $authUser2->getPgcId();
+
+		$this->subOrganisation1PgcId = $subOrganisation->getPgcId();
+		$this->subOrganisation2PgcId = $subOrganisation2->getPgcId();
+	}
+}

+ 39 - 0
src-php/test/iplay/controller/ArticleTestEnv.php

@@ -0,0 +1,39 @@
+<?php
+namespace pgc\test;
+
+use n2n\test\TestEnv;
+use pgc\sub\setting\bo\SubCountry;
+use pgc\sub\setting\bo\SubCurrency;
+use pgc\sub\plan\bo\SubPlatform;
+
+class ArticleTestEnv  {
+
+
+
+	static function setUpArticle(string $id): Article {
+		$subPlatform = new SubPlatform($id);
+		$subPlatform->setOrderIndex(0);
+		$subPlatform->setOnline(true);
+
+		TestEnv::em()->persist($subPlatform);
+
+		return $subPlatform;
+	}
+
+	static function setUpSubCurrency(string $code): SubCurrency {
+		$currency = new SubCurrency();
+		$currency->setCode($code);
+
+		TestEnv::tem()->persist($currency);
+
+		return $currency;
+	}
+
+	static function setUpSubCountry(string $code, SubCurrency $subCurrency): SubCountry {
+		$country = new SubCountry($code, $subCurrency);
+
+		TestEnv::tem()->persist($country);
+
+		return $country;
+	}
+ }

+ 23 - 0
src-php/test/util/GeneralTestEnv.php

@@ -0,0 +1,23 @@
+<?php
+namespace pgc\test;
+
+use n2n\test\TestEnv;
+use n2n\persistence\PdoStatementException;
+
+class GeneralTestEnv  {
+	
+	static function teardown() {
+		if (TestEnv::container()->tm()->hasOpenTransaction()) {
+			TestEnv::container()->tm()->getRootTransaction()->rollBack();
+		}
+	    TestEnv::em()->clear();
+		\n2n\test\TestEnv::db()->truncate();
+
+		try {
+			\n2n\test\TestEnv::db()->pdo()->exec('DELETE FROM sqlite_sequence');
+		} catch (PdoStatementException $e) {
+		}
+
+		TestEnv::replaceN2nContext();
+	}
+}