IndexTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /***
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Version\Controller\Index;
  7. class IndexTest extends \Magento\TestFramework\TestCase\AbstractController
  8. {
  9. public function testIndexAction()
  10. {
  11. // Execute controller to get version response
  12. $this->dispatch('magento_version/index/index');
  13. $body = $this->getResponse()->getBody();
  14. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  15. /** @var \Magento\Framework\App\ProductMetadataInterface $productMetadata */
  16. $productMetadata = $objectManager->get(\Magento\Framework\App\ProductMetadataInterface::class);
  17. $name = $productMetadata->getName();
  18. $edition = $productMetadata->getEdition();
  19. $fullVersion = $productMetadata->getVersion();
  20. if ($this->isComposerBasedInstallation($fullVersion)) {
  21. $versionParts = explode('.', $fullVersion);
  22. $majorMinor = $versionParts[0] . '.' . $versionParts[1];
  23. // Response must contain Major.Minor version, product name, and edition
  24. $this->assertContains($majorMinor, $body);
  25. $this->assertContains($name, $body);
  26. $this->assertContains($edition, $body);
  27. // Response must not contain full version including patch version
  28. $this->assertNotContains($fullVersion, $body);
  29. } else {
  30. // Response is supposed to be empty when the project is installed from git
  31. $this->assertEmpty($body);
  32. }
  33. }
  34. private function isComposerBasedInstallation($fullVersion)
  35. {
  36. $versionParts = explode('-', $fullVersion);
  37. return !(isset($versionParts[0]) && $versionParts[0] == 'dev');
  38. }
  39. }