示例#1
0
 /**
  * Update all settings
  *
  * @since 0.2.0
  *
  * @param \WP_REST_Request $request Full data about the request.
  *
  * @return \WP_Error|\WP_REST_Response
  */
 public function update($request)
 {
     $params = $request->get_params();
     foreach (array_keys($this->args()) as $setting) {
         if (isset($params[$setting])) {
             $saved = \ingot\testing\crud\settings::write($setting, $params[$setting]);
             if (is_wp_error($saved)) {
                 return rest_ensure_response($saved, 500);
             }
             $settings[$setting] = $params[$setting];
         } else {
             $settings[$setting] = \ingot\testing\crud\settings::read($setting);
         }
     }
     return $this->response($request, $settings);
 }
示例#2
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);
         }
     }
 }
示例#3
0
 /**
  * Test that we can not save an invalid setting
  *
  * @since 0.2.0
  *
  * @group crud
  * @group settings_crud
  *
  * @covers \ingot\testing\crud\settings::write()
  */
 public function testSaveInvalidSetting()
 {
     $saved = \ingot\testing\crud\settings::write('batman', 'batcave');
     $this->assertFalse($saved);
     $this->assertFalse(get_option('ingot_settings_batman', false));
 }