RulesProviderTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://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. class RulesProviderTest extends TestCase
  22. {
  23. /**
  24. * Tests that RulesProvider proxies the method correctly and removes the
  25. * extra arguments that are passed according to the signature of validation
  26. * methods.
  27. *
  28. * @return void
  29. */
  30. public function testProxyToValidation()
  31. {
  32. $provider = new RulesProvider;
  33. $this->assertTrue($provider->extension('foo.jpg', compact('provider')));
  34. $this->assertFalse($provider->extension('foo.jpg', ['png'], compact('provider')));
  35. }
  36. /**
  37. * Tests that it is possible to use a custom object as the provider to
  38. * be decorated
  39. *
  40. * @return void
  41. */
  42. public function testCustomObject()
  43. {
  44. $mock = $this->getMockBuilder('\Cake\Validation\Validator')
  45. ->setMethods(['field'])
  46. ->getMock();
  47. $mock->expects($this->once())
  48. ->method('field')
  49. ->with('first', null)
  50. ->will($this->returnValue(true));
  51. $provider = new RulesProvider($mock);
  52. $provider->field('first', compact('provider'));
  53. }
  54. }