/** * @dataProvider providerStoreArray */ public function testStoreArray($input, $output) { midcom::get('auth')->request_sudo('midcom.core'); $privilege = new midcom_core_privilege($input); $stat = $privilege->store(); $this->assertEquals($output['stat'], $stat, midcom_connection::get_error_string()); foreach ($output as $field => $value) { if ($field == 'stat') { continue; } $this->assertEquals($value, $privilege->{$field}, 'Difference in field ' . $field); } $stat = $privilege->drop(); $this->assertTrue($stat); midcom::get('auth')->drop_sudo(); }
/** * Drop the privilege. If we are a known DB record, we delete us, otherwise * we return silently. * * @return boolean Indicating success. */ public function drop() { $this->_sync_to_db_object(); if (!$this->__guid) { debug_add('We are not stored, GUID is empty. Ignoring silently.'); return true; } if (!$this->validate()) { debug_add('This privilege failed to validate, rejecting to drop it, see the debug log for details.', MIDCOM_LOG_WARN); debug_print_r('Privilege dump:', $this); return false; } if (!$this->__privilege_object->guid) { // We created this via collector, instantiate a new one $privilege = new midcom_core_privilege($this->__guid); return $privilege->drop(); } try { if (!$this->__privilege_object->delete()) { debug_add('Failed to delete privilege record, aborting. Error: ' . midcom_connection::get_error_string(), MIDCOM_LOG_ERROR); return false; } } catch (Exception $e) { debug_add('Failed to delete privilege record, aborting. Error: ' . $e->getMessage(), MIDCOM_LOG_ERROR); return false; } debug_add("Delete privilege record {$this->__guid} ({$this->__privilege_object->objectguid} {$this->__privilege_object->privilegename} {$this->__privilege_object->assignee} {$this->__privilege_object->value}"); $this->__privilege_object->purge(); $this->_invalidate_cache(); $this->value = MIDCOM_PRIVILEGE_INHERIT; return true; }