/** * Get possible destination test types * * @param bool $with_labels Optional. If true, name/description returned. If false, the default only "slugs" * * @return array */ public static function destination_types($with_labels = false, $api_format = false) { $types = self::get_internal_types(); if (!ingot_is_woo_active()) { unset($types['cart_woo']); unset($types['sale_woo']); } if (!ingot_is_edd_active()) { unset($types['cart_edd']); unset($types['sale_edd']); } /** * Allowed test types * * Types are keys, labels are values * * @since 0.0.7 * * @param array $types The allowed click test types */ $types = apply_filters('ingot_allowed_click_types', $types); if ($api_format) { $_types = []; foreach ($types as $value => $type) { $_types[$value] = array_merge($type, ['value' => $value]); } return $_types; } if (false == $with_labels) { $types = array_keys($types); } return $types; }
/** * Test EDD is active * * @since 1.1.0 * * @group price * @group edd * @group functions * * @covers ingot_is_edd_active() * @covers ingot_check_ecommerce_active() */ public function testEDDActive() { if (class_exists('Easy_Digital_Downloads')) { $this->assertTrue(ingot_is_edd_active()); $this->assertTrue(ingot_check_ecommerce_active('edd')); } else { $this->assertFalse(ingot_is_edd_active()); $this->assertFalse(ingot_check_ecommerce_active('edd')); } }
/** * Run the price testing setup * * @since 1.1.0 * * @param array $ingot_cookies Cookies as an array * * @return array Array of setup class objects */ public static function price_testing($ingot_cookies) { $objects = []; if (ingot_is_edd_active() && isset($ingot_cookies['price']['edd']) && !empty($ingot_cookies['price']['edd'])) { $objects['edd'] = new edd($ingot_cookies['price']['edd']); } if (ingot_is_woo_active() && isset($ingot_cookies['price']['woo']) && !empty($ingot_cookies['price']['woo'])) { $object['woo'] = new woo($ingot_cookies['price']['woo']); } /** * Runs after price tests are initialized with the object for each of those classes. * * NOTE: May be empty array if no price testing is possible. * * @since 1.1.0 * * @param array $ingot_cookies Cookies as an array */ return apply_filters('ingot_price_test_objects', $objects); }
/** * Hooks to use for tracking * * @since 1.1.0 * * @return array */ public static function hooks() { $hooks = ['template_redirect' => null]; if (ingot_is_edd_active()) { $hooks['edd_post_add_to_cart'] = null; $hooks['edd_complete_purchase'] = null; } if (ingot_is_woo_active()) { $hooks['woocommerce_add_to_cart'] = null; $hooks['woocommerce_payment_complete_order_status'] = null; } if (ingot_is_give_active()) { $hooks['give_complete_purchase'] = null; } /** * Change or add hooks for destination conversion tracking * * @since 1.1.0 * * @param array $hooks hook_name => callback If callback is null, then it must exist in the `ingot\testing\tests\click\destination\hooks` class or else bad things... */ return apply_filters('ingot_destination_hooks', $hooks); }
/** * Data needed in app * * @since 0.2.0 * * @access protected * * @return array */ protected function vars() { return array('api' => esc_url_raw(util::get_url()), 'nonce' => wp_create_nonce('wp_rest'), 'partials' => esc_url_raw(INGOT_URL . 'assets/admin/partials/'), 'spinner_url' => trailingslashit(INGOT_URL) . 'assets/img/loading.gif', 'edd_active' => esc_attr(ingot_is_edd_active()), 'woo_active' => esc_attr(ingot_is_woo_active()), 'price_tests_enabled' => esc_attr(ingot_enable_price_testing()), 'click_type_options' => types::allowed_click_types(true), 'price_type_options' => types::allowed_price_types(), 'destinations' => \ingot\testing\tests\click\destination\types::destination_types(true, true), 'dev_mode' => INGOT_DEV_MODE); }
/** * Initialize price testing * * @uses "ingot_cookies_set" * * @params \ingot\testing\cookies\init $cookies Cookies object * * @since 0.0.9 */ public static function init_price_tests($cookies) { new \ingot\testing\tests\price\init($cookies->get_ingot_cookie(false)['price']); if (ingot_is_edd_active()) { self::track_edd(); } }
/** * Track EDD sale conversions * * @since 1.1.0 * * @group group * @group destination * @group edd * * @covers \ingot\testing\tests\click\destination\hooks::edd_complete_purchase() * @covers \ingot\testing\tests\click\destination\hooks::add_hooks() */ public function testEDDConversionsSale() { if (ingot_is_edd_active()) { $this->assertTrue(\ingot\testing\tests\click\destination\types::allowed_destination_type('sale_edd')); $product = ingot_test_data_price::edd_create_simple_download(10); $data = ingot_test_desitnation::create('sale_edd'); $group_id = $data['group_ID']; $this->assertTrue(is_numeric($group_id)); $variants = $data['variants']; new \ingot\testing\bandit\content($group_id); $variant_id = \ingot\testing\tests\click\destination\init::get_test($group_id); $this->assertTrue(is_numeric($variant_id)); \ingot\testing\tests\click\destination\init::set_tracking(); $this->assertTrue(in_array(\ingot\testing\tests\click\destination\init::get_test($group_id), $variants)); $variant_id = \ingot\testing\tests\click\destination\init::get_test($group_id); $hooks = new \ingot\testing\tests\click\destination\hooks([$group_id]); $payment_id = ingot_test_data_price::edd_create_simple_payment($product); edd_complete_purchase($payment_id, 'publish', 'pending'); $group = \ingot\testing\crud\group::read($group_id); $totals = \ingot\testing\utility\group::get_total($group); $this->assertEquals(3, $totals['total']); $this->assertEquals(2, $totals['conversions']); } }