/** * Update the page with a new set of data * * @param array $data */ public function update($input = array(), $lang = null) { $data = a::update($this->content($lang)->toArray(), $input); if (!data::write($this->textfile(null, $lang), $data, 'kd')) { throw new Exception('The page could not be updated'); } cache::flush(); $this->reset(); $this->touch(); return true; }
public function testUpdate() { // original data $source = ['a' => 'value a', 'b' => 'value b']; // test with simple array $result = a::update($source, ['a' => 'updated value a', 'c' => 'new value c']); $this->assertEquals('updated value a', $result['a']); $this->assertEquals('value b', $result['b']); $this->assertEquals('new value c', $result['c']); // test with callbacks $result = a::update($source, ['a' => function ($value) { return 'updated ' . $value; }, 'c' => function ($value) { return 'new value c'; }]); $this->assertEquals('updated value a', $result['a']); $this->assertEquals('value b', $result['b']); $this->assertEquals('new value c', $result['c']); }