Example #1
0
             unset($config['lock']);
             foreach ($writer->get_locks() as $lock => $lockconfig) {
                 if ($lock == $data->lock) {
                     $config['lock'] = $data->lock;
                 }
             }
             $writer->add_store_instance($data->name, $data->plugin, $config);
             redirect($PAGE->url, get_string('addstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
         }
     }
     break;
 case 'editstore':
     // Edit the requested store.
     $plugin = required_param('plugin', PARAM_PLUGIN);
     $store = required_param('store', PARAM_TEXT);
     $mform = cache_administration_helper::get_edit_store_form($plugin, $store);
     $title = get_string('addstore', 'cache', $plugins[$plugin]['name']);
     if ($mform->is_cancelled()) {
         redirect($PAGE->url);
     } else {
         if ($data = $mform->get_data()) {
             $config = cache_administration_helper::get_store_configuration_from_data($data);
             $writer = cache_config_writer::instance();
             unset($config['lock']);
             foreach ($writer->get_locks() as $lock => $lockconfig) {
                 if ($lock == $data->lock) {
                     $config['lock'] = $data->lock;
                 }
             }
             $writer->edit_store_instance($data->name, $data->plugin, $config);
             redirect($PAGE->url, get_string('editstoresuccess', 'cache', $plugins[$plugin]['name']), 5);
Example #2
0
 /**
  * Test instantiating a form to edit a store instance.
  */
 public function test_get_edit_store_form()
 {
     $config = cache_config_writer::instance();
     $this->assertTrue($config->add_store_instance('summariesstore', 'file'));
     $form = cache_administration_helper::get_edit_store_form('file', 'summariesstore');
     $this->assertInstanceOf('moodleform', $form);
     try {
         $form = cache_administration_helper::get_edit_store_form('somethingstupid', 'moron');
         $this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
     } catch (moodle_exception $e) {
         $this->assertInstanceOf('coding_exception', $e);
     }
     try {
         $form = cache_administration_helper::get_edit_store_form('file', 'blisters');
         $this->fail('You should not be able to create an edit form for a store plugin that does not exist.');
     } catch (moodle_exception $e) {
         $this->assertInstanceOf('coding_exception', $e);
     }
 }