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 \Magium\Magento\AbstractMagentoTestCase

    public function testLogin()


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 \Magium\Magento\AbstractMagentoTestCase { public function testLogin() { $theme = $this->getTheme(\Magium\Magento\Themes\Admin\ThemeConfiguration::THEME); /* @var $theme \Magium\Magento\Themes\Admin\ThemeConfiguration */ $theme->set('baseUrl', 'http://localhost/admin/'); $admin = $this->getIdentity(\Magium\Magento\Identities\Admin::IDENTITY); /* @var $admin \Magium\Magento\Identities\Admin */ $admin->setAccount('myaccount'); $admin->setPassword('mypassword'); $this->getAction(\Magium\Magento\Actions\Admin\Login\Login::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.


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


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

$this->account = 'myaccount';
$this->password = 'mypassword';


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.