FileTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\View\Widget;
  16. use Cake\TestSuite\TestCase;
  17. use Cake\View\StringTemplate;
  18. use Cake\View\Widget\File;
  19. /**
  20. * File input test.
  21. */
  22. class FileTest extends TestCase {
  23. /**
  24. * setup
  25. *
  26. * @return void
  27. */
  28. public function setUp() {
  29. parent::setUp();
  30. $templates = [
  31. 'file' => '<input type="file" name="{{name}}"{{attrs}}>',
  32. ];
  33. $this->templates = new StringTemplate($templates);
  34. }
  35. /**
  36. * Test render in a simple case.
  37. *
  38. * @return void
  39. */
  40. public function testRenderSimple() {
  41. $input = new File($this->templates);
  42. $result = $input->render(['name' => 'image']);
  43. $expected = [
  44. 'input' => ['type' => 'file', 'name' => 'image'],
  45. ];
  46. $this->assertTags($result, $expected);
  47. }
  48. /**
  49. * Test render with a value
  50. *
  51. * @return void
  52. */
  53. public function testRenderAttributes() {
  54. $input = new File($this->templates);
  55. $data = ['name' => 'image', 'required' => true, 'val' => 'nope'];
  56. $result = $input->render($data);
  57. $expected = [
  58. 'input' => ['type' => 'file', 'required' => 'required', 'name' => 'image'],
  59. ];
  60. $this->assertTags($result, $expected);
  61. }
  62. }