RulesProviderTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Validation;
  16. use Cake\TestSuite\TestCase;
  17. use Cake\Validation\RulesProvider;
  18. /**
  19. * Tests RulesProvider class
  20. *
  21. */
  22. class RulesProviderTest extends TestCase
  23. {
  24. /**
  25. * Tests that RulesProvider proxies the method correctly and removes the
  26. * extra arguments that are passed according to the signature of validation
  27. * methods.
  28. *
  29. * @return void
  30. */
  31. public function testProxyToValidation()
  32. {
  33. $provider = new RulesProvider;
  34. $this->assertTrue($provider->extension('foo.jpg', compact('provider')));
  35. $this->assertFalse($provider->extension('foo.jpg', ['png'], compact('provider')));
  36. }
  37. /**
  38. * Tests that it is possible to use a custom object as the provider to
  39. * be decorated
  40. *
  41. * @return void
  42. */
  43. public function testCustomObject()
  44. {
  45. $mock = $this->getMock('\Cake\Validation\Validator', ['field']);
  46. $mock->expects($this->once())
  47. ->method('Field')
  48. ->with('first', null)
  49. ->will($this->returnValue(true));
  50. $provider = new RulesProvider($mock);
  51. $provider->field('first', compact('provider'));
  52. }
  53. }