EcomDev / EcomDev_PHPUnit

Magento PHPUnit Integration
http://www.ecomdev.org/shop/code-testing/php-unit-test-suite.html
Open Software License 3.0
299 stars 166 forks source link

HTTPS for unsecure baseurl not working #272

Open mobilizer opened 8 years ago

mobilizer commented 8 years ago

If baseurl is using HTTPS simple controller tests doing a dispatch exit with 0.

E.g.: $this->dispatch('');

There is a 302 redirect and an exit, due to Mage_Core_Controller_Varien_Router_Standard::_checkShouldBeSecure(...). and $request->isSecure() is false because $_SERVER['HTTPS'] is not defined.

local.xml.phpunit looks like:

<config>
   <global>
      ...
   </global>
   <default>
      <web>
         <seo>
            <use_rewrites>1</use_rewrites>
         </seo>
         <secure>
            <base_url>https://xyz.dev/</base_url>
         </secure>
         <unsecure>
            <base_url>https://xyz.dev/</base_url>
         </unsecure>
         <url>
            <redirect_to_base>0</redirect_to_base>
         </url>
      </web>
   </default>
   <phpunit>
      <allow_same_db>0</allow_same_db>
   </phpunit>
</config>

core config is: web/unsecure/base_url https://xyz.dev/

I can work around the issue by manually setting $_SERVER['HTTPS'] in the test.

class XYZ_Subaccounts_Test_Controller_SimpleTest extends EcomDev_PHPUnit_Test_Case_Controller {

/**
 * @test
 * @group simpletest
 */
public function cmsindexTest() {
    // Workarround if unsecure baseurl is also httpS
    $_SERVER['HTTPS'] = 'on';

    $this->dispatch('');
    $this->assertRequestRoute('cms/index/index');
}

}

Don't know if there is a misconfiguration. I used dev branch. It is on OS X. PHP 5.6,5.5, PHPUnit 4.8.26.