|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\SalesSequence\Test\Integration\Setup; |
| 10 | + |
| 11 | +use Magento\Framework\App\ResourceConnection as AppResource; |
| 12 | +use Magento\Framework\ObjectManagerInterface; |
| 13 | +use Magento\SalesSequence\Model\Config as SequenceConfig; |
| 14 | +use Magento\TestFramework\Helper\Bootstrap; |
| 15 | +use Magento\SalesSequence\Setup\SequenceCreator; |
| 16 | +use Magento\SalesSequence\Model\ResourceModel\Meta as MetaResource; |
| 17 | +use Magento\SalesSequence\Model\ResourceModel\Profile as ProfileResource; |
| 18 | +use Magento\SalesSequence\Model\EntityPool; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | + |
| 21 | +/** |
| 22 | + * Testing data from the sales_sequence_profile table for default stores |
| 23 | + */ |
| 24 | +class SequenceCreatorTest extends TestCase |
| 25 | +{ |
| 26 | + /** |
| 27 | + * @var ObjectManagerInterface |
| 28 | + */ |
| 29 | + private $objectManger; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var SequenceCreator |
| 33 | + */ |
| 34 | + private $sequenceCreator; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var EntityPool |
| 38 | + */ |
| 39 | + private $entityPool; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var MetaResource |
| 43 | + */ |
| 44 | + private $sequenceMetaResource; |
| 45 | + |
| 46 | + /** |
| 47 | + * @var ProfileResource |
| 48 | + */ |
| 49 | + private $sequenceProfileResource; |
| 50 | + |
| 51 | + /** |
| 52 | + * @var SequenceConfig |
| 53 | + */ |
| 54 | + private $sequenceConfig; |
| 55 | + |
| 56 | + /** |
| 57 | + * @var AppResource |
| 58 | + */ |
| 59 | + private $appResource; |
| 60 | + |
| 61 | + /** |
| 62 | + * @inheritdoc |
| 63 | + */ |
| 64 | + protected function setUp(): void |
| 65 | + { |
| 66 | + $this->objectManger = Bootstrap::getObjectManager(); |
| 67 | + $this->sequenceCreator = $this->objectManger->create(SequenceCreator::class); |
| 68 | + $this->sequenceMetaResource = $this->objectManger->create(MetaResource::class); |
| 69 | + $this->sequenceProfileResource = $this->objectManger->create(ProfileResource::class); |
| 70 | + $this->entityPool = $this->objectManger->create(EntityPool::class); |
| 71 | + $this->sequenceConfig = $this->objectManger->create(SequenceConfig::class); |
| 72 | + $this->appResource = $this->objectManger->create(AppResource::class); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Testing data from the sales_sequence_profile table for default stores |
| 77 | + * |
| 78 | + * @param array $defaultStores |
| 79 | + * @dataProvider defaultStoresDataProvider |
| 80 | + */ |
| 81 | + public function testSalesSequenceProfileTableForDefaultStores(array $defaultStores): void |
| 82 | + { |
| 83 | + foreach ($defaultStores as $storeId) { |
| 84 | + foreach ($this->entityPool->getEntities() as $entityType) { |
| 85 | + $meta = $this->sequenceMetaResource->loadByEntityTypeAndStore($entityType, $storeId); |
| 86 | + $profile = $this->sequenceProfileResource->loadActiveProfile($meta->getId()); |
| 87 | + $this->assertEquals($this->getSequenceTableName($entityType, $storeId), $meta->getSequenceTable()); |
| 88 | + $this->assertEquals($this->sequenceConfig->get('startValue'), $profile->getStartValue()); |
| 89 | + $this->assertEquals($this->sequenceConfig->get('suffix'), $profile->getSuffix()); |
| 90 | + $this->assertEquals($this->sequenceConfig->get('step'), $profile->getStep()); |
| 91 | + $this->assertEquals($this->sequenceConfig->get('warningValue'), $profile->getWarningValue()); |
| 92 | + $this->assertEquals($this->sequenceConfig->get('maxValue'), $profile->getMaxValue()); |
| 93 | + |
| 94 | + if ($storeId === 0) { |
| 95 | + $this->assertEquals(null, $profile->getPrefix()); |
| 96 | + } else { |
| 97 | + $this->assertNotNull($profile->getPrefix()); |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Default stores data provider |
| 105 | + * |
| 106 | + * @return array |
| 107 | + */ |
| 108 | + public function defaultStoresDataProvider(): array |
| 109 | + { |
| 110 | + return [ |
| 111 | + [ |
| 112 | + 'defaultStores' => [ |
| 113 | + 0, |
| 114 | + 1 |
| 115 | + ] |
| 116 | + ], |
| 117 | + ]; |
| 118 | + |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Get sequence table name |
| 123 | + * |
| 124 | + * @param string $entityType |
| 125 | + * @param int $storeId |
| 126 | + * |
| 127 | + * @return string |
| 128 | + */ |
| 129 | + private function getSequenceTableName(string $entityType, int $storeId): string |
| 130 | + { |
| 131 | + return $this->appResource->getTableName( |
| 132 | + sprintf( |
| 133 | + 'sequence_%s_%s', |
| 134 | + $entityType, |
| 135 | + $storeId |
| 136 | + ) |
| 137 | + ); |
| 138 | + } |
| 139 | +} |
0 commit comments