From f09d4c1f72e220eb45d574439f9a402a12c217dc Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Sun, 5 Apr 2020 10:36:45 +0300 Subject: [PATCH 1/2] Generate icml test --- composer.json | 1 + src/include/class-wc-retailcrm-icml.php | 4 +++- tests/bootstrap.php | 1 + tests/test-wc-retailcrm-icml.php | 29 +++++++++++++++++++++++++ tests/test-wc-retailcrm-plugin.php | 13 +++++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/test-wc-retailcrm-icml.php diff --git a/composer.json b/composer.json index 7bffffe..a298fba 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "require-dev": { "ext-json": "*", "ext-mbstring": "*", + "ext-simplexml": "*", "phpunit/phpunit": "6.*" } } diff --git a/src/include/class-wc-retailcrm-icml.php b/src/include/class-wc-retailcrm-icml.php index b703c16..bdc6ec4 100644 --- a/src/include/class-wc-retailcrm-icml.php +++ b/src/include/class-wc-retailcrm-icml.php @@ -413,7 +413,9 @@ if ( ! class_exists( 'WC_Retailcrm_Icml' ) ) : 'name' => $term->name ); - $thumbnail_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true); + $thumbnail_id = function_exists('get_term_meta') + ? get_term_meta($term->term_id, 'thumbnail_id', true) + : get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true); $picture = wp_get_attachment_url($thumbnail_id); if ($picture) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ed438a0..c2e29d6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -17,6 +17,7 @@ function _manually_load_plugin() { require $plugin_dir . 'src/include/class-wc-retailcrm-ga.php'; require $plugin_dir . 'src/include/class-wc-retailcrm-daemon-collector.php'; require $plugin_dir . 'src/include/class-wc-retailcrm-history.php'; + require $plugin_dir . 'src/include/class-wc-retailcrm-icml.php'; require $plugin_dir . 'src/retailcrm.php'; } diff --git a/tests/test-wc-retailcrm-icml.php b/tests/test-wc-retailcrm-icml.php new file mode 100644 index 0000000..a5a2cdc --- /dev/null +++ b/tests/test-wc-retailcrm-icml.php @@ -0,0 +1,29 @@ +generate(); + + $this->assertFileExists(ABSPATH . 'retailcrm.xml'); + $xml = simplexml_load_file(ABSPATH . 'retailcrm.xml'); + $res = $xml->xpath('/yml_catalog/shop/categories/category[@id]'); + + $this->assertNotEmpty($res); + + foreach ($res as $node) { + $this->assertEquals('category', $node->getName()); + } + } +} diff --git a/tests/test-wc-retailcrm-plugin.php b/tests/test-wc-retailcrm-plugin.php index d762c2d..f858c87 100644 --- a/tests/test-wc-retailcrm-plugin.php +++ b/tests/test-wc-retailcrm-plugin.php @@ -42,6 +42,19 @@ class WC_Retailcrm_Plugin_Test extends WC_Retailcrm_Test_Case_Helper } } + public function test_filter_cron_schedules() + { + $plugin = WC_Retailcrm_Plugin::getInstance(dirname(__DIR__ . '/../src/retailcrm.php')); + $schedules = $plugin->filter_cron_schedules(array()); + + $this->assertNotEmpty($schedules['five_minutes']); + $this->assertEquals(300, $schedules['five_minutes']['interval']); + $this->assertNotEmpty($schedules['three_hours']); + $this->assertEquals(10800, $schedules['three_hours']['interval']); + $this->assertNotEmpty($schedules['fiveteen_minutes']); + $this->assertEquals(900, $schedules['fiveteen_minutes']['interval']); + } + private function getResponseData() { return array( From 1912a779e01203097156662b7fd13cd67e8bb7c8 Mon Sep 17 00:00:00 2001 From: Akolzin Dmitry Date: Sun, 5 Apr 2020 12:13:09 +0300 Subject: [PATCH 2/2] create category in tests --- tests/test-wc-retailcrm-icml.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test-wc-retailcrm-icml.php b/tests/test-wc-retailcrm-icml.php index a5a2cdc..883f721 100644 --- a/tests/test-wc-retailcrm-icml.php +++ b/tests/test-wc-retailcrm-icml.php @@ -8,7 +8,14 @@ class WC_Retailcrm_Icml_Test extends WC_Retailcrm_Test_Case_Helper WC_Helper_Product::create_simple_product(); } - WC_Helper_Product::create_variation_product(); + wp_insert_term( + 'Test', // the term + 'product_cat', // the taxonomy + array( + 'description'=> 'Test', + 'slug' => 'test' + ) + ); } public function testGenerate()