Skip to content

Commit

Permalink
Fixed some tests in Export, Import and Node
Browse files Browse the repository at this point in the history
Signed-off-by: Deven Bansod <devenbansod.bits@gmail.com>
  • Loading branch information
devenbansod committed Nov 4, 2016
1 parent 00bfc9d commit 6a79e7c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 101 deletions.
43 changes: 24 additions & 19 deletions test/classes/navigation/NodeTest.php
Expand Up @@ -373,6 +373,8 @@ public function testGetDataWithEnabledISAndGroupingEnabled()
$dbi->expects($this->once())
->method('fetchResult')
->with($expectedSql);
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;
$node->getData('', $pos);
}
Expand Down Expand Up @@ -408,6 +410,9 @@ public function testGetDataWithEnabledISAndGroupingDisabled()
$dbi->expects($this->once())
->method('fetchResult')
->with($expectedSql);
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));

$GLOBALS['dbi'] = $dbi;
$node->getData('', $pos);
}
Expand Down Expand Up @@ -438,34 +443,28 @@ public function testGetDataWithDisabledISAndGroupingEnabled()
->method('tryQuery')
->with("SHOW DATABASES WHERE TRUE AND `Database` LIKE '%db%' ")
->will($this->returnValue(true));
$dbi->expects($this->at(1))
->method('fetchArray')
->will(
$this->returnValue(
array(
'0' => 'db'
)
)
);
$dbi->expects($this->at(2))
$dbi->expects($this->exactly(3))
->method('fetchArray')
->will(
$this->returnValue(
array(
'0' => 'aa_db'
)
)
->willReturnOnConsecutiveCalls(
array(
'0' => 'db'
),
array(
'0' => 'aa_db'
),
false
);
$dbi->expects($this->at(3))
->method('fetchArray')
->will($this->returnValue(false));

$dbi->expects($this->once())
->method('fetchResult')
->with(
"SHOW DATABASES WHERE TRUE AND `Database` LIKE '%db%' AND ("
. " LOCATE('db_', CONCAT(`Database`, '_')) = 1"
. " OR LOCATE('aa_', CONCAT(`Database`, '_')) = 1 )"
);
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));

$GLOBALS['dbi'] = $dbi;
$node->getData('', $pos, 'db');
}
Expand Down Expand Up @@ -553,6 +552,9 @@ public function testGetPresenceWithDisabledIS()
$dbi->expects($this->once())
->method('tryQuery')
->with("SHOW DATABASES WHERE TRUE ");
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));

$GLOBALS['dbi'] = $dbi;
$node->getPresence();

Expand All @@ -563,6 +565,9 @@ public function testGetPresenceWithDisabledIS()
$dbi->expects($this->once())
->method('tryQuery')
->with("SHOW DATABASES WHERE TRUE AND `Database` LIKE '%dbname%' ");
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));

$GLOBALS['dbi'] = $dbi;
$node->getPresence('', 'dbname');
}
Expand Down
111 changes: 29 additions & 82 deletions test/classes/plugin/export/ExportXmlTest.php
Expand Up @@ -234,29 +234,15 @@ public function testExportHeader()
->disableOriginalConstructor()
->getMock();

$dbi->expects($this->at(0))
->method('fetchResult')
->with(
'SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`'
. ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`'
. ' = \'d<"b\' LIMIT 1'
)
->will($this->returnValue($result));

$dbi->expects($this->at(1))
->method('fetchResult')
->with(
'SHOW CREATE TABLE `d<"b`.`table`',
0
)
->will($this->returnValue($result));

// isView
$dbi->expects($this->at(2))
$dbi->expects($this->exactly(3))
->method('fetchResult')
->will($this->returnValue(false));
->willReturnOnConsecutiveCalls(
$result,
$result,
false
);

$dbi->expects($this->at(3))
$dbi->expects($this->once())
->method('getTriggers')
->with('d<"b', 'table')
->will(
Expand All @@ -270,49 +256,31 @@ public function testExportHeader()
)
);

$dbi->expects($this->at(4))
$dbi->expects($this->exactly(2))
->method('getProceduresOrFunctions')
->with('d<"b', 'FUNCTION')
->will(
$this->returnValue(
array(
'fn'
)
->willReturnOnConsecutiveCalls(
array(
'fn'
),
array(
'pr'
)
);

$dbi->expects($this->at(5))
$dbi->expects($this->exactly(2))
->method('getDefinition')
->with('d<"b', 'FUNCTION', 'fn')
->will(
$this->returnValue(
'fndef'
)
);

$dbi->expects($this->at(6))
->method('getProceduresOrFunctions')
->with('d<"b', 'PROCEDURE')
->will(
$this->returnValue(
array(
'pr'
)
)
);

$dbi->expects($this->at(7))
->method('getDefinition')
->with('d<"b', 'PROCEDURE', 'pr')
->will(
$this->returnValue(
'prdef'
)
->willReturnOnConsecutiveCalls(
'fndef',
'prdef'
);

$dbi->expects($this->once())
->method('getTable')
->will($this->returnValue(new Table('table', 'd<"b')));
->will($this->returnValue(new Table('table', 'd<"b', $dbi)));
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));

$GLOBALS['dbi'] = $dbi;

Expand Down Expand Up @@ -385,39 +353,18 @@ public function testExportHeader()
't1' => array(null, '"tbl"')
);

$dbi->expects($this->at(1))
->method('fetchResult')
->with(
'SHOW CREATE TABLE `d<"b`.`t1`',
0
)
->will($this->returnValue($result));

// isView
$dbi->expects($this->at(2))
$dbi->expects($this->exactly(4))
->method('fetchResult')
->will($this->returnValue(true));

$result = array(
't2' => array(null, '"tbl"')
);

$dbi->expects($this->at(3))
->method('fetchResult')
->with(
'SHOW CREATE TABLE `d<"b`.`t2`',
0
)
->will($this->returnValue($result));

// isView
$dbi->expects($this->at(4))
->method('fetchResult')
->will($this->returnValue(false));
->willReturnOnConsecutiveCalls(
$result,
true,
$result,
false
);

$dbi->expects($this->any())
->method('getTable')
->will($this->returnValue(new Table('table', 'd<"b')));
->will($this->returnValue(new Table('table', 'd<"b', $dbi)));

$GLOBALS['dbi'] = $dbi;

Expand Down
2 changes: 2 additions & 0 deletions test/classes/plugin/import/ImportOdsTest.php
Expand Up @@ -126,6 +126,8 @@ public function testDoImport()
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $dbi;

//Test function called
Expand Down

0 comments on commit 6a79e7c

Please sign in to comment.