ArrayContextTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since CakePHP(tm) v 3.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\View\Form;
  16. use Cake\Network\Request;
  17. use Cake\TestSuite\TestCase;
  18. use Cake\View\Form\ArrayContext;
  19. /**
  20. * Array context test case.
  21. */
  22. class ArrayContextTest extends TestCase {
  23. /**
  24. * setup method.
  25. *
  26. * @return void
  27. */
  28. public function setUp() {
  29. parent::setUp();
  30. $this->request = new Request();
  31. }
  32. /**
  33. * Test reading values from the request & defaults.
  34. */
  35. public function testValPresent() {
  36. $this->request->data = [
  37. 'Articles' => [
  38. 'title' => 'New title',
  39. 'body' => 'My copy',
  40. ]
  41. ];
  42. $context = new ArrayContext($this->request, [
  43. 'defaults' => [
  44. 'Articles' => [
  45. 'title' => 'Default value',
  46. 'published' => 0
  47. ]
  48. ]
  49. ]);
  50. $this->assertEquals('New title', $context->val('Articles.title'));
  51. $this->assertEquals('My copy', $context->val('Articles.body'));
  52. $this->assertEquals(0, $context->val('Articles.published'));
  53. $this->assertNull($context->val('Articles.nope'));
  54. }
  55. /**
  56. * Test getting values when the request and defaults are missing.
  57. *
  58. * @return void
  59. */
  60. public function testValMissing() {
  61. $context = new ArrayContext($this->request, []);
  62. $this->assertNull($context->val('Comments.field'));
  63. }
  64. public function testIsRequired() {
  65. $this->markTestIncomplete();
  66. }
  67. public function testIsRequiredUndefined() {
  68. $this->markTestIncomplete();
  69. }
  70. public function testIsType() {
  71. $this->markTestIncomplete();
  72. }
  73. public function testIsTypeUndefined() {
  74. $this->markTestIncomplete();
  75. }
  76. public function testAttributes() {
  77. $this->markTestIncomplete();
  78. }
  79. }