Skip to content

Commit

Permalink
Fix ImportLdiTest global dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
  • Loading branch information
MauricioFauth committed Dec 21, 2017
1 parent 34ea196 commit af07ea1
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions test/classes/Plugins/Import/ImportLdiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
use PhpMyAdmin\Plugins\Import\ImportLdi;
use PhpMyAdmin\Tests\PmaTestCase;

/*
* we must set $GLOBALS['server'] here
* since 'check_user_privileges.inc.php' will use it globally
*/
$GLOBALS['server'] = 0;
$GLOBALS['plugin_param'] = "table";

/**
* Tests for PhpMyAdmin\Plugins\Import\ImportLdi class
*
Expand All @@ -29,6 +22,12 @@ class ImportLdiTest extends PmaTestCase
*/
protected $object;

/**
* @var \PhpMyAdmin\DatabaseInterface
* @access protected
*/
protected $dbi;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
Expand All @@ -39,6 +38,8 @@ class ImportLdiTest extends PmaTestCase
protected function setUp()
{
//setting
$GLOBALS['server'] = 0;
$GLOBALS['plugin_param'] = 'table';
$GLOBALS['finished'] = false;
$GLOBALS['read_limit'] = 100000000;
$GLOBALS['offset'] = 0;
Expand All @@ -63,24 +64,10 @@ protected function setUp()
$GLOBALS['table'] = "phpmyadmintest";

//Mock DBI
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
$this->dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
->disableOriginalConstructor()
->getMock();

$dbi->expects($this->any())->method('tryQuery')
->will($this->returnValue(true));

$dbi->expects($this->any())->method('numRows')
->will($this->returnValue(10));

$fetchRowResult = array("ON");
$dbi->expects($this->any())->method('fetchRow')
->will($this->returnValue($fetchRowResult));

$dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));

$GLOBALS['dbi'] = $dbi;
$GLOBALS['dbi'] = $this->dbi;

$this->object = new ImportLdi();
}
Expand Down Expand Up @@ -126,6 +113,17 @@ public function testGetProperties()
*/
public function testGetPropertiesAutoLdi()
{
$this->dbi->expects($this->any())->method('tryQuery')
->will($this->returnValue(true));
$this->dbi->expects($this->any())->method('numRows')
->will($this->returnValue(10));

$fetchRowResult = array("ON");
$this->dbi->expects($this->any())->method('fetchRow')
->will($this->returnValue($fetchRowResult));

$GLOBALS['dbi'] = $this->dbi;

$GLOBALS['cfg']['Import']['ldi_local_option'] = 'auto';
$this->object = new ImportLdi();
$properties = $this->object->getProperties();
Expand Down Expand Up @@ -156,6 +154,10 @@ public function testDoImport()
global $sql_query, $sql_query_disabled;
$sql_query_disabled = false;

$this->dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $this->dbi;

//Test function called
$this->object->doImport();

Expand Down Expand Up @@ -215,6 +217,10 @@ public function testDoImportLDISetting()
global $sql_query, $sql_query_disabled;
$sql_query_disabled = false;

$this->dbi->expects($this->any())->method('escapeString')
->will($this->returnArgument(0));
$GLOBALS['dbi'] = $this->dbi;

$ldi_local_option = true;
$ldi_replace = true;
$ldi_ignore = true;
Expand Down

0 comments on commit af07ea1

Please sign in to comment.