Ejemplo n.º 1
0
 /**
  * Loads ingot if not already loaded.
  *
  * @since 0.0.5
  */
 public static function maybe_load()
 {
     if (did_action('ingot_loaded')) {
         return;
     }
     if (!defined('INGOT_DEV_MODE')) {
         /**
          * Puts Ingot into dev mode
          *
          * Don't use on a live site -- makes API totally open
          *
          * @since 0.0.5
          */
         define('INGOT_DEV_MODE', false);
     }
     $load = true;
     if (!version_compare(PHP_VERSION, '5.5.0', '>=')) {
         $load = false;
     }
     $autoloader = dirname(__FILE__) . '/vendor/autoload.php';
     if (!file_exists($autoloader)) {
         $load = false;
     }
     if ($load) {
         include_once $autoloader;
         self::maybe_add_tables();
         self::maybe_upgrade();
         self::maybe_load_trial();
         if (\ingot\testing\db\delta::check_if_tables_exist()) {
             ingot\testing\ingot::instance();
             //make admin go in admin
             if (is_admin()) {
                 new ingot\ui\make();
             }
             if (ingot_is_front_end() || ingot_is_admin_ajax()) {
                 //setup destination tests
                 $destination_tests = \ingot\testing\tests\click\destination\init::set_tracking();
                 //run cookies
                 add_action('ingot_loaded', function () {
                     /**
                      * Disable running cookies
                      *
                      * @since 1.1.0
                      *
                      * @param bool $run
                      */
                     if (true == (bool) apply_filters('ingot_run_cookies', true) && !did_action('ingot_cookies_set')) {
                         if (!empty($destination_tests)) {
                             \ingot\testing\tests\click\destination\init::setup_cookies($destination_tests);
                         }
                         \ingot\testing\cookies\set::run();
                     }
                 });
             }
             /**
              * Runs when Ingot has loaded.
              *
              * @since 0.0.5
              */
             do_action('ingot_loaded');
         } else {
             if (is_admin()) {
                 printf('<div class="error"><p>%s</p></div>', __('Ingot Not Loaded', 'ingot'));
             }
             /**
              * Runs if Ingot failed to load
              *
              * @since 0.3.0
              *
              */
             do_action('ingot_loaded_failed');
             return;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Set tracking property of this class
  *
  * @access private
  *
  * @since 1.1.0
  *
  * @param array $tracking Group IDs to track
  */
 private function set_tracking(array $tracking)
 {
     if (!empty($tracking)) {
         foreach ($tracking as $group_id) {
             $variant_id = init::get_test($group_id);
             if (is_numeric($variant_id)) {
                 $this->tracking[(int) $group_id] = $variant_id;
             }
         }
     }
 }
 /**
  *
  *
  * @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());
 }
 /**
  * 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']);
     }
 }