| @@ 12-28 (lines=17) @@ | ||
| 9 | ||
| 10 | class FieldHelperTest extends TestCase |
|
| 11 | { |
|
| 12 | public function testFieldHelperReturnsPrimaryFieldOfNameWhenNoDefaultSpecified() |
|
| 13 | { |
|
| 14 | $options = [ |
|
| 15 | 'namespace' => 'Test\\Models', |
|
| 16 | 'model' => 'post' |
|
| 17 | ]; |
|
| 18 | $crudApi = new CrudApi($options); |
|
| 19 | $fieldHelper = $crudApi->fieldHelper; |
|
| 20 | ||
| 21 | $item = new Post(); |
|
| 22 | ||
| 23 | $config = require __DIR__ . '/../../config/crudapi.php'; |
|
| 24 | ||
| 25 | $primary_field = $fieldHelper->getPrimaryField($item, $config); |
|
| 26 | ||
| 27 | $this->assertEquals('name', $primary_field); |
|
| 28 | } |
|
| 29 | ||
| 30 | public function testFieldHelperReturnsOverriddenModelDefaultField() |
|
| 31 | { |
|
| @@ 72-87 (lines=16) @@ | ||
| 69 | $this->assertEquals('Test\\AnotherNamespace\\AdditionalModel', get_class($model)); |
|
| 70 | } |
|
| 71 | ||
| 72 | public function testInstanceMethodReturnsTheSpecifiedInstance() |
|
| 73 | { |
|
| 74 | $namespace = 'Test\\Models\\'; |
|
| 75 | ||
| 76 | $options = [ |
|
| 77 | 'namespace' => $namespace, |
|
| 78 | 'model' => 'AdditionalModel', |
|
| 79 | ]; |
|
| 80 | ||
| 81 | $crudApi = new CrudApi($options); |
|
| 82 | $modelHelper = new ModelHelper($crudApi); |
|
| 83 | $testInstance = 'testing'; |
|
| 84 | $crudApi->setInstance($testInstance); |
|
| 85 | $instance = $modelHelper->instance(); |
|
| 86 | $this->assertEquals($testInstance, $instance, 'Given an instance, modelHelper instance() should return that instance.'); |
|
| 87 | } |
|
| 88 | ||
| 89 | public function testInstanceMethodReturnsAnInstanceOfAModel() |
|
| 90 | { |
|