Skip to content

Commit 27c8f7c

Browse files
committed
ACP2E-998: Order Increment Id not generated with the prefix
1 parent 77339d3 commit 27c8f7c

File tree

1 file changed

+228
-0
lines changed

1 file changed

+228
-0
lines changed

setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
use Magento\Framework\Config\File\ConfigFilePool;
2323
use Magento\Framework\DB\Adapter\AdapterInterface;
2424
use Magento\Framework\DB\Ddl\Table;
25+
use Magento\Framework\DB\Select;
26+
use Magento\Framework\Exception\FileSystemException;
27+
use Magento\Framework\Exception\LocalizedException;
2528
use Magento\Framework\Exception\RuntimeException;
2629
use Magento\Framework\Filesystem;
2730
use Magento\Framework\Filesystem\Directory\WriteInterface;
@@ -41,6 +44,7 @@
4144
use Magento\Framework\Validation\ValidationException;
4245
use Magento\RemoteStorage\Driver\DriverException;
4346
use Magento\RemoteStorage\Setup\ConfigOptionsList as RemoteStorageValidator;
47+
use Magento\Setup\Console\Command\InstallCommand;
4448
use Magento\Setup\Controller\ResponseTypeInterface;
4549
use Magento\Setup\Model\AdminAccount;
4650
use Magento\Setup\Model\AdminAccountFactory;
@@ -562,6 +566,230 @@ public function installDataProvider()
562566
];
563567
}
564568

569+
/**
570+
* Test the installation with order increment prefix set and enabled
571+
*
572+
* @param array $request
573+
* @param array $logMessages
574+
* @throws RuntimeException
575+
* @throws FileSystemException
576+
* @throws LocalizedException
577+
* @dataProvider installWithOrderIncrementPrefixDataProvider
578+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
579+
*/
580+
public function testInstallWithOrderIncrementPrefix(array $request, array $logMessages)
581+
{
582+
$this->moduleList->method('getOne')
583+
->willReturnMap(
584+
[
585+
['Foo_One', ['setup_version' => '2.0.0']],
586+
['Bar_Two', ['setup_version' => null]]
587+
]
588+
);
589+
590+
$this->config->expects($this->atLeastOnce())
591+
->method('get')
592+
->willReturnMap(
593+
[
594+
[ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true],
595+
[ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true],
596+
['modules/Magento_User', null, '1']
597+
]
598+
);
599+
$allModules = ['Foo_One' => [], 'Bar_Two' => []];
600+
601+
$this->declarationInstallerMock->expects($this->once())->method('installSchema');
602+
$this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules);
603+
$setup = $this->createMock(Setup::class);
604+
$table = $this->createMock(Table::class);
605+
606+
$select = $this->createMock(Select::class);
607+
$select->expects($this->any())->method('from')->willReturn($select);
608+
$select->expects($this->any())->method('where')->willReturn($select);
609+
610+
$connection = $this->getMockBuilder(AdapterInterface::class)
611+
->onlyMethods(['getTables', 'newTable','select'])
612+
->addMethods(['getSchemaListener'])
613+
->getMockForAbstractClass();
614+
$connection->expects($this->any())->method('getSchemaListener')->willReturn($this->schemaListenerMock);
615+
$connection->expects($this->once())->method('getTables')->willReturn([]);
616+
$connection->expects($this->any())->method('select')->willReturn($select);
617+
618+
$connection->expects($this->atLeastOnce())->method('fetchRow')->willReturn([
619+
'entity_store_id' => 1,
620+
'profile_id' => 1
621+
]);
622+
$connection->expects($this->exactly(2))->method('update');
623+
624+
$setup->expects($this->any())->method('getConnection')->willReturn($connection);
625+
$table->expects($this->any())->method('addColumn')->willReturn($table);
626+
$table->expects($this->any())->method('setComment')->willReturn($table);
627+
$table->expects($this->any())->method('addIndex')->willReturn($table);
628+
$connection->expects($this->any())->method('newTable')->willReturn($table);
629+
$resource = $this->createMock(ResourceConnection::class);
630+
$this->contextMock->expects($this->any())->method('getResources')->willReturn($resource);
631+
$resource->expects($this->any())->method('getConnection')->willReturn($connection);
632+
633+
$moduleResource = $this->getMockBuilder(ModuleResource::class)
634+
->enableOriginalConstructor()
635+
->onlyMethods(['getDbVersion', 'getDataVersion'])
636+
->setConstructorArgs(['context' => $this->contextMock])
637+
->getMock();
638+
$moduleResource->method('getDbVersion')->willReturnOnConsecutiveCalls(false, '2.1.0');
639+
$moduleResource->method('getDataVersion')->willReturn(false);
640+
$this->object->method('getModuleResource')->willReturn($moduleResource);
641+
642+
$dataSetup = $this->createMock(DataSetup::class);
643+
$dataSetup->expects($this->any())->method('getConnection')->willReturn($connection);
644+
$cacheManager = $this->createMock(Manager::class);
645+
$cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
646+
$cacheManager->expects($this->exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']);
647+
$cacheManager->expects($this->exactly(3))->method('clean');
648+
$cacheManager->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]);
649+
$appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
650+
->disableOriginalConstructor()
651+
->disableArgumentCloning()
652+
->getMock();
653+
$appState->expects($this->once())
654+
->method('setAreaCode')
655+
->with(Area::AREA_GLOBAL);
656+
$registry = $this->createMock(Registry::class);
657+
$searchConfigMock = $this->getMockBuilder(SearchConfig::class)->disableOriginalConstructor()->getMock();
658+
659+
$remoteStorageValidatorMock = $this->getMockBuilder(RemoteStorageValidator::class)
660+
->disableOriginalConstructor()
661+
->getMock();
662+
663+
$this->configWriter->expects(static::never())->method('checkIfWritable');
664+
665+
$this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup);
666+
$this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup);
667+
$this->objectManager->expects($this->any())
668+
->method('create')
669+
->willReturnMap(
670+
[
671+
[Manager::class, [], $cacheManager],
672+
[\Magento\Framework\App\State::class, [], $appState],
673+
[
674+
PatchApplierFactory::class,
675+
['objectManager' => $this->objectManager],
676+
$this->patchApplierFactoryMock
677+
],
678+
]
679+
);
680+
$this->patchApplierMock->expects($this->exactly(2))->method('applySchemaPatch')->willReturnMap(
681+
[
682+
['Bar_Two'],
683+
['Foo_One']
684+
]
685+
);
686+
$this->patchApplierMock->expects($this->exactly(2))->method('applyDataPatch')->willReturnMap(
687+
[
688+
['Bar_Two'],
689+
['Foo_One']
690+
]
691+
);
692+
$this->objectManager->expects($this->any())
693+
->method('get')
694+
->willReturnMap(
695+
[
696+
[\Magento\Framework\App\State::class, $appState],
697+
[Manager::class, $cacheManager],
698+
[DeclarationInstaller::class, $this->declarationInstallerMock],
699+
[Registry::class, $registry],
700+
[SearchConfig::class, $searchConfigMock],
701+
[RemoteStorageValidator::class, $remoteStorageValidatorMock]
702+
]
703+
);
704+
$this->adminFactory->expects($this->any())->method('create')->willReturn(
705+
$this->createMock(AdminAccount::class)
706+
);
707+
$this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true);
708+
$this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn(
709+
['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS]
710+
);
711+
$this->filePermissions->expects($this->any())
712+
->method('getMissingWritablePathsForInstallation')
713+
->willReturn([]);
714+
$this->filePermissions->expects($this->once())
715+
->method('getMissingWritableDirectoriesForDbUpgrade')
716+
->willReturn([]);
717+
call_user_func_array(
718+
[
719+
$this->logger->expects($this->exactly(count($logMessages)))->method('log'),
720+
'withConsecutive'
721+
],
722+
$logMessages
723+
);
724+
$this->logger->expects($this->exactly(2))
725+
->method('logSuccess')
726+
->withConsecutive(
727+
['Magento installation complete.'],
728+
['Magento Admin URI: /']
729+
);
730+
731+
$this->object->install($request);
732+
}
733+
734+
/**
735+
* @return array
736+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
737+
*/
738+
public function installWithOrderIncrementPrefixDataProvider(): array
739+
{
740+
return [
741+
[
742+
'request' => [
743+
ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1',
744+
ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento',
745+
ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento',
746+
ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key',
747+
ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend',
748+
InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX => 'ORD'
749+
],
750+
'logMessages' => [
751+
['Starting Magento installation:'],
752+
['File permissions check...'],
753+
['Required extensions check...'],
754+
['Enabling Maintenance Mode...'],
755+
['Installing deployment configuration...'],
756+
['Installing database schema:'],
757+
['Schema creation/updates:'],
758+
['Module \'Foo_One\':'],
759+
['Module \'Bar_Two\':'],
760+
['Schema post-updates:'],
761+
['Module \'Foo_One\':'],
762+
['Module \'Bar_Two\':'],
763+
['Installing search configuration...'],
764+
['Validating remote storage configuration...'],
765+
['Installing user configuration...'],
766+
['Enabling caches:'],
767+
['Current status:'],
768+
['foo: 1'],
769+
['bar: 1'],
770+
['Installing data...'],
771+
['Data install/update:'],
772+
['Disabling caches:'],
773+
['Current status:'],
774+
['Module \'Foo_One\':'],
775+
['Module \'Bar_Two\':'],
776+
['Data post-updates:'],
777+
['Module \'Foo_One\':'],
778+
['Module \'Bar_Two\':'],
779+
['Enabling caches:'],
780+
['Current status:'],
781+
['Creating sales order increment prefix...'], // << added
782+
['Caches clearing:'],
783+
['Cache cleared successfully'],
784+
['Disabling Maintenance Mode:'],
785+
['Post installation file permissions check...'],
786+
['Write installation date...'],
787+
['Sample Data is installed with errors. See log file for details']
788+
],
789+
],
790+
];
791+
}
792+
565793
/**
566794
* Test installation with invalid remote storage configuration raises ValidationException via validation
567795
* and reverts configuration back to local file driver

0 commit comments

Comments
 (0)