Skip to content

Commit

Permalink
Merge branch 'QA_5_0'
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Jan 6, 2020
2 parents d6b25ee + 874c5af commit c1c8e09
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -49,7 +49,6 @@ jobs:
allow_failures:
- php: nightly
- os: osx
- name: "PHP 7.1 with dbase extension"
- name: "PHPUnit tests in random order"

include:
Expand Down Expand Up @@ -145,6 +144,7 @@ jobs:
install:
- pecl channel-update pecl.php.net
- pecl install dbase
- php -m |grep -F 'dbase'
- composer install --no-interaction
- yarn install --non-interactive

Expand Down
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -21,6 +21,8 @@ phpMyAdmin - ChangeLog
- issue #15717 Fixed warning popup not dissapearing on table stucture when using actions without any column selection
- issue #15693 Fixed focus of active tab is lost by clicking refresh option on browse tab
- issue #15734 Fix Uncaught TypeError: http_build_query() in setup
- issue Fix double slash in path when $cfg['TempDir'] has a trailing slash
- issue #14875 Fix shp file import tests where failing when php dbase extension was enabled

5.0.0 (2019-12-26)
- issue #13896 Drop support for PHP 5.5, PHP 5.6, PHP 7.0 and HHVM
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Config.php
Expand Up @@ -1641,7 +1641,7 @@ public function getTempDir(string $name): ?string
if (empty($path)) {
$path = null;
} else {
$path .= '/' . $name;
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $name;
if (! @is_dir($path)) {
@mkdir($path, 0770, true);
}
Expand Down
38 changes: 21 additions & 17 deletions libraries/classes/Plugins/Import/ImportShp.php
Expand Up @@ -114,21 +114,24 @@ public function doImport(array &$sql_data = [])
$dbf_file_name
);
if ($extracted !== false) {
$dbf_file_path = $temp . (PMA_IS_WINDOWS ? '\\' : '/')
. Sanitize::sanitizeFilename($dbf_file_name, true);
$handle = fopen($dbf_file_path, 'wb');
if ($handle !== false) {
fwrite($handle, $extracted);
fclose($handle);
// remove filename extension, e.g.
// dresden_osm.shp/gis.osm_transport_a_v06.dbf
// to
// dresden_osm.shp/gis.osm_transport_a_v06
$path_parts = pathinfo($dbf_file_name);
$dbf_file_name = $path_parts['dirname'] . '/' . $path_parts['filename'];

// sanitize filename
$dbf_file_name = Sanitize::sanitizeFilename($dbf_file_name, true);

// concat correct filename and extension
$dbf_file_path = $temp . '/' . $dbf_file_name . '.dbf';

if (file_put_contents($dbf_file_path, $extracted, LOCK_EX) !== false) {
$temp_dbf_file = true;
// Replace the .dbf with .*, as required
// by the bsShapeFiles library.
$file_name = substr(
$dbf_file_path,
0,
strlen($dbf_file_path) - 4
) . '.*';
$shp->FileName = $file_name;

// Replace the .dbf with .*, as required by the bsShapeFiles library.
$shp->FileName = substr($dbf_file_path, 0, -4) . '.*';
}
}
}
Expand All @@ -149,6 +152,9 @@ public function doImport(array &$sql_data = [])
}
}

// It should load data before file being deleted
$shp->loadFromFile('');

// Delete the .dbf file extracted to 'TempDir'
if ($temp_dbf_file
&& isset($dbf_file_path)
Expand All @@ -157,8 +163,6 @@ public function doImport(array &$sql_data = [])
unlink($dbf_file_path);
}

// Load data
$shp->loadFromFile('');
if ($shp->lastError != '') {
$error = true;
$message = Message::error(
Expand Down Expand Up @@ -223,7 +227,7 @@ public function doImport(array &$sql_data = [])

if ($shp->getDBFHeader() !== null) {
foreach ($shp->getDBFHeader() as $c) {
$cell = trim($record->DBFData[$c[0]]);
$cell = trim((string) $record->DBFData[$c[0]]);

if (! strcmp($cell, '')) {
$cell = 'NULL';
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Expand Up @@ -1982,16 +1982,6 @@ parameters:
count: 1
path: libraries/classes/Plugins/Import/ImportShp.php

-
message: "#^Ternary operator condition is always false\\.$#"
count: 1
path: libraries/classes/Plugins/Import/ImportShp.php

-
message: "#^Parameter \\#2 \\$str of function fwrite expects string, string\\|true given\\.$#"
count: 1
path: libraries/classes/Plugins/Import/ImportShp.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
Expand Down
33 changes: 33 additions & 0 deletions test/classes/ConfigTest.php
Expand Up @@ -1006,6 +1006,39 @@ public function testSetCookie()
);
}

/**
* Test for getTempDir
*
* @return void
*
* @group file-system
*/
public function testGetTempDir(): void
{
$this->object->set('TempDir', sys_get_temp_dir() . DIRECTORY_SEPARATOR);
// Check no double slash is here
$this->assertEquals(
sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'upload',
$this->object->getTempDir('upload')
);
}

/**
* Test for getUploadTempDir
*
* @return void
*
* @group file-system
*/
public function testGetUploadTempDir(): void
{
$this->object->set('TempDir', sys_get_temp_dir() . DIRECTORY_SEPARATOR);
$this->assertEquals(
$this->object->getTempDir('upload'),
$this->object->getUploadTempDir()
);
}

/**
* Test for isGitRevision
*
Expand Down
48 changes: 36 additions & 12 deletions test/classes/Plugins/Import/ImportShpTest.php
Expand Up @@ -140,13 +140,20 @@ public function testImportOsm()
$this->runImport('test/test_data/dresden_osm.shp.zip');

$this->assertMessages($import_notice);

$endsWith = "13.737122 51.0542065)))'))";

if (extension_loaded('dbase')) {
$endsWith = "13.737122 51.0542065)))'),";
}

$this->assertStringContainsString(
"(GeomFromText('MULTIPOLYGON((("
. '13.737122 51.0542065,'
. '13.7373039 51.0541298,'
. '13.7372661 51.0540944,'
. '13.7370842 51.0541711,'
. "13.737122 51.0542065)))'))",
. $endsWith,
$sql_query
);
}
Expand All @@ -168,22 +175,39 @@ public function testDoImport()
//Test function called
$this->runImport('test/test_data/timezone.shp.zip');

//asset that all sql are executed
// asset that all sql are executed
$this->assertStringContainsString(
'CREATE DATABASE IF NOT EXISTS `SHP_DB` DEFAULT CHARACTER '
. 'SET utf8 COLLATE utf8_general_ci',
$sql_query
);
$this->assertStringContainsString(
'CREATE TABLE IF NOT EXISTS `SHP_DB`.`TBL_NAME` '
. '(`SPATIAL` geometry) DEFAULT CHARACTER '
. 'SET utf8 COLLATE utf8_general_ci;',
$sql_query
);
$this->assertStringContainsString(
'INSERT INTO `SHP_DB`.`TBL_NAME` (`SPATIAL`) VALUES',
$sql_query
);

// dbase extension will generate different sql statement
if (extension_loaded('dbase')) {
$this->assertStringContainsString(
'CREATE TABLE IF NOT EXISTS `SHP_DB`.`TBL_NAME` '
. '(`SPATIAL` geometry, `ID` int(2), `AUTHORITY` varchar(25), `NAME` varchar(42)) '
. 'DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;',
$sql_query
);

$this->assertStringContainsString(
'INSERT INTO `SHP_DB`.`TBL_NAME` (`SPATIAL`, `ID`, `AUTHORITY`, `NAME`) VALUES',
$sql_query
);
} else {
$this->assertStringContainsString(
'CREATE TABLE IF NOT EXISTS `SHP_DB`.`TBL_NAME` (`SPATIAL` geometry)',
$sql_query
);

$this->assertStringContainsString(
'INSERT INTO `SHP_DB`.`TBL_NAME` (`SPATIAL`) VALUES',
$sql_query
);
}


$this->assertStringContainsString(
"GeomFromText('POINT(1294523.1759236",
$sql_query
Expand Down

0 comments on commit c1c8e09

Please sign in to comment.