123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace Medoo\Tests;
- use Medoo\Medoo;
- use InvalidArgumentException;
- /**
- * @coversDefaultClass \Medoo\Medoo
- */
- class QuoteTest extends MedooTestCase
- {
- /**
- * @covers ::quote()
- * @dataProvider typesProvider
- */
- public function testQuote($type)
- {
- $this->setType($type);
- $quotedString = $this->database->quote("Co'mpl''ex \"st'\"ring");
- $expected = [
- 'mysql' => <<<EOD
- 'Co\'mpl\'\'ex \"st\'\"ring'
- EOD,
- 'mssql' => <<<EOD
- 'Co''mpl''''ex "st''"ring'
- EOD,
- 'sqlite' => <<<EOD
- 'Co''mpl''''ex "st''"ring'
- EOD,
- 'pgsql' => <<<EOD
- 'Co''mpl''''ex "st''"ring'
- EOD,
- 'oracle' => <<<EOD
- 'Co''mpl''''ex "st''"ring'
- EOD
- ];
- $this->assertEquals($expected[$type], $quotedString);
- }
- /**
- * @covers ::columnQuote()
- */
- public function testColumnQuote()
- {
- $this->assertEquals('"ColumnName"', $this->database->columnQuote("ColumnName"));
- $this->assertEquals('"Column"."name"', $this->database->columnQuote("Column.name"));
- $this->assertEquals('"Column"."Name"', $this->database->columnQuote("Column.Name"));
- }
- public function columnNamesProvider(): array
- {
- return [
- ["9ColumnName"],
- ["@ColumnName"],
- [".ColumnName"],
- ["ColumnName."],
- ["_ColumnName"],
- ["ColumnName (alias)"]
- ];
- }
- /**
- * @covers ::columnQuote()
- * @dataProvider columnNamesProvider
- */
- public function testIncorrectColumnQuote($column)
- {
- $this->expectException(InvalidArgumentException::class);
- $this->database->columnQuote($column);
- }
- /**
- * @covers ::tableQuote()
- */
- public function testTableQuote()
- {
- $this->assertEquals('"TableName"', $this->database->tableQuote("TableName"));
- }
- /**
- * @covers ::tableQuote()
- */
- public function testPrefixTableQuote()
- {
- $database = new Medoo([
- 'testMode' => true,
- 'prefix' => 'PREFIX_'
- ]);
- $this->assertEquals('"PREFIX_TableName"', $database->tableQuote("TableName"));
- }
- public function tableNamesProvider(): array
- {
- return [
- ["9TableName"],
- ["@TableName"],
- [".TableName"],
- ["TableName."],
- ["_TableName"],
- ["Table.name"]
- ];
- }
- /**
- * @covers ::tableQuote()
- * @dataProvider tableNamesProvider
- */
- public function testIncorrectTableQuote($table)
- {
- $this->expectException(InvalidArgumentException::class);
- $this->database->tableQuote($table);
- }
- }
|