1
0
mirror of synced 2025-01-19 09:21:43 +03:00
woocommerce-module/tests/test-wc-retailcrm-ga.php

68 lines
1.7 KiB
PHP
Raw Normal View History

2018-05-28 12:56:19 +03:00
<?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
2021-12-20 11:41:41 +03:00
*
2018-05-28 12:56:19 +03:00
* @dataProvider dataProvider
*/
public function test_send_analytics($checkout)
{
2021-12-20 11:41:41 +03:00
if ($checkout === true) {
2018-05-28 12:56:19 +03:00
$_GET['key'] = $this->orderKey;
2021-12-20 11:41:41 +03:00
} elseif (is_null($checkout)) {
$_GET['key'] = '';
2018-05-28 12:56:19 +03:00
}
$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
),
2021-12-20 11:41:41 +03:00
array(
'checkout' => null
),
2018-05-28 12:56:19 +03:00
array(
'checkout' => true
)
);
}
}