RulesProviderTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 3.0.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Validation;
  17. use Cake\TestSuite\TestCase;
  18. use Cake\Validation\RulesProvider;
  19. use TestApp\Validation\CustomProvider;
  20. /**
  21. * Tests RulesProvider class
  22. */
  23. class RulesProviderTest extends TestCase
  24. {
  25. /**
  26. * Tests that RulesProvider proxies the method correctly and removes the
  27. * extra arguments that are passed according to the signature of validation
  28. * methods.
  29. */
  30. public function testProxyToValidation(): void
  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. public function testCustomObject(): void
  41. {
  42. $object = new CustomProvider();
  43. /** @var \TestApp\Validation\CustomProvider|\Cake\Validation\RulesProvider $provider */
  44. $provider = new RulesProvider($object);
  45. $this->assertFalse($provider->validate('string', 'context'));
  46. }
  47. }