AlphanumTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Test\Unit\Model\Entity\Increment;
  7. use Magento\Eav\Model\Entity\Increment\Alphanum;
  8. class AlphanumTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var Alphanum
  12. */
  13. private $model;
  14. protected function setUp()
  15. {
  16. $this->model = new \Magento\Eav\Model\Entity\Increment\Alphanum();
  17. }
  18. public function testGetAllowedChars()
  19. {
  20. $this->assertEquals('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', $this->model->getAllowedChars());
  21. }
  22. /**
  23. * @param int $lastId
  24. * @param string $prefix
  25. * @param int|string $expectedResult
  26. * @dataProvider getLastIdDataProvider
  27. */
  28. public function testGetNextId($lastId, $prefix, $expectedResult)
  29. {
  30. $this->model->setPrefix($prefix);
  31. $this->model->setLastId($lastId);
  32. $this->assertEquals($expectedResult, $this->model->getNextId());
  33. }
  34. /**
  35. * @return array
  36. */
  37. public function getLastIdDataProvider()
  38. {
  39. return [
  40. [
  41. 'lastId' => 'prefix00000001CZ',
  42. 'prefix' => 'prefix',
  43. 'expectedResult' => 'prefix00000001D0',
  44. ],
  45. [
  46. 'lastId' => 1,
  47. 'prefix' => 'prefix',
  48. 'expectedResult' => 'prefix00000002'
  49. ],
  50. ];
  51. }
  52. /**
  53. * @expectedException \Magento\Framework\Exception\LocalizedException
  54. * @expectedExceptionMessage Invalid character encountered in increment ID: ---wrong-id---
  55. */
  56. public function testGetNextIdThrowsExceptionIfIdContainsNotAllowedCharacters()
  57. {
  58. $this->model->setLastId('---wrong-id---');
  59. $this->model->setPrefix('prefix');
  60. $this->model->getNextId();
  61. }
  62. }