|
@@ 32-55 (lines=24) @@
|
| 29 |
|
* Tests JSONText::setValue() by means of a simple JSONPath expression operating on a nested JSON array |
| 30 |
|
* on a saved DataObject record. |
| 31 |
|
*/ |
| 32 |
|
public function testSetValueOnNestedArray() |
| 33 |
|
{ |
| 34 |
|
$model = $this->objFromFixture('MyAwesomeJSONModel', 'json-as-object'); |
| 35 |
|
$expression = '$.cars.american.[0]'; |
| 36 |
|
$field = $model->dbObject('MyJSON'); |
| 37 |
|
|
| 38 |
|
// What's the value at $expression now? (JSON as return type is the default) |
| 39 |
|
$this->assertEquals('["buick"]', $field->query($expression)); |
| 40 |
|
|
| 41 |
|
// How about now? |
| 42 |
|
$field->setValue('ford', null, $expression); |
| 43 |
|
$model->setField('MyJSON', $field->getValue()); |
| 44 |
|
$model->write(); |
| 45 |
|
$this->assertEquals('["ford"]', $field->query($expression)); |
| 46 |
|
|
| 47 |
|
// And now? (With chaining) |
| 48 |
|
$field |
| 49 |
|
->setValue('chrysler', null, $expression) |
| 50 |
|
->setReturnType('array'); |
| 51 |
|
|
| 52 |
|
$model->setField('MyJSON', $field->getValue()); |
| 53 |
|
$model->write(); |
| 54 |
|
$this->assertEquals(['chrysler'], $field->query($expression)); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
/** |
| 58 |
|
* Tests JSONText::setValue() by means of a simple JSONPath expression operating on a simple, un-nested JSON array |
|
@@ 61-84 (lines=24) @@
|
| 58 |
|
* Tests JSONText::setValue() by means of a simple JSONPath expression operating on a simple, un-nested JSON array |
| 59 |
|
* on a saved DataObject record. |
| 60 |
|
*/ |
| 61 |
|
public function testSetValueOnUnNestedArray() |
| 62 |
|
{ |
| 63 |
|
$model = $this->objFromFixture('MyAwesomeJSONModel', 'json-as-array'); |
| 64 |
|
$expression = '$.[0]'; |
| 65 |
|
$field = $model->dbObject('MyJSON'); |
| 66 |
|
|
| 67 |
|
// What's the value at $expression now? (JSON as return type is the default) |
| 68 |
|
$this->assertEquals('["buick"]', $field->query($expression)); |
| 69 |
|
|
| 70 |
|
// How about now? |
| 71 |
|
$field->setValue('ford', null, $expression); |
| 72 |
|
$model->setField('MyJSON', $field->getValue()); |
| 73 |
|
$model->write(); |
| 74 |
|
$this->assertEquals('["ford"]', $field->query($expression)); |
| 75 |
|
|
| 76 |
|
// And now? (With chaining) |
| 77 |
|
$field |
| 78 |
|
->setValue('chrysler', null, $expression) |
| 79 |
|
->setReturnType('array'); |
| 80 |
|
|
| 81 |
|
$model->setField('MyJSON', $field->getValue()); |
| 82 |
|
$model->write(); |
| 83 |
|
$this->assertEquals(['chrysler'], $field->query($expression)); |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
} |
| 87 |
|
|