@@ -361,4 +361,56 @@ public function testCloneWithArray()
361
361
$ this ->assertEquals ('foo ' , $ model1 ->getVariable ('a ' ));
362
362
$ this ->assertEquals ('bar ' , $ model2 ->getVariable ('a ' ));
363
363
}
364
+
365
+ public function variableValue ()
366
+ {
367
+ return [
368
+ // variables default expected
369
+
370
+ // if it is set always get the value
371
+ [['foo ' => 'bar ' ], 'baz ' , 'bar ' ],
372
+ [['foo ' => 'bar ' ], null , 'bar ' ],
373
+ [new ArrayObject (['foo ' => 'bar ' ]), 'baz ' , 'bar ' ],
374
+ [new ArrayObject (['foo ' => 'bar ' ]), null , 'bar ' ],
375
+
376
+ // if it is null always get null value
377
+ [['foo ' => null ], null , null ],
378
+ [['foo ' => null ], 'baz ' , null ],
379
+ [new ArrayObject (['foo ' => null ]), null , null ],
380
+ [new ArrayObject (['foo ' => null ]), 'baz ' , null ],
381
+
382
+ // when it is not set always get default value
383
+ [[], 'baz ' , 'baz ' ],
384
+ [new ArrayObject (), 'baz ' , 'baz ' ],
385
+ ];
386
+ }
387
+
388
+ /**
389
+ * @dataProvider variableValue
390
+ *
391
+ * @param array|ArrayObject $variables
392
+ * @param string|null $default
393
+ * @param string|null $expected
394
+ */
395
+ public function testGetVariableSetByConstruct ($ variables , $ default , $ expected )
396
+ {
397
+ $ model = new ViewModel ($ variables );
398
+
399
+ self ::assertSame ($ expected , $ model ->getVariable ('foo ' , $ default ));
400
+ }
401
+
402
+ /**
403
+ * @dataProvider variableValue
404
+ *
405
+ * @param array|ArrayObject $variables
406
+ * @param string|null $default
407
+ * @param string|null $expected
408
+ */
409
+ public function testGetVariableSetBySetter ($ variables , $ default , $ expected )
410
+ {
411
+ $ model = new ViewModel ();
412
+ $ model ->setVariables ($ variables );
413
+
414
+ self ::assertSame ($ expected , $ model ->getVariable ('foo ' , $ default ));
415
+ }
364
416
}
0 commit comments