don't split on ',' if within a function

This commit is contained in:
Matthew Bucci
2023-10-30 14:24:27 -07:00
parent ee6328fca7
commit ec9079d9c9
7 changed files with 100 additions and 24 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
if (!defined('ABSPATH')) {
define('ABSPATH', __DIR__ . "/../");
}
if (!defined('WPINC')) {
define('WPINC', 'wp-includes');
}
require_once __DIR__ . "/../pg4wp/db.php";
final class rewriteTest extends TestCase
{
public function test_it_can_rewrite_users_admin_query()
{
$sql = 'SELECT COUNT(NULLIF(`meta_value` LIKE \'%"administrator"%\', false)), COUNT(NULLIF(`meta_value` = \'a:0:{}\', false)), COUNT(*) FROM wp_usermeta INNER JOIN wp_users ON user_id = ID WHERE meta_key = \'wp_capabilities\'';
$expected = 'SELECT COUNT(NULLIF(meta_value ILIKE \'%"administrator"%\', false)) AS count0, COUNT(NULLIF(meta_value = \'a:0:{}\', false)) AS count1, COUNT(*) FROM wp_usermeta INNER JOIN wp_users ON user_id = "ID" WHERE meta_key = \'wp_capabilities\'';
$postgresql = pg4wp_rewrite($sql);
$this->assertSame($postgresql, $expected);
}
public function test_it_adds_group_by()
{
$sql = 'SELECT COUNT(id), username FROM users';
$expected = 'SELECT COUNT(id) AS count0, username FROM users GROUP BY username';
$postgresql = pg4wp_rewrite($sql);
$this->assertSame($postgresql, $expected);
}
}
+1 -1
View File
@@ -1 +1 @@
{"mysql":"SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM wp_comments WHERE comment_post_ID IN ( '51', '17', '11', '7' ) AND comment_approved = '0' GROUP BY comment_post_ID","postgresql":"SELECT \"comment_post_ID\" , COUNT(\"comment_ID\" ) as num_comments FROM wp_comments WHERE \"comment_post_ID\" IN ( '51', '17', '11', '7' ) AND comment_approved = '0' GROUP BY \"comment_post_ID\" "}
{"mysql":"SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM wp_comments WHERE comment_post_ID IN ( '51', '17', '11', '7' ) AND comment_approved = '0' GROUP BY comment_post_ID","postgresql":"SELECT \"comment_post_ID\" , COUNT(\"comment_ID\" ) as num_comments FROM wp_comments WHERE \"comment_post_ID\" IN ( '51', '17', '11', '7' ) AND comment_approved = '0' GROUP BY \"comment_post_ID\" "}
+1 -1
View File
@@ -1 +1 @@
{"mysql":"SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM wp_comments WHERE comment_post_ID IN ( '55', '51', '17', '11', '7' ) AND comment_approved = '0' GROUP BY comment_post_ID","postgresql":"SELECT \"comment_post_ID\" , COUNT(\"comment_ID\" ) as num_comments FROM wp_comments WHERE \"comment_post_ID\" IN ( '55', '51', '17', '11', '7' ) AND comment_approved = '0' GROUP BY \"comment_post_ID\" "}
{"mysql":"SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM wp_comments WHERE comment_post_ID IN ( '55', '51', '17', '11', '7' ) AND comment_approved = '0' GROUP BY comment_post_ID","postgresql":"SELECT \"comment_post_ID\" , COUNT(\"comment_ID\" ) as num_comments FROM wp_comments WHERE \"comment_post_ID\" IN ( '55', '51', '17', '11', '7' ) AND comment_approved = '0' GROUP BY \"comment_post_ID\" "}
+7 -2
View File
@@ -1,8 +1,13 @@
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
const ABSPATH = __DIR__ . "/../";
const WPINC = "wp-includes";
if (!defined('ABSPATH')) {
define('ABSPATH', __DIR__ . "/../");
}
if (!defined('WPINC')) {
define('WPINC', 'wp-includes');
}
require_once __DIR__ . "/../pg4wp/db.php";