/**
  * Set some test data
  */
 public function test_set_AND_get_data()
 {
     $dataobject = array('object' => array('test' => 'Value!'));
     $type = 'phpunit_test_values';
     $start_date = strtotime('-7 days');
     $end_date = time();
     $store_as = 'table';
     // Set the data object
     $set = Yoast_GA_Dashboards_Data::set($type, $dataobject, $start_date, $end_date, $store_as);
     $this->assertTrue($set);
     // Get the data object
     $result = Yoast_GA_Dashboards_Data::get($type);
     $expected = array('store_as' => $store_as, 'type' => $type, 'start_date' => $start_date, 'end_date' => $end_date, 'value' => $dataobject);
     $this->assertEquals($result, $expected);
 }
 /**
  * Handle the response from the Google Analytics api.
  *
  * @param array|boolean $response
  * @param string        $metric
  * @param array         $dimensions
  * @param string        $start_date
  * @param string        $end_date
  * @param string        $store_as
  * @param string        $storage_name
  *
  * @return bool
  */
 private function handle_response($response, $metric, $dimensions, $start_date, $end_date, $store_as = 'table', $storage_name = 'auto')
 {
     if (is_array($response)) {
         // Success, store this data
         $filter_metrics = $this->get_filter_metrics();
         $extracted = str_replace('ga:', '', str_replace('ga:date,', '', $dimensions));
         if (isset($filter_metrics[$extracted])) {
             $name = $extracted;
         } else {
             $name = $metric;
         }
         if ($dimensions !== 'ga:date' && !isset($filter_metrics[$extracted])) {
             $name = str_replace('ga:date,', '', $dimensions);
         }
         // Overwrite the name if we have a defined one
         if ($storage_name != 'auto') {
             $name = $storage_name;
         }
         return Yoast_GA_Dashboards_Data::set($name, $response, strtotime($start_date), strtotime($end_date), $store_as);
     } else {
         // Failure on API call try to log it
         $this->log_error(print_r($response, true));
         return false;
     }
 }