Skip to content

Commit

Permalink
Merge pull request #341 from magento-api/develop
Browse files Browse the repository at this point in the history
[API] Sprint 49 – Test Coverage and Bugs
  • Loading branch information
Paliarush, Alexander(apaliarush) committed Jun 5, 2015
2 parents 8fd210d + 7c5177d commit 27b0b2b
Show file tree
Hide file tree
Showing 54 changed files with 3,128 additions and 254 deletions.
11 changes: 9 additions & 2 deletions app/code/Magento/Backend/Block/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ protected function _prepareLayout()

$this->addChild('sales', 'Magento\Backend\Block\Dashboard\Sales');

if ($this->_scopeConfig->getValue(self::XML_PATH_ENABLE_CHARTS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
$isChartEnabled = $this->_scopeConfig->getValue(
self::XML_PATH_ENABLE_CHARTS,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
if ($isChartEnabled) {
$block = $this->getLayout()->createBlock('Magento\Backend\Block\Dashboard\Diagrams');
} else {
$block = $this->getLayout()->createBlock(
'Magento\Backend\Block\Template'
)->setTemplate(
'dashboard/graph/disabled.phtml'
)->setConfigUrl(
$this->getUrl('adminhtml/system_config/edit', ['section' => 'admin'])
$this->getUrl(
'adminhtml/system_config/edit',
['section' => 'admin', '_fragment' => 'admin_dashboard-link']
)
);
}
$this->setChild('diagrams', $block);
Expand Down
8 changes: 5 additions & 3 deletions app/code/Magento/Backend/Model/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getCredentialStorage()
public function login($username, $password)
{
if (empty($username) || empty($password)) {
self::throwException(__('Please correct the user name or password.'));
self::throwException(__('You did not sign in correctly or your account is temporarily disabled.'));
}

try {
Expand All @@ -162,7 +162,7 @@ public function login($username, $password)
}

if (!$this->getAuthStorage()->getUser()) {
self::throwException(__('Please correct the user name or password.'));
self::throwException(__('You did not sign in correctly or your account is temporarily disabled.'));
}
} catch (PluginAuthenticationException $e) {
$this->_eventManager->dispatch(
Expand All @@ -175,7 +175,9 @@ public function login($username, $password)
'backend_auth_user_login_failed',
['user_name' => $username, 'exception' => $e]
);
self::throwException(__($e->getMessage()? : 'Please correct the user name or password.'));
self::throwException(
__($e->getMessage()? : 'You did not sign in correctly or your account is temporarily disabled.')
);
}
}

Expand Down
7 changes: 4 additions & 3 deletions app/code/Magento/Backend/Test/Unit/Model/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function setUp()

/**
* @expectedException \Magento\Framework\Exception\AuthenticationException
* @expectedExceptionMessage Please correct the user name or password.
* @expectedExceptionMessage You did not sign in correctly or your account is temporarily disabled.
*/
public function testLoginFailed()
{
Expand All @@ -59,8 +59,9 @@ public function testLoginFailed()
->method('create')
->with('Magento\Backend\Model\Auth\Credential\StorageInterface')
->will($this->returnValue($this->_credentialStorage));
$exceptionMock =
new \Magento\Framework\Exception\LocalizedException(__('Please correct the user name or password.'));
$exceptionMock = new \Magento\Framework\Exception\LocalizedException(
__('You did not sign in correctly or your account is temporarily disabled.')
);
$this->_credentialStorage
->expects($this->once())
->method('login')
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
"Current Month","Current Month"
YTD,YTD
2YTD,2YTD
"Please correct the user name or password.","Please correct the user name or password."
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
"Authentication error occurred.","Authentication error occurred."
"Please specify the admin custom URL.","Please specify the admin custom URL."
"Invalid %1. %2","Invalid %1. %2"
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
"Current Month","Current Month"
YTD,YTD
2YTD,2YTD
"Please correct the user name or password.","Please correct the user name or password."
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
"Authentication error occurred.","Authentication error occurred."
"Please specify the admin custom URL.","Please specify the admin custom URL."
"Invalid %1. %2","Invalid %1. %2"
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/i18n/es_ES.csv
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
"Current Month","Current Month"
YTD,YTD
2YTD,2YTD
"Please correct the user name or password.","Please correct the user name or password."
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
"Authentication error occurred.","Authentication error occurred."
"Please specify the admin custom URL.","Please specify the admin custom URL."
"Invalid %1. %2","Invalid %1. %2"
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
"Current Month","Current Month"
YTD,YTD
2YTD,2YTD
"Please correct the user name or password.","Please correct the user name or password."
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
"Authentication error occurred.","Authentication error occurred."
"Please specify the admin custom URL.","Please specify the admin custom URL."
"Invalid %1. %2","Invalid %1. %2"
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/i18n/nl_NL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
"Current Month","Current Month"
YTD,YTD
2YTD,2YTD
"Please correct the user name or password.","Please correct the user name or password."
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
"Authentication error occurred.","Authentication error occurred."
"Please specify the admin custom URL.","Please specify the admin custom URL."
"Invalid %1. %2","Invalid %1. %2"
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/i18n/pt_BR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
"Current Month","Current Month"
YTD,YTD
2YTD,2YTD
"Please correct the user name or password.","Please correct the user name or password."
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
"Authentication error occurred.","Authentication error occurred."
"Please specify the admin custom URL.","Please specify the admin custom URL."
"Invalid %1. %2","Invalid %1. %2"
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/i18n/zh_CN.csv
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
"Current Month","Current Month"
YTD,YTD
2YTD,2YTD
"Please correct the user name or password.","Please correct the user name or password."
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
"Authentication error occurred.","Authentication error occurred."
"Please specify the admin custom URL.","Please specify the admin custom URL."
"Invalid %1. %2","Invalid %1. %2"
Expand Down
18 changes: 18 additions & 0 deletions app/code/Magento/Email/Test/Unit/Model/BackendTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class BackendTemplateTest extends \PHPUnit_Framework_TestCase
*/
protected $resourceModelMock;

/**
* @var \Magento\Framework\App\ObjectManager
*/
protected $objectManagerBackup;

protected function setUp()
{
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
Expand All @@ -54,6 +59,13 @@ protected function setUp()
->method('get')
->with('Magento\Email\Model\Resource\Template')
->will($this->returnValue($this->resourceModelMock));

try {
$this->objectManagerBackup = \Magento\Framework\App\ObjectManager::getInstance();
} catch (\RuntimeException $e) {
$this->objectManagerBackup = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $_SERVER)
->create($_SERVER);
}
\Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);

$this->model = $helper->getObject(
Expand All @@ -62,6 +74,12 @@ protected function setUp()
);
}

protected function tearDown()
{
parent::tearDown();
\Magento\Framework\App\ObjectManager::setInstance($this->objectManagerBackup);
}

public function testGetSystemConfigPathsWhereUsedAsDefaultNoTemplateCode()
{
$this->assertEquals([], $this->model->getSystemConfigPathsWhereUsedAsDefault());
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/Integration/Model/AdminTokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public function createAdminAccessToken($username, $password)
* Constant cannot be created in Auth Model since it uses legacy translation that doesn't support it.
* Need to make sure that this is refactored once exception handling is updated in Auth Model.
*/
throw new AuthenticationException(__('Please correct the user name or password.'));
throw new AuthenticationException(
__('You did not sign in correctly or your account is temporarily disabled.')
);
}
return $this->tokenModelFactory->create()->createAdminToken($this->userModel->getId())->getToken();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* Service config data reader.
*
* @codeCoverageIgnore
*/
class Reader extends \Magento\Framework\Config\Reader\Filesystem
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function validate($username, $password)
if (!is_string($username) || strlen($username) == 0) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'username']));
}
if (!is_string($username) || strlen($password) == 0) {
if (!is_string($password) || strlen($password) == 0) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'password']));
}
if ($exception->wasErrorAdded()) {
Expand Down
37 changes: 0 additions & 37 deletions app/code/Magento/Integration/Model/IntegrationFactory.php

This file was deleted.

2 changes: 1 addition & 1 deletion app/code/Magento/Integration/Model/IntegrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(IntegrationFactory $integrationFactory, IntegrationO
public function create(array $integrationData)
{
$this->_checkIntegrationByName($integrationData['name']);
$integration = $this->_integrationFactory->create($integrationData);
$integration = $this->_integrationFactory->create()->setData($integrationData);
$integration->save();
$consumerName = 'Integration' . $integration->getId();
$consumer = $this->_oauthService->createConsumer(['name' => $consumerName]);
Expand Down
44 changes: 20 additions & 24 deletions app/code/Magento/Integration/Model/Oauth/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class Consumer extends \Magento\Framework\Model\AbstractModel implements Consume
/**
* @var \Magento\Framework\Url\Validator
*/
protected $_urlValidator;
protected $urlValidator;

/**
* @var \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLengthFactory
* @var \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength
*/
protected $_keyLengthFactory;
protected $keyLengthValidator;

/**
* @var \Magento\Integration\Helper\Oauth\Data
Expand All @@ -46,7 +46,7 @@ class Consumer extends \Magento\Framework\Model\AbstractModel implements Consume
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLengthFactory $keyLengthFactory
* @param \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength $keyLength
* @param \Magento\Framework\Url\Validator $urlValidator
* @param \Magento\Integration\Helper\Oauth\Data $dataHelper
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
Expand All @@ -56,15 +56,15 @@ class Consumer extends \Magento\Framework\Model\AbstractModel implements Consume
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Integration\Model\Oauth\Consumer\Validator\KeyLengthFactory $keyLengthFactory,
\Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength $keyLength,
\Magento\Framework\Url\Validator $urlValidator,
\Magento\Integration\Helper\Oauth\Data $dataHelper,
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\Db $resourceCollection = null,
array $data = []
) {
$this->_keyLengthFactory = $keyLengthFactory;
$this->_urlValidator = $urlValidator;
$this->keyLengthValidator = $keyLength;
$this->urlValidator = $urlValidator;
$this->dataHelper = $dataHelper;
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}
Expand All @@ -87,9 +87,7 @@ protected function _construct()
*/
public function beforeSave()
{
if (!$this->getId()) {
$this->setUpdatedAt(time());
}
$this->setUpdatedAt(time());
$this->validate();
parent::beforeSave();
return $this;
Expand All @@ -104,29 +102,27 @@ public function validate()
$this->setCallbackUrl(trim($this->getCallbackUrl()));
$this->setRejectedCallbackUrl(trim($this->getRejectedCallbackUrl()));

if ($this->getCallbackUrl() && !$this->_urlValidator->isValid($this->getCallbackUrl())) {
if ($this->getCallbackUrl() && !$this->urlValidator->isValid($this->getCallbackUrl())) {
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Callback URL'));
}
if ($this->getRejectedCallbackUrl() && !$this->_urlValidator->isValid($this->getRejectedCallbackUrl())) {
if ($this->getRejectedCallbackUrl() && !$this->urlValidator->isValid($this->getRejectedCallbackUrl())) {
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Rejected Callback URL'));
}
}

/** @var $validatorLength \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength */
$validatorLength = $this->_keyLengthFactory->create(
['options' => ['length' => \Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY]]
);

$validatorLength->setName('Consumer Key');
if (!$validatorLength->isValid($this->getKey())) {
$messages = $validatorLength->getMessages();
$this->keyLengthValidator
->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY)
->setName('Consumer Key');
if (!$this->keyLengthValidator->isValid($this->getKey())) {
$messages = $this->keyLengthValidator->getMessages();
throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages)));
}

$validatorLength->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET);
$validatorLength->setName('Consumer Secret');
if (!$validatorLength->isValid($this->getSecret())) {
$messages = $validatorLength->getMessages();
$this->keyLengthValidator
->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET)
->setName('Consumer Secret');
if (!$this->keyLengthValidator->isValid($this->getSecret())) {
$messages = $this->keyLengthValidator->getMessages();
throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages)));
}
return true;
Expand Down
Loading

0 comments on commit 27b0b2b

Please sign in to comment.