ExpressionConverterTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /***
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\DB\Test\Unit;
  7. use Magento\Framework\DB\ExpressionConverter;
  8. class ExpressionConverterTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @dataProvider shortenEntityNameDataProvider
  12. */
  13. public function testShortenEntityName($in, $prefix, $expectedOut)
  14. {
  15. $resultEntityName = ExpressionConverter::shortenEntityName($in, $prefix);
  16. $this->assertTrue(
  17. strpos($resultEntityName, $expectedOut) === 0,
  18. "Entity name '$resultEntityName' did not begin with expected value '$expectedOut'"
  19. );
  20. }
  21. /**
  22. * @return array
  23. */
  24. public function shortenEntityNameDataProvider()
  25. {
  26. $length64 = '________________________________________________________________';
  27. $length40 = '________________________________________';
  28. return [
  29. 'Short identifier' => [
  30. 'already_short',
  31. 'pre_',
  32. 'already_short'
  33. ],
  34. 'Hashed identifer' => [
  35. $length64 . '_cannotBeAbbreviated',
  36. 'pre_',
  37. 'pre_'
  38. ],
  39. 'Abbreviated identifier' => [
  40. $length40 . 'downloadable_notification_index',
  41. 'pre_',
  42. $length40 . 'dl_ntfc_idx'
  43. ],
  44. ];
  45. }
  46. public function testShortenEntityNameReducedHash()
  47. {
  48. /** Length of 64 characters, to go over max MySql identifier length */
  49. $length64 = '________________________________________________________________';
  50. $longPrefix = 'pre_____________________________________';
  51. $shortenedName = ExpressionConverter::shortenEntityName($length64 . '_cannotBeAbbreviated', $longPrefix);
  52. $this->assertNotSame(0, strpos($shortenedName, 'pre'), 'Entity name not supposed to with long prefix');
  53. }
  54. }