/** * Set tests property with all test we need to track * * @since 1.1.0 * * @access private * * @return array|mixed */ private function set_groups() { $key = md5(__FUNCTION__); if (WP_DEBUG || !is_array($groups = get_transient($key)) && !empty($groups)) { foreach (types::allowed_price_types() as $plugin) { $this->groups[$plugin] = price_query::find_by_plugin($plugin); } set_transient($key, $this->groups, HOUR_IN_SECONDS); } }
/** * Set tests property by product ID * * @since 1.1.0 * * @access private * * @param int $id Product ID */ private function set_tests_by_product_id($id) { $this->tests = price_query::find_by_product($id); }
/** * Test that we can query by plugin and exclude those without variants * * @since 1.1.0 * * @group xs * @group price_query * @group price * * @covers \ingot\testing\crud\price_query::find_by_plugin() */ public function testQueryByPluginNoVariant() { $args = ['type' => 'price', 'sub_type' => 'edd', 'meta' => ['product_ID' => 5], 'wp_ID' => 5]; $variant_args = ['type' => 'price', 'meta' => ['price' => []], 'content' => 5]; for ($i = 0; $i <= 5; $i++) { $group_id = \ingot\testing\crud\group::create($args); $args['wp_ID'] = $args['wp_ID'] + 1; if (3 == $i) { $expected_id = $group_id; $variant_args['group_ID'] = $group_id; $variant_args['meta']['price'] = rand_float(); $variant_id = \ingot\testing\crud\variant::create($variant_args, true); $this->assertTrue(is_numeric($variant_id)); $group = \ingot\testing\crud\group::read($group_id); $group['variants'] = [$variant_id]; \ingot\testing\crud\group::update($group, $group_id, true); } } $groups = \ingot\testing\crud\price_query::find_by_plugin('edd', true); $this->assertInternalType('array', $groups); $this->assertFalse(empty($groups)); $ids = wp_list_pluck($groups, 'ID'); $this->assertTrue(in_array($expected_id, $ids)); $this->assertSame(1, count($groups)); }