admin Good To Know Instructions

Logging in to the Magento Admin UI

Logging in to the admin UI is fairly simple, but there are a few things you need to do ahead of time. The actual functionality looks like this:

class LoginTest extends MagiumMagentoAbstractMagentoTestCase
{

    public function testLogin()
    {
        $this->getAction(MagiumMagentoActionsAdminLoginLogin::ACTION)->login();
    }

}

That is all that is needed to log in… from the perspective of an action. But you do need to configure it to work in your environment. There are two ways of doing that.

The bad, but easy way

The easiest way is to configure your admin identity and theme directly in your test.


class LoginTest extends MagiumMagentoAbstractMagentoTestCase { public function testLogin() { $theme = $this->getTheme(MagiumMagentoThemesAdminThemeConfiguration::THEME); /* @var $theme MagiumMagentoThemesAdminThemeConfiguration */ $theme->set('baseUrl', 'http://localhost/admin/'); $admin = $this->getIdentity(MagiumMagentoIdentitiesAdmin::IDENTITY); /* @var $admin MagiumMagentoIdentitiesAdmin */ $admin->setAccount('myaccount'); $admin->setPassword('mypassword'); $this->getAction(MagiumMagentoActionsAdminLoginLogin::ACTION)->login(); } }

That will work, but what if something changes. Then you’ll need to go and change each and every instance where you did that. For that reason you should choose the

Marginally more complicated, but infinitely better way

This involves using the configurable nature of Magium. There are two files you will need to create in the base of your project.

  1. /configuration/Magium/Magento/Themes/Admin/ThemeConfiguration.php
  2. /configuration/Magium/Magento/Identities/Admin.php

This file will contain the configuration information for the theme. In this case the only thing we need to change is the baseUrl.

<?php

$this->baseUrl = 'http://magento19.loc/admin/';

/configuration/Magium/Magento/Themes/Admin/ThemeConfiguration.php

Next up you will need to set the admin username and password.

<?php
$this->account = 'myaccount';
$this->password = 'mypassword';

/configuration/Magium/Magento/Identities/Admin.php

From there any test that requires the admin will be automatically configured to work with these credentials and with this URL.

If you still need some help understanding configurable elements you should check out this video.

Powered by WPeMatico

Leave a Reply

Your email address will not be published. Required fields are marked *