You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.6 KiB

14 years ago
<?php
12 years ago
namespace yiiunit\framework\db;
use yii\db\Connection;
14 years ago
class ConnectionTest extends DatabaseTestCase
14 years ago
{
12 years ago
public function testConstruct()
14 years ago
{
13 years ago
$connection = $this->getConnection(false);
$params = $this->database;
14 years ago
$this->assertEquals($params['dsn'], $connection->dsn);
$this->assertEquals($params['username'], $connection->username);
$this->assertEquals($params['password'], $connection->password);
}
12 years ago
public function testOpenClose()
14 years ago
{
$connection = $this->getConnection(false, false);
$this->assertFalse($connection->isActive);
14 years ago
$this->assertEquals(null, $connection->pdo);
$connection->open();
$this->assertTrue($connection->isActive);
$this->assertTrue($connection->pdo instanceof \PDO);
14 years ago
$connection->close();
$this->assertFalse($connection->isActive);
14 years ago
$this->assertEquals(null, $connection->pdo);
13 years ago
$connection = new Connection;
$connection->dsn = 'unknown::memory:';
14 years ago
$this->setExpectedException('yii\db\Exception');
$connection->open();
}
12 years ago
public function testGetDriverName()
{
$connection = $this->getConnection(false, false);
$this->assertEquals($this->driverName, $connection->driverName);
}
12 years ago
public function testQuoteValue()
{
13 years ago
$connection = $this->getConnection(false);
$this->assertEquals(123, $connection->quoteValue(123));
$this->assertEquals("'string'", $connection->quoteValue('string'));
$this->assertEquals("'It\\'s interesting'", $connection->quoteValue("It's interesting"));
}
12 years ago
public function testQuoteTableName()
{
13 years ago
$connection = $this->getConnection(false);
$this->assertEquals('`table`', $connection->quoteTableName('table'));
$this->assertEquals('`table`', $connection->quoteTableName('`table`'));
$this->assertEquals('`schema`.`table`', $connection->quoteTableName('schema.table'));
$this->assertEquals('`schema`.`table`', $connection->quoteTableName('schema.`table`'));
$this->assertEquals('{{table}}', $connection->quoteTableName('{{table}}'));
$this->assertEquals('(table)', $connection->quoteTableName('(table)'));
}
12 years ago
public function testQuoteColumnName()
{
13 years ago
$connection = $this->getConnection(false);
$this->assertEquals('`column`', $connection->quoteColumnName('column'));
$this->assertEquals('`column`', $connection->quoteColumnName('`column`'));
$this->assertEquals('`table`.`column`', $connection->quoteColumnName('table.column'));
$this->assertEquals('`table`.`column`', $connection->quoteColumnName('table.`column`'));
$this->assertEquals('[[column]]', $connection->quoteColumnName('[[column]]'));
$this->assertEquals('{{column}}', $connection->quoteColumnName('{{column}}'));
$this->assertEquals('(column)', $connection->quoteColumnName('(column)'));
}
14 years ago
}