예제 #1
0
파일: track.php 프로젝트: Ramoonus/ingot
 /**
  * Check products in a sale for any we are testing
  *
  * @since 0.0.9
  *
  * @access protected
  *
  * @param array $products
  * @param string $plugin
  */
 protected static function check_for_winners($products, $plugin)
 {
     $winners = array();
     $testing = price::current();
     if (!empty($testing) && isset($testing[$plugin])) {
         foreach ($products as $product) {
             if (isset($testing[$plugin][$product])) {
                 $winners[] = $testing[$plugin][$product];
             }
         }
         self::record_victories($winners);
     }
 }
예제 #2
0
 /**
  * Test inflating/defalting object
  *
  * @since 1.1.0
  *
  * @group price_object
  * @group price
  * @group edd_price
  */
 function testInflationDefaltion()
 {
     $data = ingot_test_data_price::edd_tests(10);
     $bandit = new \ingot\testing\bandit\price($data['group_ID']);
     $variant_id = $bandit->choose();
     $args = ['ID' => $variant_id, 'expires' => 167234];
     $obj = new \ingot\testing\object\price\test($args);
     $as_json = wp_json_encode($obj);
     $this->assertEquals(wp_json_encode($args), $as_json);
     $inflated = \ingot\testing\utility\price::inflate_price_test($as_json);
     $this->assertSame($obj->ID, $inflated->ID);
     $this->assertSame($obj->variant, $inflated->variant);
 }
예제 #3
0
 /**
  * Check price detail util
  *
  * @since 0.2.0
  *
  * @covers \ingot\testing\utility\price::price_detail()
  */
 function testPriceDetails()
 {
     return;
     $product_id = 9;
     $params = array('product_ID' => $product_id, 'default' => rand(-0.9, 0.9));
     for ($i = 0; $i <= 3; $i++) {
         $id = \ingot\testing\crud\price_test::create($params);
         $tests[$i] = $id;
         $params['default'] = rand(-0.9, 0.9);
     }
     $params = array('type' => 'price', 'plugin' => 'edd', 'group_name' => rand(), 'test_order' => $tests, 'product_ID' => $product_id);
     $group_id = \ingot\testing\crud\price_group::create($params);
     $group = \ingot\testing\crud\price_group::read($group_id);
     $sequence_id = $group['current_sequence'];
     $test = \ingot\testing\crud\price_test::read($tests[rand(0, 3)]);
     $details = \ingot\testing\utility\price::price_detail($test, 'a', $sequence_id, $group_id);
     $this->assertEquals($details['plugin'], $test['plugin']);
     $this->assertEquals($details['product_ID'], $test['product_ID']);
     $this->assertEquals($details['test_ID'], $test['ID']);
     $this->assertEquals($details['sequence_ID'], $sequence_id);
     $this->assertEquals($details['group_ID'], $group_id);
 }
예제 #4
0
 /**
  * Test contents of price cookie
  *
  * @since 1.1.0
  *
  * @group cookie
  * @group price_cookie
  * @group price
  *
  * @covers \ingot\testing\cookies\price()
  */
 public function testCookieSetup()
 {
     $group_1 = ingot_test_data_price::edd_tests(10);
     $group_2 = ingot_test_data_price::edd_tests(15);
     $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_1 = \ingot\testing\utility\price::get_product_ID($group_1['group_ID']);
     $product_2 = \ingot\testing\utility\price::get_product_ID($group_2['group_ID']);
     $this->assertArrayHasKey($product_1, $price_cookie['edd']);
     $this->assertArrayHasKey($product_2, $price_cookie['edd']);
     $this->assertSame(2, count($price_cookie['edd']));
     foreach ($price_cookie['edd'] as $content) {
         $content = \ingot\testing\utility\price::inflate_price_test($content);
         $this->assertInternalType('object', $content);
         foreach (['plugin', 'ID', 'variant', 'expires', 'price', 'product'] as $key) {
             $this->assertObjectHasAttribute($key, $content);
         }
         $this->assertInternalType('object', $content->product);
     }
 }
예제 #5
0
 /**
  * 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);
 }
예제 #6
0
 /**
  * Add test to cookie
  *
  * @since 1.1.0
  *
  * @access protected
  *
  * @param array $group Group config
  */
 protected function add_test($group)
 {
     if (group::valid($group)) {
         $test = $this->setup_test_object($group);
         if (is_object($test)) {
             $product_ID = \ingot\testing\utility\price::get_product_ID($group);
             if (is_object($test) && is_numeric($product_ID)) {
                 $this->cookie[$group['sub_type']][$product_ID] = wp_json_encode($test);
             }
         }
     }
 }
예제 #7
0
 /**
  * Generic save for read/update
  *
  * @since 0.0.4
  *
  * @param array $data Item con
  * @param int $id Optional. Item ID. Not used or needed if using to create.
  * @param bool|false $bypass_cap
  *
  * @return int|bool||WP_Error Item ID if created, or false if not created, or error if not allowed to create.
  */
 protected static function save($data, $id = null, $bypass_cap = false)
 {
     $data = static::prepare_data($data);
     if (is_wp_error($data) || !is_array($data)) {
         return $data;
     }
     if ('group' === static::what() && is_null($id)) {
         if ('price' == $data['type']) {
             if (!isset($data['wp_ID'])) {
                 //shouldn't be needed.
                 return new \WP_Error();
             }
             if (isset($data['wp_ID']) && false !== ($existing = price::product_test_exists($data['wp_ID']))) {
                 return new \WP_Error('ingot-price-test-for-product-exists', __(sprintf('Product ID %d is already being tested by test group ID %d', $data['meta']['product_ID'], $existing), 'ingot'), ['product_ID' => $data['meta']['product_ID'], 'group_ID' => $existing]);
             }
         }
     }
     $table_name = static::get_table_name();
     foreach ($data as $key => $datum) {
         if (is_array($data[$key])) {
             if (empty($data[$key])) {
                 $data[$key] = serialize([]);
             } else {
                 $data[$key] = helpers::sanitize($data[$key]);
                 $data[$key] = serialize($datum);
             }
         }
     }
     if (self::can($id, $bypass_cap)) {
         global $wpdb;
         if ($id) {
             $data['ID'] = $id;
             $wpdb->update($table_name, $data, array('ID' => (int) $id));
         } else {
             unset($data['ID']);
             $wpdb->insert($table_name, $data);
             $id = $wpdb->insert_id;
         }
         return $id;
     } else {
         return false;
     }
 }
예제 #8
0
 /**
  * Test that we can't create a group for a product that is already being tested
  *
  * @since 1.1.0
  *
  * @group price
  * @group helper
  * @covers 	\ingot\testing\utility\price::product_test_exists()
  */
 public function testPriceTestExists()
 {
     $group = \ingot\testing\crud\group::create(['name' => 'd', 'type' => 'price', 'sub_type' => 'edd', 'meta' => ['product_ID' => 169], 'wp_ID' => 169], true);
     $this->assertTrue(is_numeric($group));
     $existing = \ingot\testing\utility\price::product_test_exists(169);
     $this->assertEquals($existing, $group);
 }
예제 #9
0
파일: price.php 프로젝트: Ramoonus/ingot
 /**
  * Add a test
  *
  * @since 0.0.9
  *
  * @access protected
  *
  * @param array $sequence
  */
 protected function add_test($sequence)
 {
     $a_or_b = $this->a_or_b($sequence, false);
     $group = price_group::read($sequence['group_ID']);
     if (is_array($group)) {
         $test_id = $this->get_test_id($sequence, $a_or_b);
         $test = test::read($test_id);
         $test_details = \ingot\testing\utility\price::price_detail($test_id, $a_or_b, $sequence['ID'], $group);
         $this->price_cookie[$sequence['ID']] = $test_details;
     }
 }
예제 #10
0
 /**
  * Get price of a product
  *
  * @since 1.1.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @return \WP_Error|\WP_REST_Response
  */
 public function get_price($request)
 {
     $price = price::get_price($request->get_param('plugin'), $request->get_url_params()['id']);
     return ingot_rest_response(['price' => $price]);
 }
예제 #11
0
 /**
  * Set product property
  *
  * @since 1.1.0
  *
  * @access private
  */
 private function set_product()
 {
     if (!is_object($this->product)) {
         $group = group::read($this->variant['group_ID']);
         if (in_array($group['sub_type'], types::allowed_price_types())) {
             $this->product = price::get_product($group);
         }
     }
 }
예제 #12
0
 /**
  * @param $products
  */
 private function set_products($products)
 {
     foreach ($products as $id => $test) {
         if (is_string($test)) {
             $test = json_decode($test, true);
         }
         if (is_array($test)) {
             $test = \ingot\testing\utility\price::inflate_price_test($test);
             $this->products[$id] = $test;
         }
     }
 }