1
0
Fork 0
MySQLDumper/tests/functional/controllers/SqlControllerTest.php

131 Zeilen
5,2 KiB
PHP

2011-06-10 21:55:32 +00:00
<?php
/**
* @group Sql
*/
class Msd_Application_Controller_SqlControllerTest
extends ControllerTestCase
{
public function testCanShowDatabaseList()
{
$this->loginUser();
$this->dispatch('sql');
// make sure headline of db list is shown with correct user
$expected = "Datenbanken des Benutzers 'root'@'localhost'";
$this->assertQueryContentContains('h2', $expected);
// make sure we see the "show tables" link for db information_schema
$expected = base64_encode("information_schema");
2011-06-16 17:42:53 +00:00
$this->assertXpath("//a[contains(@href, '" . $expected . "')]");
2011-06-10 21:55:32 +00:00
}
public function testCanShowTableList()
{
$this->loginUser();
$this->dispatch('sql/show.tables/dbName/bXlzcWw%3D');
// make sure headline shows the selected database
$expected = 'Tabellen der Datenbank `mysql`';
$this->assertQueryContentContains('h2', $expected);
// make sure we see the detail link for table `mysql`.`db`
$expected = 'columns_priv';
$this->assertQueryContentContains('table > tr > td > label', $expected);
}
public function testCanShowTableData()
{
$this->loginUser();
$this->dispatch('sql/show.table.data/dbName/bXlzcWw%3D/tableName/dXNlcg%3D%3D');
// make sure headline shows the selected table
$expected = 'Datensätze der Tabelle `mysql`.`user`';
$this->assertQueryContentContains('h2', $expected);
// make sure user root@localhost is shown
$expected = 'localhost ';
$this->assertQueryContentContains('table > tr > td', $expected);
$expected = 'root ';
$this->assertQueryContentContains('table > tr > td', $expected);
}
2011-06-16 17:42:53 +00:00
public function testShowTableDataCanDetectEmptyDatabase()
{
//create empty testDb
$db = Msd_Db::getAdapter();
$db->query('DROP DATABASE IF EXISTS `testDb`');
$sql = 'CREATE DATABASE `testDb` DEFAULT CHARSET utf8 DEFAULT COLLATE utf8_general_ci';
$db->query($sql);
$this->dispatch('sql/show.table.data/dbName/' . base64_encode('testDb') . '/tableName/IDontExits');
// make sure we see an error message
$this->assertXpathCount('//p[@class="error"]', 1);
// make sure message is "Database is empty!"
$expected = 'Die Datenbank ist leer!';
$this->assertQueryContentContains('p', $expected);
}
2011-06-10 21:55:32 +00:00
public function testCanFallbackToShowingDataOfFirstTableOnIncorrectTable()
{
$this->loginUser();
$this->dispatch('sql/show.table.data/dbName/bXlzcWw%3D/tableName/iDontExits');
// we excpect a fall back to the first found table in db `mysql`
$expected = 'Datensätze der Tabelle `mysql`.`columns_priv`';
$this->assertQueryContentContains('h2', $expected);
}
2011-06-14 20:02:42 +00:00
public function testCanCreateADatabase()
{
$this->loginUser();
//drop our testDb if it exists
$db = Msd_Db::getAdapter();
$db->query('DROP DATABASE IF EXISTS `testDb`');
$this->request->setMethod('POST');
$newDbInfo = array(
2011-06-16 17:42:53 +00:00
'dbName' => 'testDb',
'dbCharset' => 'utf8',
'dbCollation' => 'utf8_general_ci'
2011-06-14 20:02:42 +00:00
);
$this->request->setPost('newDbInfo', $newDbInfo);
$this->dispatch('sql/create.database');
$expected = 'Die Datenbank \'testDb\' wurde erfolgreich erstellt.';
$this->assertQueryContentContains('div', $expected);
2011-06-14 20:06:41 +00:00
// retry to create the same database - should fail ;)
$this->request->setPost('newDbInfo', $newDbInfo);
$this->dispatch('sql/create.database');
$expected = 'Die Datenbank wurde nicht erstellt.';
$this->assertQueryContentContains('div', $expected);
2011-06-14 20:02:42 +00:00
// clean up
$db->query('DROP DATABASE IF EXISTS `testDb`');
}
2011-06-16 17:42:53 +00:00
/**
* @depends testCanCreateADatabase
*/
2011-06-14 20:20:22 +00:00
public function testCanDropADatabase()
{
$this->loginUser();
2011-06-16 17:42:53 +00:00
//create our testDb
2011-06-14 20:20:22 +00:00
$db = Msd_Db::getAdapter();
$sql = 'CREATE DATABASE `testDb` DEFAULT CHARSET utf8 DEFAULT COLLATE utf8_general_ci';
$db->query($sql);
// now let's see if we can drop it
$this->request->setMethod('POST');
$this->request->setPost('dbNames', array(base64_encode('testDb')));
$this->dispatch('sql/drop.database');
2011-06-14 20:20:22 +00:00
// check action output
$this->assertQueryContentContains('h4', 'Aktion - Datenbank löschen:');
$this->assertQueryContentContains('td', 'testDb');
$this->assertQueryContentContains('td', 'DROP DATABASE `testDb`;');
// look for the "ok" icon
$this->assertQueryContentContains('td', '/css/msd/icons/16x16/Apply.png');
}
2011-06-14 21:09:19 +00:00
public function testShowDatabasesCanFallbackOnInvalidActualDatabase()
{
$this->loginUser();
$config = Msd_Configuration::getInstance();
$config->set('dynamic.dbActual', 'IDontExist');
$this->dispatch('sql/show.databases');
// make sure we fall back to first db "information_schema"
$expected = '<option value="aW5mb3JtYXRpb25fc2NoZW1h" selected="selected">information_schema</option>';
$this->assertQueryContentContains('select', $expected);
}
2011-06-16 17:42:53 +00:00
2011-06-10 21:55:32 +00:00
}