From 2382540ae7bcc110224bc5dcd9d32d4a7a8aec06 Mon Sep 17 00:00:00 2001 From: Roger Date: Sat, 21 Dec 2024 18:51:02 +0000 Subject: [PATCH 1/2] remove version in production mode --- .../Version/Controller/Index/Index.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Version/Controller/Index/Index.php b/app/code/Magento/Version/Controller/Index/Index.php index 512dbe13ab3c0..6123ed32bd754 100644 --- a/app/code/Magento/Version/Controller/Index/Index.php +++ b/app/code/Magento/Version/Controller/Index/Index.php @@ -1,7 +1,7 @@ rawFactory = $rawFactory; $this->productMetadata = $productMetadata; + $this->appState = $appState ?: ObjectManager::getInstance()->get(AppState::class); } /** @@ -55,11 +65,12 @@ public function execute() $version = $this->productMetadata->getVersion() ?? ''; $versionParts = explode('.', $version); if (!$this->isGitBasedInstallation($version) && $this->isCorrectVersion($versionParts)) { - $rawResponse->setContents( - $this->productMetadata->getName() . '/' . - $this->getMajorMinorVersion($versionParts) . - ' (' . $this->productMetadata->getEdition() . ')' - ); + $content = $this->productMetadata->getName(); + if ($this->appState->getMode() != AppState::MODE_PRODUCTION) { + $content .= '/' . $this->getMajorMinorVersion($versionParts) . + ' (' . $this->productMetadata->getEdition() . ')'; + } + $rawResponse->setContents($content); } return $rawResponse; From 300838540a9fd0f748643efdf14f1840d17b21ba Mon Sep 17 00:00:00 2001 From: Roger Date: Sun, 22 Dec 2024 04:09:37 +0000 Subject: [PATCH 2/2] add unit test --- .../Test/Unit/Controller/Index/IndexTest.php | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Version/Test/Unit/Controller/Index/IndexTest.php b/app/code/Magento/Version/Test/Unit/Controller/Index/IndexTest.php index 045cb4c40267e..eb27230064bf5 100644 --- a/app/code/Magento/Version/Test/Unit/Controller/Index/IndexTest.php +++ b/app/code/Magento/Version/Test/Unit/Controller/Index/IndexTest.php @@ -1,7 +1,7 @@ onlyMethods(['getName', 'getEdition', 'getVersion']) ->getMockForAbstractClass(); + $this->appStateMock = $this->createMock(AppState::class); + $this->rawResponseFactoryMock = $this->createPartialMock(RawFactory::class, ['create']); $this->rawResponseMock = $this->createPartialMock(Raw::class, ['setContents']); $this->rawResponseFactoryMock->method('create')->willReturn($this->rawResponseMock); @@ -51,7 +57,8 @@ protected function setUp(): void $this->versionController = new VersionIndex( $this->contextMock, $this->rawResponseFactoryMock, - $this->productMetadataMock + $this->productMetadataMock, + $this->appStateMock ); } @@ -85,4 +92,19 @@ public function testCommunityVersionDisplaysMajorMinorVersionAndEditionName(): v $this->versionController->execute(); } + + public function testCommunityVersionDisplaysMajorMinorVersionAndEditionNameProductionMode(): void + { + $this->productMetadataMock->expects($this->any())->method('getVersion')->willReturn('2.3.3'); + $this->productMetadataMock->expects($this->any())->method('getEdition')->willReturn('Community'); + $this->productMetadataMock->expects($this->any())->method('getName')->willReturn('Magento'); + + $this->appStateMock->expects($this->any())->method('getMode')->willReturn(AppState::MODE_PRODUCTION); + + $this->rawResponseMock->expects($this->once())->method('setContents') + ->with('Magento') + ->willReturnSelf(); + + $this->versionController->execute(); + } }