mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
parent
1130376ad6
commit
69aa6e3d22
@ -1,108 +1,59 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
/**
|
||||||
|
* This file is part of Icinga 2 Web.
|
||||||
|
*
|
||||||
|
* Icinga 2 Web - Head for multiple monitoring backends.
|
||||||
|
* Copyright (C) 2013 Icinga Development Team
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||||
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||||
|
* @author Icinga Development Team <info@icinga.org>
|
||||||
|
*/
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
namespace Tests\Icinga\User\Preferences;
|
namespace Tests\Icinga\User\Preferences;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../../../library/Icinga/Exception/ConfigurationError.php';
|
// @codingStandardsIgnoreStart
|
||||||
require_once __DIR__ . '/../../../../../../library/Icinga/Util/ConfigAwareFactory.php';
|
require_once realpath(__DIR__. '/../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||||
require_once __DIR__ . '/../../../../../../library/Icinga/Application/DbAdapterFactory.php';
|
// @codingStandardsIgnoreEnd
|
||||||
require_once __DIR__ . '/../../../../../../library/Icinga/User.php';
|
|
||||||
require_once __DIR__ . '/../../../../../../library/Icinga/User/Preferences.php';
|
|
||||||
require_once __DIR__ . '/../../../../../../library/Icinga/User/Preferences/ChangeSet.php';
|
|
||||||
require_once __DIR__ . '/../../../../../../library/Icinga/User/Preferences/LoadInterface.php';
|
|
||||||
require_once __DIR__ . '/../../../../../../library/Icinga/User/Preferences/FlushObserverInterface.php';
|
|
||||||
require_once __DIR__ . '/../../../../../../library/Icinga/User/Preferences/DbStore.php';
|
|
||||||
|
|
||||||
|
use Icinga\Test\BaseTestCase;
|
||||||
|
|
||||||
|
// @codingStandardsIgnoreStart
|
||||||
require_once 'Zend/Db.php';
|
require_once 'Zend/Db.php';
|
||||||
require_once 'Zend/Config.php';
|
|
||||||
require_once 'Zend/Db/Adapter/Abstract.php';
|
require_once 'Zend/Db/Adapter/Abstract.php';
|
||||||
|
require_once BaseTestCase::$libDir . '/Exception/ConfigurationError.php';
|
||||||
|
require_once BaseTestCase::$libDir . '/User.php';
|
||||||
|
require_once BaseTestCase::$libDir . '/User/Preferences.php';
|
||||||
|
require_once BaseTestCase::$libDir . '/User/Preferences/LoadInterface.php';
|
||||||
|
require_once BaseTestCase::$libDir . '/User/Preferences/FlushObserverInterface.php';
|
||||||
|
require_once BaseTestCase::$libDir . '/User/Preferences/DbStore.php';
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
use Icinga\Application\DbAdapterFactory;
|
use \Zend_Db_Adapter_PDO_Abstract;
|
||||||
use Icinga\User;
|
use Icinga\User;
|
||||||
use Icinga\User\Preferences\DbStore;
|
use Icinga\User\Preferences\DbStore;
|
||||||
use Icinga\User\Preferences;
|
use Icinga\User\Preferences;
|
||||||
use \PHPUnit_Framework_TestCase;
|
|
||||||
use \Zend_Config;
|
|
||||||
use \Zend_Db;
|
|
||||||
use \Zend_Db_Adapter_Abstract;
|
|
||||||
use \PDOException;
|
|
||||||
use \Exception;
|
|
||||||
|
|
||||||
class DbStoreTest extends PHPUnit_Framework_TestCase
|
class DbStoreTest extends BaseTestCase
|
||||||
{
|
{
|
||||||
const TYPE_MYSQL = 'mysql';
|
|
||||||
|
|
||||||
const TYPE_PGSQL = 'pgsql';
|
private function createDbStore(Zend_Db_Adapter_PDO_Abstract $db)
|
||||||
|
|
||||||
private $table = 'preference';
|
|
||||||
|
|
||||||
private $databaseConfig = array(
|
|
||||||
'type' => 'db',
|
|
||||||
'host' => '127.0.0.1',
|
|
||||||
'username' => 'icinga_unittest',
|
|
||||||
'password' => 'icinga_unittest',
|
|
||||||
'dbname' => 'icinga_unittest'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Zend_Db_Adapter_Abstract
|
|
||||||
*/
|
|
||||||
private $dbMysql;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Zend_Db_Adapter_Abstract
|
|
||||||
*/
|
|
||||||
private $dbPgsql;
|
|
||||||
|
|
||||||
private function createDb($type)
|
|
||||||
{
|
|
||||||
$this->databaseConfig['db'] = $type;
|
|
||||||
$db = DbAdapterFactory::createDbAdapterFromConfig(
|
|
||||||
new Zend_Config($this->databaseConfig)
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$db->getConnection();
|
|
||||||
|
|
||||||
$dumpFile = realpath(__DIR__ . '/../../../../../../etc/schema/preferences.' . strtolower($type) . '.sql');
|
|
||||||
|
|
||||||
if (!$dumpFile) {
|
|
||||||
throw new Exception('Dumpfile for db type not found: ' . $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$db->getConnection()->exec(file_get_contents($dumpFile));
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
// PASS
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (\Zend_Db_Adapter_Exception $e) {
|
|
||||||
return null;
|
|
||||||
} catch (PDOException $e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $db;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function setUp()
|
|
||||||
{
|
|
||||||
$this->dbMysql = $this->createDb(self::TYPE_MYSQL);
|
|
||||||
$this->dbPgsql = $this->createDb(self::TYPE_PGSQL);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function tearDown()
|
|
||||||
{
|
|
||||||
if ($this->dbMysql) {
|
|
||||||
$this->dbMysql->getConnection()->exec('DROP TABLE ' . $this->table);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->dbPgsql) {
|
|
||||||
$this->dbPgsql->getConnection()->exec('DROP TABLE ' . $this->table);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createDbStore(Zend_Db_Adapter_Abstract $db)
|
|
||||||
{
|
{
|
||||||
$user = new User('jdoe');
|
$user = new User('jdoe');
|
||||||
|
|
||||||
@ -113,10 +64,20 @@ class DbStoreTest extends PHPUnit_Framework_TestCase
|
|||||||
return $store;
|
return $store;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateUpdateDeletePreferenceValuesMySQL()
|
/**
|
||||||
|
* @dataProvider mysqlDb
|
||||||
|
* @param Zend_Db_Adapter_PDO_Abstract $mysqlDb
|
||||||
|
*/
|
||||||
|
public function testCreateUpdateDeletePreferenceValuesMySQL($mysqlDb)
|
||||||
{
|
{
|
||||||
if ($this->dbMysql) {
|
$this->setupDbProvider($mysqlDb);
|
||||||
$store = $this->createDbStore($this->dbMysql);
|
|
||||||
|
$this->loadSql(
|
||||||
|
$mysqlDb,
|
||||||
|
$sqlDumpFile = BaseTestCase::$etcDir . '/schema/preferences.mysql.sql'
|
||||||
|
);
|
||||||
|
|
||||||
|
$store = $this->createDbStore($mysqlDb);
|
||||||
|
|
||||||
$preferences = new Preferences(array());
|
$preferences = new Preferences(array());
|
||||||
$preferences->attach($store);
|
$preferences->attach($store);
|
||||||
@ -133,15 +94,22 @@ class DbStoreTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('OK1', $preferencesTest->get('test.key1'));
|
$this->assertEquals('OK1', $preferencesTest->get('test.key1'));
|
||||||
$this->assertNull($preferencesTest->get('test.key2'));
|
$this->assertNull($preferencesTest->get('test.key2'));
|
||||||
$this->assertEquals('OKOK333', $preferencesTest->get('test.key3'));
|
$this->assertEquals('OKOK333', $preferencesTest->get('test.key3'));
|
||||||
} else {
|
|
||||||
$this->markTestSkipped('MySQL test environment is not configured');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateUpdateDeletePreferenceValuesPgSQL()
|
/**
|
||||||
|
* @dataProvider pgsqlDb
|
||||||
|
* @param Zend_Db_Adapter_PDO_Abstract $pgsqlDb
|
||||||
|
*/
|
||||||
|
public function testCreateUpdateDeletePreferenceValuesPgSQL($pgsqlDb)
|
||||||
{
|
{
|
||||||
if ($this->dbPgsql) {
|
$this->setupDbProvider($pgsqlDb);
|
||||||
$store = $this->createDbStore($this->dbPgsql);
|
|
||||||
|
$this->loadSql(
|
||||||
|
$pgsqlDb,
|
||||||
|
$sqlDumpFile = BaseTestCase::$etcDir . '/schema/preferences.pgsql.sql'
|
||||||
|
);
|
||||||
|
|
||||||
|
$store = $this->createDbStore($pgsqlDb);
|
||||||
|
|
||||||
$preferences = new Preferences(array());
|
$preferences = new Preferences(array());
|
||||||
$preferences->attach($store);
|
$preferences->attach($store);
|
||||||
@ -158,8 +126,5 @@ class DbStoreTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('OK1', $preferencesTest->get('test.key1'));
|
$this->assertEquals('OK1', $preferencesTest->get('test.key1'));
|
||||||
$this->assertNull($preferencesTest->get('test.key2'));
|
$this->assertNull($preferencesTest->get('test.key2'));
|
||||||
$this->assertEquals('OKOK333', $preferencesTest->get('test.key3'));
|
$this->assertEquals('OKOK333', $preferencesTest->get('test.key3'));
|
||||||
} else {
|
|
||||||
$this->markTestSkipped('PgSQL test environment is not configured');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user