IndexTest.php 1.75 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
<?php
/***
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Version\Controller\Index;

class IndexTest extends \Magento\TestFramework\TestCase\AbstractController
{
    public function testIndexAction()
    {
        // Execute controller to get version response
        $this->dispatch('magento_version/index/index');
        $body = $this->getResponse()->getBody();

        $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
        /** @var \Magento\Framework\App\ProductMetadataInterface $productMetadata */
        $productMetadata = $objectManager->get(\Magento\Framework\App\ProductMetadataInterface::class);
        $name = $productMetadata->getName();
        $edition = $productMetadata->getEdition();

        $fullVersion = $productMetadata->getVersion();
        if ($this->isComposerBasedInstallation($fullVersion)) {
            $versionParts = explode('.', $fullVersion);
            $majorMinor = $versionParts[0] . '.' . $versionParts[1];

            // Response must contain Major.Minor version, product name, and edition
            $this->assertContains($majorMinor, $body);
            $this->assertContains($name, $body);
            $this->assertContains($edition, $body);

            // Response must not contain full version including patch version
            $this->assertNotContains($fullVersion, $body);
        } else {
            // Response is supposed to be empty when the project is installed from git
            $this->assertEmpty($body);
        }
    }

    private function isComposerBasedInstallation($fullVersion)
    {
        $versionParts = explode('-', $fullVersion);
        return !(isset($versionParts[0]) && $versionParts[0] == 'dev');
    }
}