/**
  * Test that price tests in cookie makes 1 time ran only.
  *
  * @since 1.1.0
  *
  * @group cookie
  * @group price_cookie
  * @group price
  *
  *
  * @covers
  */
 public function testEnsureRate()
 {
     $data = ingot_test_data_price::edd_tests(10);
     for ($i = 0; $i <= 10; $i++) {
         wp_remote_get(home_url());
     }
     $obj = new \ingot\testing\object\group($data['group_ID']);
     $stats_obj = new \ingot\testing\object\group_stats($obj->get_levers());
     $stats = $stats_obj->get_stats();
     $this->assertArrayHasKey('group', $stats);
     $this->assertInternalType('object', $stats['group']);
     /** @var \ingot\testing\object\stats $group_stats */
     $group_stats = $stats['group'];
     $this->assertSame(1, $group_stats->total);
     $this->assertSame(0, $group_stats->conversions);
 }
Beispiel #2
0
 /**
  * Create groups with variants, optionally added to them.
  *
  * @param bool $add_variants Optional. If true, the default, variants are added to groups via groups object. If false, they are created, IDs are returned but they will nto be associated with a group properly.
  * @param int $total_groups Optional. Default is 5.
  * @param int $variants_per_group Optional. Default is 3.
  * @param array $args Optional
  *
  * @return array
  */
 public static function make_groups($add_variants = true, $total_groups = 5, $variants_per_group = 3, $args = array())
 {
     $defaults = ['group_args' => ['name' => rand(), 'type' => 'click', 'sub_type' => 'button', 'meta' => ['link' => 'https://bats.com']], 'variant_args' => ['type' => 'click', 'group_ID' => 1, 'content' => rand()]];
     $keys = array_keys($defaults);
     foreach ($keys as $i => $key) {
         if (!empty($args[$key])) {
             $args[$key] = wp_parse_args($args[$key], $defaults[$key]);
         } else {
             $args[$key] = $defaults[$key];
         }
     }
     $groups = ['ids' => [], 'variants' => []];
     $group_args = $args['group_args'];
     $variant_args = $args['variant_args'];
     for ($g = 0; $g <= $total_groups; $g++) {
         $variants = [];
         $group_args['name'] = (string) $g . rand();
         $group_id = \ingot\testing\crud\group::create($group_args, true);
         $groups['ids'][] = $group_id;
         $variant_args['group_ID'] = $group_id;
         for ($v = 0; $v <= $variants_per_group; $v++) {
             $variant_id = \ingot\testing\crud\variant::create($variant_args, true);
             $variants[] = $variant_id;
         }
         $groups['variants'][$group_id] = $variants;
         if ($add_variants) {
             if (is_user_logged_in()) {
                 $obj = new \ingot\testing\object\group($group_id);
                 $obj->update_group(['variants' => $variants]);
             } else {
                 $_group = \ingot\testing\crud\group::read($group_id);
                 $_group['variants'] = $variants;
                 $saved = \ingot\testing\crud\group::update($_group, $group_id, true);
             }
         }
     }
     return $groups;
 }
 /**
  * Test that EDD sale of non-variable product is properly priced/recorded
  *
  * @since 1.1.0
  *
  * @group pricez
  * @group edd_price
  *
  * @covers \ingot\testing\tests\price\plugins\edd
  */
 public function testPriceTrackingNonVariableProduct()
 {
     $price_is = 10;
     $product = ingot_test_data_price::edd_create_simple_download($price_is);
     $group_id = \ingot\testing\crud\group::create(['type' => 'price', 'sub_type' => 'edd', 'meta' => ['product_ID' => $product->ID], 'wp_ID' => $product->ID], true);
     $variant_one = \ingot\testing\crud\variant::create(['group_ID' => $group_id, 'type' => 'price', 'meta' => ['price' => [0.5]], 'content' => $product->ID], true);
     $variant_two = \ingot\testing\crud\variant::create(['group_ID' => $group_id, 'type' => 'price', 'meta' => ['price' => [0.5]], 'content' => $product->ID], true);
     $group = \ingot\testing\crud\group::read($group_id);
     $group['variants'] = [$variant_one, $variant_two];
     \ingot\testing\crud\group::update($group, $group_id, true);
     $cookie_class = new \ingot\testing\cookies\price([]);
     $price_cookie = $cookie_class->get_cookie();
     $this->assertArrayHasKey('edd', $price_cookie);
     $this->assertFalse(empty($price_cookie['edd']));
     $this->assertInternalType('array', $price_cookie['edd']);
     $product_id = \ingot\testing\utility\price::get_product_ID($group);
     $this->assertEquals($product_id, $product->ID);
     $this->assertArrayHasKey($product_id, $price_cookie['edd']);
     new \ingot\testing\tests\price\plugins\edd($price_cookie['edd']);
     $test = \ingot\testing\utility\price::get_price_test_from_cookie('edd', $product->ID, $price_cookie);
     $this->assertInternalType('object', $test);
     $price_should_be = $test->get_price();
     //NOTE: USING edd_get_download_price here is to ensure we don't have recursion
     $this->assertEquals(edd_get_download_price($product->ID), $price_should_be);
     $group_obj = new \ingot\testing\object\group($group_id);
     $lever = $group_obj->get_lever($test->ID);
     $this->assertInternalType('object', $lever);
     $before_wins = $lever->getNumerator();
     $payment_id = ingot_test_data_price::edd_create_simple_payment($product);
     edd_complete_purchase($payment_id, 'publish', 'pending');
     $group_obj = new \ingot\testing\object\group($group_id);
     $lever = $group_obj->get_lever($test->ID);
     $this->assertInternalType('object', $lever);
     $after_wins = $lever->getNumerator();
     $this->assertEquals($before_wins + 1, $after_wins);
 }
Beispiel #4
0
 /**
  * Test that when we can update other stuff through group object
  *
  * @since 0.4.0
  *
  * @group group
  * @group group_object
  *
  * @covers \ingot\testing\object\group::get_group_config()
  * @covers \ingot\testing\object\group::update_group()
  */
 public function testUpdateThroughObject()
 {
     $groups = ingot_tests_make_groups(true, 1, 3);
     $id = $groups['ids'][0];
     $this->assertTrue(is_numeric($id));
     $variants = $groups['variants'][$id];
     $obj = new \ingot\testing\object\group($id);
     $this->assertEquals($variants, $obj->get_group_config()['variants']);
     $new_data = ['name' => 'BATMAN'];
     $obj->update_group($new_data);
     $group = \ingot\testing\crud\group::read($id);
     $this->assertEquals('BATMAN', $group['name']);
     $new_data = ['name' => 'Hi Roy', 'sub_type' => 'button_color'];
     $obj->update_group($new_data);
     $group = \ingot\testing\crud\group::read($id);
     $this->assertEquals('Hi Roy', $group['name']);
     $this->assertEquals('button_color', $group['sub_type']);
 }
 /**
  *
  *
  * @since 1.1.0
  *
  * @group group
  * @group destination
  * @group cookie
  * @group destination_cookie
  *
  * @covers \ingot\testing\tests\click\destination\init::get_test()
  * @covers \ingot\testing\tests\click\destination\init::set_tracking()
  * @covers \ingot\testing\tests\click\destination\cookie::get_cookie()
  */
 public function testCookieTracking()
 {
     $data = ingot_test_desitnation::create('page');
     $group_id = $data['group_ID'];
     $this->assertTrue(is_numeric($group_id));
     $group = \ingot\testing\crud\group::read($group_id);
     $this->assertInternalType('array', $group);
     $bandit = new \ingot\testing\bandit\content($group_id);
     $variant_id = $bandit->choose();
     $this->assertTrue(is_numeric($variant_id));
     \ingot\testing\tests\click\destination\init::set_tracking();
     \ingot\testing\tests\click\destination\init::get_test($group_id);
     $obj = new \ingot\testing\object\group($group_id);
     $levers = $obj->get_levers();
     $this->assertInternalType('array', $levers);
     $cookie_name = \ingot\testing\tests\click\destination\cookie::cookie_key($group_id);
     $variant_id = \ingot\testing\tests\click\destination\init::get_test($group_id);
     $this->assertTrue(is_numeric($variant_id));
     $_COOKIE[$cookie_name] = $variant_id;
     $this->assertEquals($variant_id, \ingot\testing\tests\click\destination\cookie::get_cookie($group_id));
     $obj = new \ingot\testing\object\group($group_id);
     $_levers = $obj->get_levers();
     for ($i = 0; $i <= 10; $i++) {
         \ingot\testing\tests\click\destination\init::set_tracking();
     }
     $obj = new \ingot\testing\object\group($group_id);
     $levers = $obj->get_levers();
     $this->assertEquals($levers, $_levers);
     $this->assertInternalType('array', $levers);
     $this->assertArrayHasKey($group_id, $levers);
     $this->assertArrayHasKey($variant_id, $levers[$group_id]);
     $lever = $levers[$variant_id];
     $this->assertInternalType('object', $lever);
     $this->assertEquals(0, $lever->getNumerator());
     $this->assertEquals(1, $lever->getDenominator());
 }
Beispiel #6
0
 /**
  * Get stats for a group
  *
  * @since 0.4.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @return \WP_Error|\WP_REST_Response
  */
 public function get_stats($request)
 {
     $url = $request->get_url_params();
     $id = helpers::v('id', $url, 0);
     $group = group::read($id);
     if (!is_array($group)) {
         if (is_wp_error($group)) {
             return $group;
         }
         return ingot_rest_response(['message' => esc_html__('No group found', 'ingot')]);
     }
     $obj = new \ingot\testing\object\group($group);
     $stats = $obj->get_stats();
     if ('admin' == $request->get_param('context')) {
         $names = $obj->names();
         if (!empty($stats['variants']) && !empty($names['variants'])) {
             foreach ($names['variants'] as $v_id => $name) {
                 if (isset($stats['variants'][$v_id])) {
                     $stats['variants'][$v_id] = (array) $stats['variants'][$v_id];
                     $stats['variants'][$v_id]['name'] = $name;
                     $stats['variants'][$v_id] = (object) $stats['variants'][$v_id];
                 }
             }
         }
         $stats['names'] = $names;
     }
     return ingot_rest_response($stats, 200);
 }