function test_update_if_set_to_default_but_nondefault_in_db() { $s = new AbstractSettings('testtable', array('key1', 'key2', 'key3'), 'val'); $s->_defaults = array('3' => 'defaultval'); // Mock the return value of get_results, to simulate saved settings. $r = array(array('key1' => 1, 'key2' => 2, 'key3' => 3, 'val' => 'dbval')); $this->MockDB->returns('get_results', $r); $this->MockDB->returns('query', 1); $s->load_all(); $this->assertEqual($s->get(1, 2, 3), 'dbval'); $this->assertEqual($s->get_default(3), 'defaultval'); // Setting it to default value (with another value in DB) should update: $this->assertTrue($s->set(1, 2, 3, 'defaultval')); $this->assertTrue($s->dbupdate()); $this->assertTrue($s->delete(1, 2, 3)); $this->assertEqual($s->get(1, 2, 3), 'defaultval'); // If db value is the default value (set explicitly), do not remove (or update) it: $this->assertFalse($s->dbupdate()); // Reload mocked db values. $s->reset(); // Deleting a value should cause an update. $this->assertEqual($s->get(1, 2, 3), 'dbval'); $this->assertTrue($s->delete(1, 2, 3)); $this->assertEqual($s->get(1, 2, 3), 'defaultval'); $this->assertTrue($s->dbupdate()); }