From ae2cbff59b56a050a546e2c5bed281b00092c8f3 Mon Sep 17 00:00:00 2001 From: Matthew Bucci Date: Mon, 30 Oct 2023 21:32:25 -0700 Subject: [PATCH] add test for verifying parsing of insert statements and caching --- tests/parseTest.php | 44 ++++++++++++++++++++++++++++++++ tests/verifyAgainstStubsTest.php | 10 ++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/parseTest.php diff --git a/tests/parseTest.php b/tests/parseTest.php new file mode 100644 index 0000000..128e65d --- /dev/null +++ b/tests/parseTest.php @@ -0,0 +1,44 @@ +assertSame($GLOBALS['pg4wp_ins_table'], "wp_options"); + $this->assertSame($GLOBALS['pg4wp_ins_field'], "option_name"); + } + + + public function test_it_can_parse_a_page_creation_correctly() + { + + $sql = 'INSERT INTO wp_posts (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt, post_status, post_type, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type, guid) VALUES (\'1\', \'2023-10-31 03:54:02\', now() AT TIME ZONE \'gmt\', \'\', \'\', \'Auto Draft\', \'\', \'auto-draft\', \'page\', \'closed\', \'closed\', \'\', \'\', \'\', \'\', \'2023-10-31 03:54:02\', now() AT TIME ZONE \'gmt\', 0, 0, \'\', \'\')'; + $postgresql = pg4wp_rewrite($sql); + $this->assertSame($GLOBALS['pg4wp_ins_table'], "wp_posts"); + $this->assertSame($GLOBALS['pg4wp_ins_field'], "post_author"); + } + + + protected function setUp(): void + { + global $wpdb; + $wpdb = new class() { + public $options = "wp_options"; + public $categories = "wp_categories"; + }; + } + +} \ No newline at end of file diff --git a/tests/verifyAgainstStubsTest.php b/tests/verifyAgainstStubsTest.php index 3b21b5d..1a568c8 100644 --- a/tests/verifyAgainstStubsTest.php +++ b/tests/verifyAgainstStubsTest.php @@ -22,6 +22,16 @@ final class verifyAgainstStubsTest extends TestCase $data = json_decode(file_get_contents(self::STUBS_DIRECTORY . "/" . $file), true); $this->assertSame(pg4wp_rewrite($data['mysql']), $data['postgresql']); } + } + protected function setUp(): void + { + global $wpdb; + $wpdb = new class() { + public $categories = "wp_categories"; + public $comments = "wp_comments"; + public $prefix = "wp_"; + public $options = "wp_options"; + }; } } \ No newline at end of file