public function testFormatSelectOptions() { $field = m::mock('Frozennode\\Administrator\\Fields\\Field'); $field->shouldReceive('getOption')->twice()->andReturn('name_field'); $firstResult = m::mock('stdClass'); $firstResult->shouldReceive('getKey')->once()->andReturn(1)->set('name_field', 'first'); $secondResult = m::mock('stdClass'); $secondResult->shouldReceive('getKey')->once()->andReturn(2)->set('name_field', 'second'); $results = new \Illuminate\Database\Eloquent\Collection(array($firstResult, $secondResult)); $output = array(array('id' => 1, 'text' => 'first'), array('id' => 2, 'text' => 'second')); $this->assertEquals($this->factory->formatSelectOptions($field, $results), $output); }
public function testFormatSelectOptions() { $model = m::mock(array('getKeyName' => 'id')); $field = m::mock('Frozennode\Administrator\Fields\Field'); $field->shouldReceive('getOption')->twice()->andReturn('name_field'); $firstResult = new \stdClass(); $firstResult->id = 1; $firstResult->name_field = 'first'; $secondResult = new \stdClass(); $secondResult->id = 2; $secondResult->name_field = 'second'; $results = array($firstResult, $secondResult); $this->config->shouldReceive('getDataModel')->andReturn($model); $output = array(array('id' => 1, 'text' => 'first'), array('id' => 2, 'text' => 'second')); $this->assertEquals($this->factory->formatSelectOptions($model, $field, $results), $output); }