示例#1
0
 /**
  * Test creating of object
  *
  * @since 1.1.0
  *
  * @group price_object
  * @group price
  * @group edd_price
  */
 public function testWithMinimal()
 {
     $data = ingot_test_data_price::edd_tests(10);
     $bandit = new \ingot\testing\bandit\price($data['group_ID']);
     $variant_id = $bandit->choose();
     $obj = new \ingot\testing\object\price\test(['ID' => $variant_id, 'expires' => time() * 167234]);
     $product_ID = \ingot\testing\utility\price::get_product_ID($data['group']);
     $variant = \ingot\testing\crud\variant::read($variant_id);
     $this->assertEquals($variant_id, $obj->ID);
     $this->assertEquals($variant, $obj->variant);
     $this->assertEquals(get_post($product_ID), $obj->product);
     $this->assertEquals('edd_get_download_price', $obj->price_callback);
 }
 /**
  * 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);
     }
 }
示例#3
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);
 }
示例#4
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);
             }
         }
     }
 }