1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Utils;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\DummyResult;
use PhpMyAdmin\Utils\Gis;
use function hex2bin;
/**
* @covers \PhpMyAdmin\Utils\Gis
*/
#[\PHPUnit\Framework\Attributes\CoversClass(\PhpMyAdmin\Utils\Gis::class)]
class GisTest extends AbstractTestCase
{
/**
* @param string $expectedQuery The query to expect
* @param array $returnData The data to return for fetchRow
* @param bool $SRIDOption Use the SRID option or not
* @param int $mysqlVersion The mysql version to return for getVersion
*
* @dataProvider providerConvertToWellKnownText
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerConvertToWellKnownText')]
public function testConvertToWellKnownText(
string $expectedQuery,
array $returnData,
string $expectedResult,
bool $SRIDOption,
int $mysqlVersion
): void {
$resultStub = $this->createMock(DummyResult::class);
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
$dbi->expects($SRIDOption ? $this->once() : $this->exactly(2))
->method('getVersion')
->willReturn($mysqlVersion);
$dbi->expects($SRIDOption ? $this->once() : $this->exactly(2))
->method('tryQuery')
->with($expectedQuery)
->willReturn($resultStub);// Omit the real object
$resultStub->expects($SRIDOption ? $this->once() : $this->exactly(2))
->method('fetchRow')
->willReturn($returnData);
$GLOBALS['dbi'] = $dbi;
if (! $SRIDOption) {
// Also test default signature
self::assertSame($expectedResult, Gis::convertToWellKnownText(
(string) hex2bin('000000000101000000000000000000F03F000000000000F03F')
));
}
self::assertSame($expectedResult, Gis::convertToWellKnownText(
(string) hex2bin('000000000101000000000000000000F03F000000000000F03F'),
$SRIDOption
));
}
public static function providerConvertToWellKnownText(): array
{
return [
[
'SELECT ASTEXT(x\'000000000101000000000000000000f03f000000000000f03f\')',
['POINT(1 1)'],
'POINT(1 1)',
false,
50300,
],
[
'SELECT ASTEXT(x\'000000000101000000000000000000f03f000000000000f03f\'),'
. ' SRID(x\'000000000101000000000000000000f03f000000000000f03f\')',
['POINT(1 1)', '0'],
'\'POINT(1 1)\',0',
true,
50300,
],
[
'SELECT ST_ASTEXT(x\'000000000101000000000000000000f03f000000000000f03f\')',
['POINT(1 1)'],
'POINT(1 1)',
false,
50700,
],
[
'SELECT ST_ASTEXT(x\'000000000101000000000000000000f03f000000000000f03f\'),'
. ' ST_SRID(x\'000000000101000000000000000000f03f000000000000f03f\')',
['POINT(1 1)', '0'],
'\'POINT(1 1)\',0',
true,
50700,
],
[
'SELECT ST_ASTEXT(x\'000000000101000000000000000000f03f000000000000f03f\', \'axis-order=long-lat\'),'
. ' ST_SRID(x\'000000000101000000000000000000f03f000000000000f03f\')',
['POINT(1 1)', '0'],
'\'POINT(1 1)\',0',
true,
80001,
],
[
'SELECT ST_ASTEXT(x\'000000000101000000000000000000f03f000000000000f03f\'),'
. ' ST_SRID(x\'000000000101000000000000000000f03f000000000000f03f\')',
['POINT(1 1)', '0'],
'\'POINT(1 1)\',0',
true,
50700,
],
[
'SELECT ST_ASTEXT(x\'000000000101000000000000000000f03f000000000000f03f\', \'axis-order=long-lat\')',
['POINT(1 1)', '0'],
'POINT(1 1)',
false,
80001,
],
[
'SELECT ST_ASTEXT(x\'000000000101000000000000000000f03f000000000000f03f\')',
['POINT(1 1)', '0'],
'POINT(1 1)',
false,
50700,
],
];
}
public function testCreateDataOldMysql(): void
{
self::assertSame('abc', Gis::createData('abc', 50500));
self::assertSame('GeomFromText(\'POINT()\',10)', Gis::createData('\'POINT()\',10', 50500));
}
public function testCreateDataNewMysql(): void
{
self::assertSame('abc', Gis::createData('abc', 50600));
self::assertSame('ST_GeomFromText(\'POINT()\',10)', Gis::createData('\'POINT()\',10', 50600));
}
public function testGetFunctions(): void
{
$funcs = Gis::getFunctions();
self::assertArrayHasKey('Dimension', $funcs);
self::assertArrayHasKey('GeometryType', $funcs);
self::assertArrayHasKey('MBRDisjoint', $funcs);
}
}
|