Пример #1
0
 /**
  * Test that the wp_ID column gets added to groups via the 1.1.0 updater
  *
  * @since 1.1.0
  *
  * @group db
  *
  * @covers \ingot\testing\db\add_wp_id_column()
  * @covers \ingot\testing\db\run()
  */
 public function test1dot1Update()
 {
     global $wpdb;
     $table_name = \ingot\testing\crud\group::get_table_name();
     //test method in isolation
     $wpdb->query(sprintf('ALTER TABLE %s DROP COLUMN wp_ID', $table_name));
     $updater = new \ingot\testing\db\upgrade('1.1.0');
     $updater->add_wp_id_column();
     $data = ingot_test_data_price::edd_tests(10);
     $this->assertTrue(is_array($data));
     $this->assertTrue(is_numeric($data['group_ID']));
     $product_ID = $data['product_ID'];
     $results = $wpdb->query(sprintf('SELECT * FROM `%s` WHERE `wp_ID` = %d', $table_name, $product_ID));
     $this->assertTrue(!empty($results));
     //test using run method
     $wpdb->query(sprintf('ALTER TABLE %s DROP COLUMN wp_ID', $table_name));
     $updater->run();
     $data = ingot_test_data_price::edd_tests(10);
     $this->assertTrue(is_array($data));
     $this->assertTrue(is_numeric($data['group_ID']));
     $product_ID = $data['product_ID'];
     $results = $wpdb->query(sprintf('SELECT * FROM `%s` WHERE `wp_ID` = %d', $table_name, $product_ID));
     $this->assertTrue(!empty($results));
     //test that running it anyway doesn't break stuff
     $results = $wpdb->query(sprintf('SELECT * FROM `%s` WHERE `wp_ID` = %d', $table_name, $product_ID));
     $this->assertTrue(!empty($results));
 }
Пример #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
 /**
  * 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);
 }
Пример #4
0
 /**
  * Test getting price tests via API
  *
  * @since 1.0.0
  *
  * @group price
  * @group rest
  * @group group_rest
  * @group group
  *
  * @covers ingot\testing\api\rest\groups::get_items()
  */
 public function testGetPrice()
 {
     wp_set_current_user(1);
     ingot_test_data_price::edd_tests();
     ingot_test_data_price::edd_tests();
     ingot_tests_make_groups(true, 4, 3);
     $groups = ingot_tests_make_groups(true, 4, 3);
     $request = new \WP_REST_Request('GET', $this->namespaced_route);
     $request->set_query_params(array('type' => 'price'));
     $response = $this->server->dispatch($request);
     $response = rest_ensure_response($response);
     $this->assertEquals(200, $response->get_status());
     $data = (array) $response->get_data();
     foreach ($data as $group) {
         $this->assertEquals('price', $group['type']);
     }
 }
 /**
  * Test that we can query for these tests properly
  *
  * @since 1.1.0
  *
  * @group group
  * @group destination
  * @group cookie
  * @group destination_cookie
  *
  * @covers \ingot\testing\tests\click\destination\init::get_destination_tests()
  */
 public function testQuery()
 {
     ingot_test_data_price::edd_tests();
     ingot_tests_data::make_groups();
     $x = 0;
     foreach (\ingot\testing\tests\click\destination\types::destination_types() as $type) {
         if ('hook' == $type) {
             continue;
         }
         $data = ingot_test_desitnation::create($type);
         $this->assertTrue(is_numeric($data['group_ID']));
         $the_groups[] = $data['group_ID'];
         $x++;
     }
     $groups = \ingot\testing\tests\click\destination\init::get_destination_tests();
     $this->assertSame($x, count($groups));
     $this->assertEquals($the_groups, $groups);
 }
Пример #6
0
 /**
  * Test price testing setup
  *
  * @since 1.1.0
  *
  * @group cookie
  * @group price_cookie
  * @group price
  *
  *
  * @covers \ingot\testing\cookies\set::price_testing()
  */
 public function testRunPriceTests()
 {
     return;
     $this->assertFalse((bool) did_action('ingot_loaded'));
     $group_1 = ingot_test_data_price::edd_tests(10);
     $group_2 = ingot_test_data_price::edd_tests(15);
     $product_1 = $group_1['product_ID'];
     $product_2 = $group_2['product_ID'];
     $cookies = \ingot\testing\cookies\init::create([]);
     $this->assertFalse(is_wp_error($cookies));
     $ingot_cookies = $cookies->get_ingot_cookie(false);
     $this->assertInternalType('array', $ingot_cookies);
     $this->assertArrayHasKey('edd', $ingot_cookies);
     $objects = \ingot\testing\cookies\set::price_testing($ingot_cookies);
     $this->assertArrayHasKey('edd', $objects);
     $this->assertInternalType('object', $objects['edd']);
     /** @var ingot\testing\tests\price\plugins\edd $edd */
     $edd = $objects['edd'];
     $products = $edd->get_products();
     $this->assertEquals(2, count($products));
     $this->assertArrayHasKey($product_1, $products);
     $this->assertArrayHasKey($product_2, $products);
 }
Пример #7
0
 public function _testVariablePrice()
 {
     $download = ingot_test_data_price::edd_create_variable_download(10);
     $prices = edd_get_variable_prices($download->ID);
 }
Пример #8
0
 /**
  * Test GET /products for EDD
  *
  * @since 1.1.0
  *
  * @group products_api
  * @group edd
  * @group price
  *
  * @covers ingot\testing\api\rest/products::get_price()
  */
 public function testGetEDDPrice()
 {
     wp_set_current_user(1);
     ingot_test_data_price::edd_create_simple_download(72);
     $product = ingot_test_data_price::edd_create_simple_download(7);
     $request = new \WP_REST_Request('GET', $this->namespaced_route . '/price/' . $product->ID);
     $request->set_query_params(array('plugin' => 'edd'));
     $response = $this->server->dispatch($request);
     $response = rest_ensure_response($response);
     $this->assertEquals(200, $response->get_status());
     $data = (array) $response->get_data();
     $this->assertArrayHasKey('price', $data);
     $this->assertSame(ingot_sanitize_amount(7), $data['price']);
 }
Пример #9
0
 /**
  * Test get price of EDD product
  *
  * @since 1.1.0
  *
  * @group price
  * @group helper
  * @group edd
  *
  * @covers \ingot\testing\utility\price::get_price()
  */
 public function testGetPriceEDD()
 {
     $product_1 = ingot_test_data_price::edd_create_simple_download(10.51);
     $product_2 = ingot_test_data_price::edd_create_simple_download(5.21);
     $this->assertSame(ingot_sanitize_amount(10.51), \ingot\testing\utility\price::get_price('edd', $product_1->ID));
     $this->assertSame(ingot_sanitize_amount(5.21), \ingot\testing\utility\price::get_price('edd', $product_2->ID));
 }
 /**
  * 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']);
     }
 }
Пример #11
0
 /**
  * Test that when we can create price tests properly
  *
  * @since 0.4.0
  *
  * @group crud
  * @group group
  * @group group_crud
  * @group price
  *
  * @covers \ingot\testing\crud\group::get_items()
  */
 public function testQueryByType()
 {
     $data = ingot_test_data_price::edd_tests();
     ingot_tests_make_groups(false, 11, 1);
     $data = ingot_test_data_price::edd_tests();
     $group_id = $data['group_ID'];
     $items = \ingot\testing\crud\group::get_items(['type' => 'price', 'limit' => 5]);
     $this->assertTrue(is_array($items));
     $this->assertNotEmpty($items);
     $this->assertSame(2, count($items));
     foreach ($items as $item) {
         $this->assertEquals('price', $item['type']);
     }
 }