ViewVarsTraitTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Cake\Test\TestCase\View;
  15. use Cake\TestSuite\TestCase;
  16. use Cake\View\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. parent::setUp();
  29. $this->subject = $this->getObjectForTrait('Cake\View\ViewVarsTrait');
  30. }
  31. /**
  32. * Test set() with one param.
  33. *
  34. * @return void
  35. */
  36. public function testSetOneParam() {
  37. $data = ['test' => 'val', 'foo' => 'bar'];
  38. $this->subject->set($data);
  39. $this->assertEquals($data, $this->subject->viewVars);
  40. $update = ['test' => 'updated'];
  41. $this->subject->set($update);
  42. $this->assertEquals('updated', $this->subject->viewVars['test']);
  43. }
  44. /**
  45. * test set() with 2 params
  46. *
  47. * @return void
  48. */
  49. public function testSetTwoParam() {
  50. $this->subject->set('testing', 'value');
  51. $this->assertEquals(['testing' => 'value'], $this->subject->viewVars);
  52. }
  53. /**
  54. * test set() with 2 params in combine mode
  55. *
  56. * @return void
  57. */
  58. public function testSetTwoParamCombind() {
  59. $keys = ['one', 'key'];
  60. $vals = ['two', 'val'];
  61. $this->subject->set($keys, $vals);
  62. $expected = ['one' => 'two', 'key' => 'val'];
  63. $this->assertEquals($expected, $this->subject->viewVars);
  64. }
  65. }