Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG FIX - Uncaught exception when accessing admin with none existent use... #2

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/code/core/Mage/Admin/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,11 @@ public function reload()
*/
public function loadByUsername($username)
{
$this->setData($this->getResource()->loadByUsername($username));
$user = $this->getResource()->loadByUsername($username);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to practice implementing an integration test for this method?
Supposedly dev/tests/integration/testsuite/Mage/Admin/Model/UserTest.php -- it doesn't exist yet. But implementing just loadByUsernameTest() would be enough.

I recommend using @magentoDataFixture to create a test admin account fixture. The fixture will be reverted automatically after test execution.

if ($user) {
$this->setData($user);
}

return $this;
}

Expand Down
56 changes: 56 additions & 0 deletions dev/tests/integration/testsuite/Mage/Admin/Model/UserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Magento
* @package Magento_Admin
* @subpackage integration_tests
* @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Tests admin user model:
* - general behaviour is tested
*
* @group module:Mage_Admin
* @magentoDataFixture Mage/Admin/_files/user.php
*/
class Mage_Admin_Model_UserTest extends PHPUnit_Framework_TestCase
{
/**
* @var Mage_Admin_Model_User
*/
protected $_model;

protected function setUp()
{
$this->_model = new Mage_Admin_Model_User;
}

/**
* Ensure that an exception is not thrown if the user does not exist
*/
public function testloadByUsername() {
$this->_model->loadByUsername('non_exiting_user');
$this->assertNull($this->_model->getId(), 'The admin user has an unexpected ID');
$this->_model->loadByUsername('adminuser');
$this->assertTrue(!is_null($this->_model->getId()), 'The admin user should have been loaded');
}
}
35 changes: 35 additions & 0 deletions dev/tests/integration/testsuite/Mage/Admin/_files/user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Magento
* @package Mage_Admin
* @subpackage integration_tests
* @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

$product = new Mage_Admin_Model_User();
$product->setFirstname('Admin')
->setLastname('User')
->setEmail('test@magento.com')
->setUsername('adminuser')
->setPassword('1234567890')
->setIsActive(1)
->save();