Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:09:21+00:00 2026-06-08T21:09:21+00:00

Is there way to test Magento POST controllers actions? E.g. customer login: Mage_Customer_AccountController::loginPostAction() I’m

  • 0

Is there way to test Magento POST controllers actions? E.g. customer login:

Mage_Customer_AccountController::loginPostAction()

I’m using EcomDev_PHPUnit module for test. It works great with basic actions, but I can’t invoke POST actions.

$this->getRequest()->setMethod('POST');
// ivokes loginAction instead loginPostAction
$this->dispatch('customer/account/login');
// fails also
$this->dispatch('customer/account/loginPost');
// but this assert pass
$this->assertEquals('POST', $_SERVER['REQUEST_METHOD']);

I would like to make tests more or less like

// ... some setup
$this->getRequest()->setMethod('POST');
$this->dispatch('customer/account/login');
// since login uses singleton, then...
$session = Mage::getSingleton('customer/session');
$this->assertTrue($session->isLoggedIn());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:09:23+00:00Added an answer on June 8, 2026 at 9:09 pm

    In customer account controller login and loginPost is two different actions. As for logging in, you need to do something like this:

    // Setting data for request
    $this->getRequest()->setMethod('POST')
            ->setPost('login', array(
                'username' => 'customer@email.com',
                'password' => 'customer_password'
            ));
    
    $this->dispatch('customer/account/loginpost'); // This will login customer via controller
    

    But this kind of test body is only required if you need to test login process, but if just want to simulate that customer is logged in, you can create a stub that particular customer is logged in. I used it in few projects. Just add this method to your test case and then use when you need it. It will login customer within single test run and will tear down all the session changes afterwards.

    /**
     * Creates information in the session,
     * that customer is logged in
     *
     * @param string $customerEmail
     * @param string $customerPassword
     * @return Mage_Customer_Model_Session|PHPUnit_Framework_MockObject_MockObject
     */
    protected function createCustomerSession($customerId, $storeId = null)
    {
        // Create customer session mock, for making our session singleton isolated
        $customerSessionMock = $this->getModelMock('customer/session', array('renewSession'));
        $this->replaceByMock('singleton', 'customer/session', $customerSessionMock);
    
        if ($storeId === null) {
            $storeId = $this->app()->getAnyStoreView()->getCode();
        }
    
        $this->setCurrentStore($storeId);
        $customerSessionMock->loginById($customerId);
    
        return $customerSessionMock;
    }
    

    Also renewSession method is mocked in above code, because it is using direct setcookie function, instead of core/cookie model, so in command line it produces an error.

    Sincerely,
    Ivan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to test the multitouch capability of an application using a
Is there a way to test, using Python, how long the system has been
Is there a way to test a Web Service using VS2010 like it's used
Using PHP, is there a way to test if the browser is accessing a
Is there a way to test code coverage within visual studio if I'm using
Is there any way to test in code about which certificate is using? (Development
Is there a way to test if the current thread is holding a monitor
Is there a way to test to see if javascript is enabled to ensure
Is there a canonical way to test to see if the process has administrative
Is there any way to first test if a file is in use before

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.