Andreas von Burg 3 anni fa
parent
commit
58da714d80

+ 2 - 0
.gitignore

@@ -1 +1,3 @@
 /.idea/workspace.xml
 /.idea/workspace.xml
+/.idea/shelf
+/src-php/huii.sql

+ 14 - 0
.idea/php-test-framework.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="PhpTestFrameworkVersionCache">
+    <tools_cache>
+      <tool tool_name="PHPUnit">
+        <cache>
+          <versions>
+            <info id="Local" version="9.5.27" />
+          </versions>
+        </cache>
+      </tool>
+    </tools_cache>
+  </component>
+</project>

+ 9 - 0
.idea/php.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
+  <component name="PhpUnit">
+    <phpunit_settings>
+      <PhpUnitSettings custom_loader_path="$PROJECT_DIR$/src-php/vendor/autoload.php" phpunit_phar_path="" />
+    </phpunit_settings>
+  </component>
+</project>

+ 3 - 2
src-php/composer.json → composer.json

@@ -21,15 +21,16 @@
     },
     },
     "autoload" : {
     "autoload" : {
         "psr-4" : {
         "psr-4" : {
-            "custom\\" : "app/custom"
+            "custom\\" : "src-php/app/internship"
         }
         }
     },
     },
     "autoload-dev" : {
     "autoload-dev" : {
         "psr-4" : {
         "psr-4" : {
-            "custom\\" : "test/custom"
+            "custom\\" : "src-php/test/internship"
         }
         }
     },
     },
     "config": {
     "config": {
+        "vendor-dir" : "src-php/vendor",
         "allow-plugins": {
         "allow-plugins": {
             "n2n/n2n-composer-module-installer": true
             "n2n/n2n-composer-module-installer": true
         }
         }

+ 0 - 0
src-php/composer.lock → composer.lock


+ 0 - 45
src-php/composer.master.json

@@ -1,45 +0,0 @@
-{
-    "name": "n2n/n2n-skeleton",
-    "description": "n2n skeleton application installable by Composer",
-    "type": "project",
-    "minimum-stability": "dev",
-    "prefer-stable": true,
-    "require": {
-        "n2n/n2n": "master-dev",
-        "n2n/n2n-batch": "master-dev",
-        "n2n/n2n-context": "master-dev",
-        "n2n/n2n-mail": "master-dev",
-        "n2n/n2n-impl-persistence-meta": "master-dev",
-        "n2n/n2n-impl-persistence-orm": "master-dev",
-        "n2n/n2n-impl-web-dispatch": "master-dev",
-        "n2n/n2n-impl-web-ui": "master-dev",
-        "n2n/rocket": "master-dev",
-        "n2n/page": "master-dev",
-        "hnm/bootstrap": "master-dev",
-        "hnm/ch-hnm-util": "master-dev",
-        "hnm/ci": "master-dev",
-        "hnm/bstmpl": "master-dev",
-	"hnm/simplefile": "master-dev",
-	"hnm/report" : "master-dev"
-    },
-    "require-dev": {
-        "n2n/hangar": "master-dev",
-        "n2n/n2n-test" : "master-dev",
-        "phpunit/phpunit" : "^7.5"
-    },
-    "autoload" : {
-        "psr-4" : {
-            "custom\\" : "app/custom"
-        }
-    },
-    "autoload-dev" : {
-        "psr-4" : {
-            "custom\\" : "test/custom"
-        }
-    },
-    "config": {
-        "allow-plugins": {
-            "n2n/n2n-composer-module-installer": true
-        }
-    }
-}

+ 0 - 45
src-php/composer.stable.json

@@ -1,45 +0,0 @@
-{
-    "name": "n2n/n2n-skeleton",
-    "description": "n2n skeleton application installable by Composer",
-    "type": "project",
-    "minimum-stability": "dev",
-    "prefer-stable": true,
-    "require": {
-        "n2n/n2n": "^7.2.0",
-        "n2n/n2n-batch": "^7.2.0",
-        "n2n/n2n-context": "^7.2.0",
-        "n2n/n2n-mail": "^7.2.0",
-        "n2n/n2n-impl-persistence-meta": "^7.2.0",
-        "n2n/n2n-impl-persistence-orm": "^7.2.0",
-        "n2n/n2n-impl-web-dispatch": "^7.2.0",
-        "n2n/n2n-impl-web-ui": "^7.2.0",
-        "n2n/rocket": "^2.0.0",
-        "n2n/page": "^1.5.0",
-        "hnm/bootstrap": "~1.0.0",
-        "hnm/ch-hnm-util": "^7.2.0",
-        "hnm/ci": "^2.0.0",
-        "hnm/bstmpl": "^2.0.0",
-	"hnm/simplefile": "^1.3.0",
-	"hnm/report" : "^3.0.0"
-    },
-    "require-dev": {
-        "n2n/hangar": "^7.2.0",
-		"n2n/n2n-test" : "^7.2.0",
-		"phpunit/phpunit" : "^7.5"
-    },
-    "autoload" : {
-        "psr-4" : {
-            "custom\\" : "app/custom"
-        }
-    },
-    "autoload-dev" : {
-        "psr-4" : {
-            "custom\\" : "test/custom"
-        }
-    },
-    "config": {
-        "allow-plugins": {
-            "n2n/n2n-composer-module-installer": true
-        }
-    }
-}

+ 45 - 0
src-php/test/internship/controller/ArticleControllerTest.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace internship\controller;
+
+use PHPUnit\Framework\TestCase;
+use n2n\test\TestEnv;
+use intership\test\ArticleTestEnv;
+use util\GeneralTestEnv;
+
+
+class ArticleControllerTest extends TestCase {
+
+	private int $article1Id;
+	private int $article2Id;
+	private int $article3Id;
+
+	function setUp(): void {
+		GeneralTestEnv::tearDown();
+
+		$tx = TestEnv::createTransaction();
+		$article1 = ArticleTestEnv::setUpArticle('Title 1', 'Loren ipsum 1', 'teaser');
+		$article2 = ArticleTestEnv::setUpArticle('Title 2', 'Loren ipsum 2', 'news');
+		$article3 = ArticleTestEnv::setUpArticle('Title 3', 'Loren ipsum 3', 'news');
+		$tx->commit();
+
+		$this->article1Id = $article1->getId();
+		$this->article2Id = $article2->getId();
+		$this->article3Id = $article3->getId();
+	}
+
+	function testGetDoArticles() {
+		$response = TestEnv::http()->newRequest()
+				->get(['api', 'articles'])
+				->exec();
+
+
+		$articleStructs = $response->parseJson();
+		$this->assertCount(3, $articleStructs);
+
+		$this->assertEquals('Title 3', $articleStructs[0]['title']);
+		$this->assertEquals('Title 2', $articleStructs[1]['title']);
+		$this->assertEquals('Title 1', $articleStructs[2]['title']);
+	}
+
+}

+ 20 - 0
src-php/test/internship/test/ArticleTestEnv.php

@@ -0,0 +1,20 @@
+<?php
+namespace internship\test;
+
+use n2n\test\TestEnv;
+use internship\bo\Article;
+
+class ArticleTestEnv  {
+
+	static function setUpArticle(string $title, string $text, string $categoryName): Article {
+		$article = new Article();
+		$article->setTitle($title);
+		$article->setText($text);
+		$article->setCategoryName($categoryName);
+
+		TestEnv::em()->persist($article);
+		TestEnv::em()->flush();
+
+		return $article;
+	}
+ }

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

@@ -1,42 +0,0 @@
-<?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();
-	}
-}

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

@@ -1,39 +0,0 @@
-<?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;
-	}
- }

+ 3 - 3
src-php/test/util/GeneralTestEnv.php

@@ -1,5 +1,5 @@
 <?php
 <?php
-namespace pgc\test;
+namespace util;
 
 
 use n2n\test\TestEnv;
 use n2n\test\TestEnv;
 use n2n\persistence\PdoStatementException;
 use n2n\persistence\PdoStatementException;
@@ -11,10 +11,10 @@ class GeneralTestEnv  {
 			TestEnv::container()->tm()->getRootTransaction()->rollBack();
 			TestEnv::container()->tm()->getRootTransaction()->rollBack();
 		}
 		}
 	    TestEnv::em()->clear();
 	    TestEnv::em()->clear();
-		\n2n\test\TestEnv::db()->truncate();
+		TestEnv::db()->truncate();
 
 
 		try {
 		try {
-			\n2n\test\TestEnv::db()->pdo()->exec('DELETE FROM sqlite_sequence');
+			TestEnv::db()->pdo()->exec('DELETE FROM sqlite_sequence');
 		} catch (PdoStatementException $e) {
 		} catch (PdoStatementException $e) {
 		}
 		}
 
 

+ 7 - 0
src-php/var/etc/app.ini

@@ -104,6 +104,13 @@ default.transaction_isolation_level = "SERIALIZABLE"
 default.dialect = "n2n\impl\persistence\meta\mysql\MysqlDialect"
 default.dialect = "n2n\impl\persistence\meta\mysql\MysqlDialect"
 
 
 
 
+[database : test]
+default.dsn_uri = "sqlite::memory:"
+default.dialect = "n2n\impl\persistence\meta\sqlite\SqliteDialect"
+default.user = ""
+default.password = ""
+
+
 [orm]
 [orm]
 ; entities[] = "example\bo\Example"
 ; entities[] = "example\bo\Example"