1
0
mirror of synced 2025-01-18 17:01:41 +03:00
woocommerce-module/tests/test-wc-retailcrm-ga.php
Akolzin Dmitry cc4e8c9c5b update build
2020-02-25 13:45:17 +03:00

62 lines
1.6 KiB
PHP

<?php
class WC_Retailcrm_Google_Analytics_Test extends WC_Retailcrm_Test_Case_Helper
{
private $ga;
private $options;
private $order;
private $orderKey;
public function setUp()
{
$this->order = WC_Helper_Order::create_order(0);
$this->orderKey = $this->order->get_order_key();
$this->setOptions();
$this->options = get_option(WC_Retailcrm_Base::$option_key);
$this->ga = WC_Retailcrm_Google_Analytics::getInstance($this->options);
}
public function test_initialize_analytics()
{
$js = $this->ga->initialize_analytics();
$this->assertContains($this->options['ua_code'], $js);
$this->assertContains($this->options['ua_custom'], $js);
}
/**
* @param $checkout
* @dataProvider dataProvider
*/
public function test_send_analytics($checkout)
{
if ($checkout) {
$_GET['key'] = $this->orderKey;
}
$js = $this->ga->send_analytics();
if ($checkout) {
$this->assertContains((string)$this->order->get_id(), $js);
$this->assertContains((string)$this->order->get_total(), $js);
$this->assertContains((string)$this->order->get_total_tax(), $js);
$this->assertContains((string)$this->order->get_shipping_total(), $js);
} else {
$this->assertEmpty($js);
}
}
public function dataProvider()
{
return array(
array(
'checkout' => false
),
array(
'checkout' => true
)
);
}
}