ViewVarsTraitTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @since 3.0.0
  12. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  13. */
  14. namespace Cake\Test\TestCase\Utility;
  15. use Cake\TestSuite\TestCase;
  16. use Cake\Utility\ViewVarsTrait;
  17. /**
  18. * ViewVarsTrait test case
  19. *
  20. */
  21. class ViewVarsTraitTest extends TestCase {
  22. /**
  23. * setup
  24. *
  25. * @return void
  26. */
  27. public function setUp() {
  28. $this->subject = $this->getObjectForTrait('Cake\Utility\ViewVarsTrait');
  29. }
  30. /**
  31. * Test set() with one param.
  32. *
  33. * @return void
  34. */
  35. public function testSetOneParam() {
  36. $data = ['test' => 'val', 'foo' => 'bar'];
  37. $this->subject->set($data);
  38. $this->assertEquals($data, $this->subject->viewVars);
  39. $update = ['test' => 'updated'];
  40. $this->subject->set($update);
  41. $this->assertEquals('updated', $this->subject->viewVars['test']);
  42. }
  43. /**
  44. * test set() with 2 params
  45. *
  46. * @return void
  47. */
  48. public function testSetTwoParam() {
  49. $this->subject->set('testing', 'value');
  50. $this->assertEquals(['testing' => 'value'], $this->subject->viewVars);
  51. }
  52. /**
  53. * test set() with 2 params in combine mode
  54. *
  55. * @return void
  56. */
  57. public function testSetTwoParamCombind() {
  58. $keys = ['one', 'key'];
  59. $vals = ['two', 'val'];
  60. $this->subject->set($keys, $vals);
  61. $expected = ['one' => 'two', 'key' => 'val'];
  62. $this->assertEquals($expected, $this->subject->viewVars);
  63. }
  64. }