NumericTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\NumericValue;
  8. class NumericTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var NumericValue
  12. */
  13. private $model;
  14. protected function setUp()
  15. {
  16. $this->model = new \Magento\Eav\Model\Entity\Increment\NumericValue();
  17. }
  18. /**
  19. * @param int $lastId
  20. * @param string $prefix
  21. * @param int|string $expectedResult
  22. * @dataProvider getLastIdDataProvider
  23. */
  24. public function testGetNextId($lastId, $prefix, $expectedResult)
  25. {
  26. $this->model->setLastId($lastId);
  27. $this->model->setPrefix($prefix);
  28. $this->assertEquals($expectedResult, $this->model->getNextId());
  29. }
  30. /**
  31. * @return array
  32. */
  33. public function getLastIdDataProvider()
  34. {
  35. return [
  36. [
  37. 'lastId' => 1,
  38. 'prefix' => 'prefix',
  39. 'expectedResult' => 'prefix00000002',
  40. ],
  41. [
  42. 'lastId' => 'prefix00000001',
  43. 'prefix' => 'prefix',
  44. 'expectedResult' => 'prefix00000002'
  45. ],
  46. ];
  47. }
  48. public function testGetPadLength()
  49. {
  50. $this->assertEquals(8, $this->model->getPadLength());
  51. $this->model->setPadLength(10);
  52. $this->assertEquals(10, $this->model->getPadLength());
  53. }
  54. public function getPadChar()
  55. {
  56. $this->assertEquals('0', $this->model->getPadChar());
  57. $this->model->setPadChar('z');
  58. $this->assertEquals('z', $this->model->getPadChar());
  59. }
  60. public function testFormat()
  61. {
  62. $this->model->setPrefix('prefix');
  63. $this->model->setPadLength(3);
  64. $this->model->setPadChar('z');
  65. $this->assertEquals('prefixzz1', $this->model->format(1));
  66. }
  67. public function testFrontendFormat()
  68. {
  69. $this->assertEquals('value', $this->model->frontendFormat('value'));
  70. }
  71. }