RulesProviderTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. * 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. $provider = new RulesProvider;
  32. $this->assertTrue($provider->extension('foo.jpg', compact('provider')));
  33. $this->assertFalse($provider->extension('foo.jpg', ['png'], compact('provider')));
  34. }
  35. /**
  36. * Tests that it is possible to use a custom object as the provider to
  37. * be decorated
  38. *
  39. * @return void
  40. */
  41. public function testCustomObject() {
  42. $mock = $this->getMock('\Cake\Validation\Validator', ['field']);
  43. $mock->expects($this->once())
  44. ->method('Field')
  45. ->with('first', null)
  46. ->will($this->returnValue(true));
  47. $provider = new RulesProvider($mock);
  48. $provider->field('first', compact('provider'));
  49. }
  50. }