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{x$BX{{+uQS4f2T7/E|lǸ!HXϗg zie["0]ž]dV?Sr:}/h"RSoezG<uYٱܛx;|Т#2,zi[ZoKSB_ʩ֡.HXik%Bܻ%e@0S
uStn*Qg?ۯb%ff]: қ<//$'Y}n2mY&_oKPu~x/Jt&UV77]|VYtmFn#{hb3䈮KeWŵ9܏.ݲUc	O2;<ǭgrURtcT3	нQ&cAS&45?:R~iVWV8mE9 hBCn6e`IxS#|.X꿑u0xhFTtoYH+-/B03ȳ..a(sFH6j"Ǻ,_-Jw]# Բʥy{:ǕsvD32vFܾ)hŵ9܏.ݲVHWC8#ᦑueK!cOxDtM a׽7`	bzsh;<PM/:>fꁕw) `zWFEƯEM{	wKny&E,3GgoXe 릭4ڟ{u?f{XƜ3
e}w3?nG:aF!ҩ{rمn57`	bzsh
0O%wu?'}|%
ԦJ̚=t8g葶9H%x$mZ?'jv6kΆF!Lǹ6
C7o目{oBr 喱QaMF>Aqi-ئ	Y&:R:l=J$!Z J7`	bzsht{CZƀB^ɶKvPR`Q1E[r.f@N{PG,1m4>q ,-:[-;R7u3`h%;:m9_7Pc{g	}lc#Hj#U:4XVT8\3uonEy"z؀a80b%ηpAs9tZv'I[y}"	ESM9U/SASm|lFFOshV5,o{X#͐[۹|_Ww@β :-x`4svfuA;Xaj.K"w 0|-,y}N
Rg ;ƓXP|Ov:YC`#<5(XCHI8\3uonEKvo^5c"*oN3-e 릭4ڟ{u%/:&_ngC\_P5;k']ve4nfzu,Z/ȕ^38\3uonE77Pobk}ZvYl=2\RAη=JF7<EvXDZbEJ=vAƿ#5`&Ϸk26\vU@Qg_٠C0-@	vbWxT8͗
<Y7<6 ,sIR4f"f(ʱSTo._sc#4H{rRDI
 խ(ZXKLrO$this->object->setAllowedKeys(null);
        $this->object->set('b', 2);

        $this->assertEquals(
            array('a' => 1, 'b' => 2, 'c' => 3),
            $this->object->getConfig()
        );
    }

    /**
     * Test for ConfigFile::setCfgUpdateReadMapping
     *
     * @return void
     * @test
     */
    public function testConfigReadMapping()
    {
        $this->object->setCfgUpdateReadMapping(
            array(
                'Servers/value1' => 'Servers/1/value1',
                'Servers/value2' => 'Servers/1/value2'
            )
        );
        $this->object->set('Servers/1/passthrough1', 1);
        $this->object->set('Servers/1/passthrough2', 2);
        $this->object->updateWithGlobalConfig(array('Servers/value1' => 3));

        $this->assertEquals(
            array('Servers' => array(
                1 => array(
                    'passthrough1' => 1,
                    'passthrough2' => 2,
                    'value1' => 3))),
            $this->object->getConfig()
        );
        $this->assertEquals(
            3,
            $this->object->get('Servers/1/value1')
        );
    }

    /**
     * Test for ConfigFile::resetConfigData
     *
     * @return void
     * @test
     */
    public function testResetConfigData()
    {
        $this->object->set('key', 'value');

        $this->object->resetConfigData();

        $this->assertEmpty($this->object->getConfig());
        $this->assertEmpty($this->object->getConfigArray());
    }

    /**
     * Test for ConfigFile::setConfigData
     *
     * @return void
     * @test
     */
    public function testSetConfigData()
    {
        $this->object->set('abc', 'should be deleted by setConfigData');
        $this->object->setConfigData(array('a' => 'b'));

        $this->assertEquals(
            array('a' => 'b'),
            $this->object->getConfig()
        );
        $this->assertEquals(
            array('a' => 'b'),
            $this->object->getConfigArray()
        );
    }

    /**
     * Test for ConfigFile::set and ConfigFile::get
     *
     * @return void
     * @test
     */
    public function testBasicSetUsage()
    {
        $default_host = $this->object->getDefault('Servers/1/host');
        $nondefault_host = $default_host . '.abc';

        $this->object->set('Servers/4/host', $nondefault_host);
        $this->object->set('Servers/5/host', $default_host);
        $this->object->set('Servers/6/host', $default_host, 'Servers/6/host');
        $this->assertEquals(
            $nondefault_host,
            $this->object->get('Servers/4/host')
        );
        $this->assertEquals(
            null,
            $this->object->get('Servers/5/host')
        );
        $this->assertEquals(
            $default_host,
            $this->object->get('Servers/6/host')
        );

        // return default value for nonexistent keys
        $this->assertNull(
            $this->object->get('key not excist')
        );
        $this->assertEquals(
            array(1),
            $this->object->get('key not excist', array(1))
        );
        $default = new stdClass();
        $this->assertInstanceOf(
            'stdClass',
            $this->object->get('key not excist', $default)
        );
    }

    /**
     * Test for ConfigFile::set - in PMA Setup
     *
     * @return void
     * @test
     */
    public function testConfigFileSetInSetup()
    {
        $default_value = $this->object->getDefault(
            self::SIMPLE_KEY_WITH_DEFAULT_VALUE
        );

        // default values are not written
        $this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_value);
        $this->assertEmpty($this->object->getConfig());
    }

    /**
     * Test for ConfigFile::set - in user preferences
     *
     * @return void
     * @test
     */
    public function testConfigFileSetInUserPreferences()
    {
        $default_value = $this->object->getDefault(
            self::SIMPLE_KEY_WITH_DEFAULT_VALUE
        );

        // values are not written when they are the same as in config.inc.php
        $this->object = new ConfigFile(
            array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value)
        );
        $this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_value);
        $this->assertEmpty($this->object->getConfig());

        // but if config.inc.php differs from config.default.php,
        // allow to overwrite with value from config.default.php
        $config_inc_php_value = $default_value . 'suffix';
        $this->object = new ConfigFile(
            array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $config_inc_php_value)
        );
        $this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_value);
        $this->assertEquals(
            array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value),
            $this->object->getConfig()
        );
    }

    /**
     * Test for ConfigFile::getFlatDefaultConfig
     *
     * @return void
     * @test
     * @group medium
     */
    public function testGetFlatDefaultConfig()
    {
        $flat_default_config = $this->object->getFlatDefaultConfig();

        $default_value = $this->object->getDefault(
            self::SIMPLE_KEY_WITH_DEFAULT_VALUE
        );
        $this->assertEquals(
            $default_value, $flat_default_config[self::SIMPLE_KEY_WITH_DEFAULT_VALUE]
        );

        $localhost_value = $this->object->getDefault('Servers/1/host');
        $this->assertEquals(
            $localhost_value, $flat_default_config['Servers/1/host']
        );

        $cfg = array();
        include './libraries/config.default.php';
        // verify that $cfg read from config.default.php is valid
        $this->assertGreaterThanOrEqual(100, count($cfg));
        $this->assertGreaterThanOrEqual(count($cfg), count($flat_default_config));
    }

    /**
     * Test for ConfigFile::updateWithGlobalConfig
     *
     * @return void
     * @test
     */
    public function testUpdateWithGlobalConfig()
    {
        $this->object->set('key', 'value');
        $this->object->set('key2', 'value');
        $this->object->updateWithGlobalConfig(array('key' => 'ABC'));

        $this->assertEquals(
            array('key' => 'ABC', 'key2' => 'value'),
            $this->object->getConfig()
        );
    }

    /**
     * Test for ConfigFile::getCanonicalPath
     *
     * @return void
     * @test
     */
    public function testGetCanonicalPath()
    {
        $this->assertEquals(
            "Servers/1/abcd",
            $this->object->getCanonicalPath("Servers/2/abcd")
        );

        $this->assertEquals(
            "Servers/foo/bar",
            $this->object->getCanonicalPath("Servers/foo/bar")
        );
    }

    /**
     * Test for ConfigFile::getDbEntry
     *
     * @return void
     * @test
     */
    public function testGetDbEntry()
    {
        $cfg_db = array();
        include './libraries/config.values.php';
        // verify that $cfg_db read from config.values.php is valid
        $this->assertGreaterThanOrEqual(20, count($cfg_db));

        $this->assertEquals(
            $cfg_db['Servers'][1]['port'],
            $this->object->getDbEntry('Servers/1/port')
        );
        $this->assertNull($this->object->getDbEntry('no such key'));
        $this->assertEquals(
            array(1),
            $this->object->getDbEntry('no such key', array(1))
        );
    }

    /**
     * Test for ConfigFile::getServerCount
     *
     * @return void
     * @test
     */
    public function testGetServerCount()
    {
        $this->object->set('Servers/1/x', 1);
        $this->object->set('Servers/2/x', 2);
        $this->object->set('Servers/3/x', 3);
        $this->object->set('Servers/4/x', 4);
        $this->object->set('ServerDefault', 3);

        $this->assertEquals(
            4,
            $this->object->getServerCount()
        );

        $this->object->removeServer(2);
        $this->object->removeServer(2);

        $this->assertEquals(
            2,
            $this->object->getServerCount()
        );

        $this->assertLessThanOrEqual(
            2,
            $this->object->get('ServerDefault')
        );
        $this->assertEquals(
            array('Servers' => array(1 => array('x' => 1), 2 => array('x' => 4))),
            $this->object->getConfig()
        );
        $this->assertEquals(
            array('Servers/1/x' => 1, 'Servers/2/x' => 4),
            $this->object->getConfigArray()
        );
    }

    /**
     * Test for ConfigFile::getServers
     *
     * @return void
     * @test
     */
    public function testGetServers()
    {
        $this->object->set('Servers/1/x', 'a');
        $this->object->set('Servers/2/x', 'b');

        $this->assertEquals(
            array(1 => array('x' => 'a'), 2 => array('x' => 'b')),
            $this->object->getServers()
        );
    }

    /**
     * Test for ConfigFile::getServerDSN
     *
     * @return void
     * @test
     */
    public function testGetServerDSN()
    {
        $this->assertEquals(
            '',
            $this->object->getServerDSN(1)
        );

        $this->object->updateWithGlobalConfig(
            array(
                'Servers' => array(
                    1 => array(
                        "auth_type" => "config",
                        "user" => "testUser",
                        "connect_type" => "tcp",
                        "host" => "example.com",
                        "port" => "21"
                    )
                )
            )
        );
        $this->assertEquals(
            "mysqli://testUser:***@example.com:21",
            $this->object->getServerDSN(1)
        );

        $this->object->updateWithGlobalConfig(
            array(
                'Servers' => array(
                    1 => array(
                        "auth_type" => "config",
                        "user" => "testUser",
                        "connect_type" => "socket",
                        "host" => "example.com",
                        "port" => "21",
                        "nopassword" => "yes",
                        "socket" => "123"
                    )
                )
            )
        );
        $this->assertEquals(
            "mysqli://testUser@123",
            $this->object->getServerDSN(1)
        );

        $this->object->updateWithGlobalConfig(
            array(
                'Servers' => array(
                    1 => array(
                        "auth_type" => "config",
                        "user" => "testUser",
                        "connect_type" => "tcp",
                        "host" => "example.com",
                        "port" => "21",
                        "nopassword" => "yes",
                        "password" => "testPass"
                    )
                )
            )
        );
        $this->assertEquals(
            "mysqli://testUser:***@example.com:21",
            $this->object->getServerDSN(1)
        );
    }

    /**
     * Test for ConfigFile::getServerName
     *
     * @return void
     * @test
     */
    public function testGetServerName()
    {
        $this->assertEquals(
            '',
            $this->object->getServerName(1)
        );

        $this->object->set('Servers/1/host', 'example.com');
        $this->assertEquals(
            'example.com',
            $this->object->getServerName(1)
        );

        $this->object->set('Servers/1/verbose', 'testData');
        $this->assertEquals(
            'testData',
            $this->object->getServerName(1)
        );
    }

    /**
     * Test for ConfigFile::getConfigArray
     *
     * @return void
     * @test
     */
    public function testGetConfigArray()
    {
        $this->object->setPersistKeys(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE));
        $this->object->set('Array/test', array('x', 'y'));
        $default_value = $this->object->getDefault(
            self::SIMPLE_KEY_WITH_DEFAULT_VALUE
        );

        $this->assertEquals(
            array(
                self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value,
                'Array/test' => array('x', 'y')
            ),
            $this->object->getConfigArray()
        );
    }
}
