StringLengthTest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Validator\Test\Unit;
  7. /**
  8. * Test case for \Magento\Framework\Validator\StringLength
  9. */
  10. class StringLengthTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Framework\Validator\StringLength
  14. */
  15. protected $_validator;
  16. protected function setUp()
  17. {
  18. $this->_validator = new \Magento\Framework\Validator\StringLength();
  19. }
  20. public function testDefaultEncoding()
  21. {
  22. $this->assertEquals('UTF-8', $this->_validator->getEncoding());
  23. }
  24. /**
  25. * @dataProvider isValidDataProvider
  26. * @param string $value
  27. * @param int $maxLength
  28. * @param bool $isValid
  29. */
  30. public function testIsValid($value, $maxLength, $isValid)
  31. {
  32. $this->_validator->setMax($maxLength);
  33. $this->assertEquals($isValid, $this->_validator->isValid($value));
  34. }
  35. /**
  36. * @return array
  37. */
  38. public function isValidDataProvider()
  39. {
  40. return [
  41. ['строка', 6, true],
  42. ['строка', 5, false],
  43. ['string', 6, true],
  44. ['string', 5, false]
  45. ];
  46. }
  47. }