]> git.mxchange.org Git - friendica.git/commitdiff
[Tests] Extract fixture logic from ApiTest
authorHypolite Petovan <hypolite@mrpetovan.com>
Tue, 9 Jun 2020 12:38:31 +0000 (08:38 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 9 Jun 2020 12:38:31 +0000 (08:38 -0400)
- Reorder frio scheme tests to avoid PConfig persistence side-effect

tests/FixtureTest.php [new file with mode: 0644]
tests/include/ApiTest.php

diff --git a/tests/FixtureTest.php b/tests/FixtureTest.php
new file mode 100644 (file)
index 0000000..74abfdd
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * FixtureTest class.
+ */
+
+namespace Friendica\Test;
+
+use Dice\Dice;
+use Friendica\Core\Config\Cache;
+use Friendica\Core\Config\IConfig;
+use Friendica\Core\Session;
+use Friendica\Core\Session\ISession;
+use Friendica\Database\Database;
+use Friendica\Database\DBStructure;
+use Friendica\DI;
+use Friendica\Test\Util\Database\StaticDatabase;
+
+/**
+ * Parent class for test cases requiring fixtures
+ */
+abstract class FixtureTest extends DatabaseTest
+{
+       /** @var Dice */
+       protected $dice;
+
+       /**
+        * Create variables used by tests.
+        */
+       protected function setUp()
+       {
+               parent::setUp();
+
+               $this->dice = (new Dice())
+                       ->addRules(include __DIR__ . '/../static/dependencies.config.php')
+                       ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
+                       ->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
+               DI::init($this->dice);
+
+               /** @var IConfig $config */
+               $configCache = $this->dice->create(Cache::class);
+               $configCache->set('database', 'disable_pdo', true);
+
+               /** @var Database $dba */
+               $dba = $this->dice->create(Database::class);
+
+               $dba->setTestmode(true);
+
+               DBStructure::checkInitialValues();
+
+               // Load the API dataset for the whole API
+               $this->loadFixture(__DIR__ . '/datasets/api.fixture.php', $dba);
+       }
+}
index e12b0cdd7d32d682ad2efdc30af44884f0fc8208..cce0541aa93ceb5998f532b79c497530586e92e0 100644 (file)
@@ -5,19 +5,12 @@
 
 namespace Friendica\Test;
 
-use Dice\Dice;
 use Friendica\App;
 use Friendica\Core\Config\IConfig;
 use Friendica\Core\PConfig\IPConfig;
 use Friendica\Core\Protocol;
-use Friendica\Core\Session;
-use Friendica\Core\Session\ISession;
-use Friendica\Database\Database;
-use Friendica\Database\DBStructure;
 use Friendica\DI;
-use Friendica\Model\Contact;
 use Friendica\Network\HTTPException;
-use Friendica\Test\Util\Database\StaticDatabase;
 use Friendica\Util\Temporal;
 use Monolog\Handler\TestHandler;
 
@@ -29,7 +22,7 @@ require_once __DIR__ . '/../../include/api.php';
  * Functions that use header() need to be tested in a separate process.
  * @see https://phpunit.de/manual/5.7/en/appendixes.annotations.html#appendixes.annotations.runTestsInSeparateProcesses
  */
-class ApiTest extends DatabaseTest
+class ApiTest extends FixtureTest
 {
        /**
         * @var TestHandler Can handle log-outputs
@@ -51,9 +44,6 @@ class ApiTest extends DatabaseTest
        /** @var IConfig */
        protected $config;
 
-       /** @var Dice */
-       protected $dice;
-
        /**
         * Create variables used by tests.
         */
@@ -61,19 +51,6 @@ class ApiTest extends DatabaseTest
        {
                parent::setUp();
 
-               $this->dice = (new Dice())
-                       ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
-                       ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
-                       ->addRule(ISession::class, ['instanceOf' => Session\Memory::class, 'shared' => true, 'call' => null]);
-               DI::init($this->dice);
-
-               /** @var Database $dba */
-               $dba = $this->dice->create(Database::class);
-
-               $dba->setTestmode(true);
-
-               DBStructure::checkInitialValues();
-
                /** @var IConfig $config */
                $this->config = $this->dice->create(IConfig::class);
 
@@ -88,8 +65,6 @@ class ApiTest extends DatabaseTest
                $this->config->set('system', 'throttle_limit_month', 100);
                $this->config->set('system', 'theme', 'system_theme');
 
-               // Load the API dataset for the whole API
-               $this->loadFixture(__DIR__ . '/../datasets/api.fixture.php', $dba);
 
                /** @var App app */
                $this->app = DI::app();
@@ -842,38 +817,38 @@ class ApiTest extends DatabaseTest
        }
 
        /**
-        * Test the api_get_user() function with a custom Frio schema.
+        * Test the api_get_user() function with an empty Frio schema.
         *
         * @return void
         */
-       public function testApiGetUserWithCustomFrioSchema()
+       public function testApiGetUserWithEmptyFrioSchema()
        {
                $pConfig = $this->dice->create(IPConfig::class);
                $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
-               $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
-               $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
-               $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
                $user = api_get_user($this->app);
                $this->assertSelfUser($user);
-               $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
-               $this->assertEquals('123456', $user['profile_link_color']);
-               $this->assertEquals('123456', $user['profile_background_color']);
+               $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
+               $this->assertEquals('6fdbe8', $user['profile_link_color']);
+               $this->assertEquals('ededed', $user['profile_background_color']);
        }
 
        /**
-        * Test the api_get_user() function with an empty Frio schema.
+        * Test the api_get_user() function with a custom Frio schema.
         *
         * @return void
         */
-       public function testApiGetUserWithEmptyFrioSchema()
+       public function testApiGetUserWithCustomFrioSchema()
        {
                $pConfig = $this->dice->create(IPConfig::class);
                $pConfig->set($this->selfUser['id'], 'frio', 'schema', '---');
+               $pConfig->set($this->selfUser['id'], 'frio', 'nav_bg', '#123456');
+               $pConfig->set($this->selfUser['id'], 'frio', 'link_color', '#123456');
+               $pConfig->set($this->selfUser['id'], 'frio', 'background_color', '#123456');
                $user = api_get_user($this->app);
                $this->assertSelfUser($user);
-               $this->assertEquals('708fa0', $user['profile_sidebar_fill_color']);
-               $this->assertEquals('6fdbe8', $user['profile_link_color']);
-               $this->assertEquals('ededed', $user['profile_background_color']);
+               $this->assertEquals('123456', $user['profile_sidebar_fill_color']);
+               $this->assertEquals('123456', $user['profile_link_color']);
+               $this->assertEquals('123456', $user['profile_background_color']);
        }
 
        /**