/**
 * Get HTML for our test. Use this function to output the test.
 *
 * Note that because this function has the same name as the test sub_type we registered, it can be called by the Ingot shortcode.
 *
 * @return string
 */
function my_custom_banner()
{
    //check if is bot
    $is_bot = ingot_is_bot();
    $variant = [];
    //if cookie isset get variant without registering as a new test instance
    if (!$is_bot && isset($_COOKIE['my_ingot_custom_test_variant']) && 0 < absint($_COOKIE['my_ingot_custom_test_variant'])) {
        $variant_id = absint($_COOKIE['my_ingot_custom_test_variant']);
        $variant = \ingot\testing\crud\variant::read($variant_id);
    } elseif (!$is_bot && isset($my_custom_test_variant_id) && 0 < absint($my_custom_test_variant_id)) {
        //if is same session as cookie was set, we use the global variable to get the ID
        $variant_id = absint($my_custom_test_variant_id);
        $variant = \ingot\testing\crud\variant::read($variant_id);
    } else {
        //this should never be reached unless this is a bot, the cookie should have been set at template_redirect
        //We still need to show something since we want crawlers to index the site properly and false postives on bot checks to look right.
        $id = my_ingot_custom_test_group();
        if (is_numeric($id)) {
            $group = \ingot\testing\crud\group::read($id);
            if (is_array($group) && isset($group['variants']) && !empty($group['variants'])) {
                $variant = array_rand($group['variants']);
                //set up test and select a variant
                $test = new \ingot\testing\bandit\content($id);
                $variant_id = $test->choose();
                //a test instance is now registered
                $variant = \ingot\testing\crud\variant::read($variant_id);
            }
        }
    }
    //get chosen image URL and return it in an image tag
    if (isset($variant['content'])) {
        $content = $variant['content'];
    } else {
        //something is very wrong, let's show a picture of a cat in a flower pot
        $content = 'http://hellogiggles.com/wp-content/uploads/2014/07/22/you-popular-cute-cat-the-very-creative_113506.jpg';
    }
    return sprintf('<img src="%s" />', esc_url($content));
}
 /**
  *
  *
  * @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());
 }