Ejemplo n.º 1
0
 public function testUpdate()
 {
     wp_set_current_user(1);
     $expected = array('click_tracking' => 0, 'anon_tracking' => 0, 'license_code' => 'batman');
     foreach ($expected as $setting => $value) {
         \ingot\testing\crud\settings::write($setting, $value);
     }
     $request = new \WP_REST_Request('POST', $this->namespaced_route);
     $request->set_query_params(array('click_tracking' => 'true', 'anon_tracking' => 'true', 'license_code' => 'allthespidermen'));
     $response = $this->server->dispatch($request);
     $response = rest_ensure_response($response);
     $this->assertEquals(200, $response->get_status());
     $data = (array) $response->get_data();
     foreach ($expected as $setting => $value) {
         $this->assertArrayHasKey($setting, $data);
         if ('license_code' != $setting) {
             $data[$setting] = intval($data[$setting]);
             $this->assertEquals($value, $data[$setting], $setting);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Sanatize Ingot settings
  *
  * @since 0.0.8
  *
  * @uses "pre_update_option"
  */
 public function presave_settings($value, $option)
 {
     $keys = settings::get_key_names();
     if (in_array($option, $keys)) {
         $value = settings::sanatize_setting($option, $value);
     }
     return $value;
 }
Ejemplo n.º 3
0
 /**
  * Test that we can not get an invalid setting, even if its prefixed with ingot_settings
  *
  * @since 0.2.0
  *
  * @group crud
  * @group settings_crud
  *
  * @covers \ingot\testing\crud\settings::write()
  */
 public function testReadInvalidSetting()
 {
     update_option('ingot_settings_cat', 'dog');
     $read = \ingot\testing\crud\settings::read('cat');
     $this->assertFalse($read);
 }
Ejemplo n.º 4
0
 /**
  * Create a response
  *
  * @since 0.2.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  * @param array $settings Optional. Current settings. If not used current settings will be queried
  *
  * @return \WP_Error|\WP_REST_Response
  */
 protected function response($request, $settings = array())
 {
     if (empty($settings)) {
         foreach (array_keys($this->args()) as $setting) {
             $settings[$setting] = \ingot\testing\crud\settings::read($setting);
         }
     }
     if ('admin' == $request->get_param('context')) {
         $valid = false;
         if (ingot_sl_check_license(false)) {
             $valid = true;
         }
         $settings['license_valid'] = (int) $valid;
     }
     return rest_ensure_response($settings);
 }
Ejemplo n.º 5
0
 /**
  * Get HTML for settings form
  *
  * @since 0.0.9
  *
  * @return string
  */
 protected function get_settings_form()
 {
     $settings_class = new \ingot\ui\admin\settings(settings::get_settings_keys());
     $settings_form = $settings_class->get_form();
     return $settings_form;
 }