getMockBuilder('PMA\libraries\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; $this->object = new ImportLdi(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. * * @access protected * @return void */ protected function tearDown() { unset($this->object); } /** * Test for getProperties * * @return void * * @group medium */ public function testGetProperties() { $properties = $this->object->getProperties(); $this->assertEquals( __('CSV using LOAD DATA'), $properties->getText() ); $this->assertEquals( 'ldi', $properties->getExtension() ); } /** * Test for getProperties for ldi_local_option = auto * * @return void * * @group medium */ public function testGetPropertiesAutoLdi() { $GLOBALS['cfg']['Import']['ldi_local_option'] = 'auto'; $this->object = new ImportLdi(); $properties = $this->object->getProperties(); $this->assertEquals( true, $GLOBALS['cfg']['Import']['ldi_local_option'] ); $this->assertEquals( __('CSV using LOAD DATA'), $properties->getText() ); $this->assertEquals( 'ldi', $properties->getExtension() ); } /** * Test for doImport * * @return void * * @group medium */ public function testDoImport() { //$sql_query_disabled will show the import SQL detail global $sql_query, $sql_query_disabled; $sql_query_disabled = false; //Test function called $this->object->doImport(); //asset that all sql are executed $this->assertContains( "LOAD DATA INFILE 'test/test_data/db_test_ldi.csv' INTO TABLE " . "`phpmyadmintest`", $sql_query ); $this->assertEquals( true, $GLOBALS['finished'] ); } /** * Test for doImport : invalid import file * * @return void * * @group medium */ public function testDoImportInvalidFile() { global $import_file; $import_file = 'none'; //Test function called $this->object->doImport(); // We handle only some kind of data! $this->assertContains( __('This plugin does not support compressed imports!'), $GLOBALS['message']->__toString() ); $this->assertEquals( true, $GLOBALS['error'] ); } /** * Test for doImport with LDI setting * * @return void * * @group medium */ public function testDoImportLDISetting() { global $ldi_local_option, $ldi_replace, $ldi_ignore, $ldi_terminated, $ldi_enclosed, $ldi_new_line, $skip_queries; //$sql_query_disabled will show the import SQL detail global $sql_query, $sql_query_disabled; $sql_query_disabled = false; $ldi_local_option = true; $ldi_replace = true; $ldi_ignore = true; $ldi_terminated = ','; $ldi_enclosed = ')'; $ldi_new_line = 'newline_mark'; $skip_queries = true; //Test function called $this->object->doImport(); //asset that all sql are executed //replace $this->assertContains( "LOAD DATA LOCAL INFILE 'test/test_data/db_test_ldi.csv' REPLACE INTO " . "TABLE `phpmyadmintest`", $sql_query ); //FIELDS TERMINATED $this->assertContains( "FIELDS TERMINATED BY ','", $sql_query ); //LINES TERMINATED $this->assertContains( "LINES TERMINATED BY 'newline_mark'", $sql_query ); //IGNORE $this->assertContains( "IGNORE 1 LINES", $sql_query ); $this->assertEquals( true, $GLOBALS['finished'] ); } }