Skip to content

Commit 27b0b2b

Browse files
author
Paliarush, Alexander(apaliarush)
committed
Merge pull request #341 from magento-api/develop
[API] Sprint 49 – Test Coverage and Bugs
2 parents 8fd210d + 7c5177d commit 27b0b2b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3128
-254
lines changed

app/code/Magento/Backend/Block/Dashboard.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,22 @@ protected function _prepareLayout()
3131

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

34-
if ($this->_scopeConfig->getValue(self::XML_PATH_ENABLE_CHARTS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
34+
$isChartEnabled = $this->_scopeConfig->getValue(
35+
self::XML_PATH_ENABLE_CHARTS,
36+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
37+
);
38+
if ($isChartEnabled) {
3539
$block = $this->getLayout()->createBlock('Magento\Backend\Block\Dashboard\Diagrams');
3640
} else {
3741
$block = $this->getLayout()->createBlock(
3842
'Magento\Backend\Block\Template'
3943
)->setTemplate(
4044
'dashboard/graph/disabled.phtml'
4145
)->setConfigUrl(
42-
$this->getUrl('adminhtml/system_config/edit', ['section' => 'admin'])
46+
$this->getUrl(
47+
'adminhtml/system_config/edit',
48+
['section' => 'admin', '_fragment' => 'admin_dashboard-link']
49+
)
4350
);
4451
}
4552
$this->setChild('diagrams', $block);

app/code/Magento/Backend/Model/Auth.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function getCredentialStorage()
145145
public function login($username, $password)
146146
{
147147
if (empty($username) || empty($password)) {
148-
self::throwException(__('Please correct the user name or password.'));
148+
self::throwException(__('You did not sign in correctly or your account is temporarily disabled.'));
149149
}
150150

151151
try {
@@ -162,7 +162,7 @@ public function login($username, $password)
162162
}
163163

164164
if (!$this->getAuthStorage()->getUser()) {
165-
self::throwException(__('Please correct the user name or password.'));
165+
self::throwException(__('You did not sign in correctly or your account is temporarily disabled.'));
166166
}
167167
} catch (PluginAuthenticationException $e) {
168168
$this->_eventManager->dispatch(
@@ -175,7 +175,9 @@ public function login($username, $password)
175175
'backend_auth_user_login_failed',
176176
['user_name' => $username, 'exception' => $e]
177177
);
178-
self::throwException(__($e->getMessage()? : 'Please correct the user name or password.'));
178+
self::throwException(
179+
__($e->getMessage()? : 'You did not sign in correctly or your account is temporarily disabled.')
180+
);
179181
}
180182
}
181183

app/code/Magento/Backend/Test/Unit/Model/AuthTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function setUp()
5050

5151
/**
5252
* @expectedException \Magento\Framework\Exception\AuthenticationException
53-
* @expectedExceptionMessage Please correct the user name or password.
53+
* @expectedExceptionMessage You did not sign in correctly or your account is temporarily disabled.
5454
*/
5555
public function testLoginFailed()
5656
{
@@ -59,8 +59,9 @@ public function testLoginFailed()
5959
->method('create')
6060
->with('Magento\Backend\Model\Auth\Credential\StorageInterface')
6161
->will($this->returnValue($this->_credentialStorage));
62-
$exceptionMock =
63-
new \Magento\Framework\Exception\LocalizedException(__('Please correct the user name or password.'));
62+
$exceptionMock = new \Magento\Framework\Exception\LocalizedException(
63+
__('You did not sign in correctly or your account is temporarily disabled.')
64+
);
6465
$this->_credentialStorage
6566
->expects($this->once())
6667
->method('login')

app/code/Magento/Backend/i18n/de_DE.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
287287
"Current Month","Current Month"
288288
YTD,YTD
289289
2YTD,2YTD
290-
"Please correct the user name or password.","Please correct the user name or password."
290+
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
291291
"Authentication error occurred.","Authentication error occurred."
292292
"Please specify the admin custom URL.","Please specify the admin custom URL."
293293
"Invalid %1. %2","Invalid %1. %2"

app/code/Magento/Backend/i18n/en_US.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
287287
"Current Month","Current Month"
288288
YTD,YTD
289289
2YTD,2YTD
290-
"Please correct the user name or password.","Please correct the user name or password."
290+
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
291291
"Authentication error occurred.","Authentication error occurred."
292292
"Please specify the admin custom URL.","Please specify the admin custom URL."
293293
"Invalid %1. %2","Invalid %1. %2"

app/code/Magento/Backend/i18n/es_ES.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
287287
"Current Month","Current Month"
288288
YTD,YTD
289289
2YTD,2YTD
290-
"Please correct the user name or password.","Please correct the user name or password."
290+
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
291291
"Authentication error occurred.","Authentication error occurred."
292292
"Please specify the admin custom URL.","Please specify the admin custom URL."
293293
"Invalid %1. %2","Invalid %1. %2"

app/code/Magento/Backend/i18n/fr_FR.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
287287
"Current Month","Current Month"
288288
YTD,YTD
289289
2YTD,2YTD
290-
"Please correct the user name or password.","Please correct the user name or password."
290+
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
291291
"Authentication error occurred.","Authentication error occurred."
292292
"Please specify the admin custom URL.","Please specify the admin custom URL."
293293
"Invalid %1. %2","Invalid %1. %2"

app/code/Magento/Backend/i18n/nl_NL.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
287287
"Current Month","Current Month"
288288
YTD,YTD
289289
2YTD,2YTD
290-
"Please correct the user name or password.","Please correct the user name or password."
290+
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
291291
"Authentication error occurred.","Authentication error occurred."
292292
"Please specify the admin custom URL.","Please specify the admin custom URL."
293293
"Invalid %1. %2","Invalid %1. %2"

app/code/Magento/Backend/i18n/pt_BR.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
287287
"Current Month","Current Month"
288288
YTD,YTD
289289
2YTD,2YTD
290-
"Please correct the user name or password.","Please correct the user name or password."
290+
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
291291
"Authentication error occurred.","Authentication error occurred."
292292
"Please specify the admin custom URL.","Please specify the admin custom URL."
293293
"Invalid %1. %2","Invalid %1. %2"

app/code/Magento/Backend/i18n/zh_CN.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ Synchronizing...,Synchronizing...
287287
"Current Month","Current Month"
288288
YTD,YTD
289289
2YTD,2YTD
290-
"Please correct the user name or password.","Please correct the user name or password."
290+
"You did not sign in correctly or your account is temporarily disabled.","You did not sign in correctly or your account is temporarily disabled."
291291
"Authentication error occurred.","Authentication error occurred."
292292
"Please specify the admin custom URL.","Please specify the admin custom URL."
293293
"Invalid %1. %2","Invalid %1. %2"

app/code/Magento/Email/Test/Unit/Model/BackendTemplateTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class BackendTemplateTest extends \PHPUnit_Framework_TestCase
3737
*/
3838
protected $resourceModelMock;
3939

40+
/**
41+
* @var \Magento\Framework\App\ObjectManager
42+
*/
43+
protected $objectManagerBackup;
44+
4045
protected function setUp()
4146
{
4247
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -54,6 +59,13 @@ protected function setUp()
5459
->method('get')
5560
->with('Magento\Email\Model\Resource\Template')
5661
->will($this->returnValue($this->resourceModelMock));
62+
63+
try {
64+
$this->objectManagerBackup = \Magento\Framework\App\ObjectManager::getInstance();
65+
} catch (\RuntimeException $e) {
66+
$this->objectManagerBackup = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $_SERVER)
67+
->create($_SERVER);
68+
}
5769
\Magento\Framework\App\ObjectManager::setInstance($objectManagerMock);
5870

5971
$this->model = $helper->getObject(
@@ -62,6 +74,12 @@ protected function setUp()
6274
);
6375
}
6476

77+
protected function tearDown()
78+
{
79+
parent::tearDown();
80+
\Magento\Framework\App\ObjectManager::setInstance($this->objectManagerBackup);
81+
}
82+
6583
public function testGetSystemConfigPathsWhereUsedAsDefaultNoTemplateCode()
6684
{
6785
$this->assertEquals([], $this->model->getSystemConfigPathsWhereUsedAsDefault());

app/code/Magento/Integration/Model/AdminTokenService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ public function createAdminAccessToken($username, $password)
7979
* Constant cannot be created in Auth Model since it uses legacy translation that doesn't support it.
8080
* Need to make sure that this is refactored once exception handling is updated in Auth Model.
8181
*/
82-
throw new AuthenticationException(__('Please correct the user name or password.'));
82+
throw new AuthenticationException(
83+
__('You did not sign in correctly or your account is temporarily disabled.')
84+
);
8385
}
8486
return $this->tokenModelFactory->create()->createAdminToken($this->userModel->getId())->getToken();
8587
}

app/code/Magento/Integration/Model/Config/Integration/Reader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/**
99
* Service config data reader.
10+
*
11+
* @codeCoverageIgnore
1012
*/
1113
class Reader extends \Magento\Framework\Config\Reader\Filesystem
1214
{

app/code/Magento/Integration/Model/CredentialsValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function validate($username, $password)
2727
if (!is_string($username) || strlen($username) == 0) {
2828
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'username']));
2929
}
30-
if (!is_string($username) || strlen($password) == 0) {
30+
if (!is_string($password) || strlen($password) == 0) {
3131
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'password']));
3232
}
3333
if ($exception->wasErrorAdded()) {

app/code/Magento/Integration/Model/IntegrationFactory.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

app/code/Magento/Integration/Model/IntegrationService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(IntegrationFactory $integrationFactory, IntegrationO
4545
public function create(array $integrationData)
4646
{
4747
$this->_checkIntegrationByName($integrationData['name']);
48-
$integration = $this->_integrationFactory->create($integrationData);
48+
$integration = $this->_integrationFactory->create()->setData($integrationData);
4949
$integration->save();
5050
$consumerName = 'Integration' . $integration->getId();
5151
$consumer = $this->_oauthService->createConsumer(['name' => $consumerName]);

app/code/Magento/Integration/Model/Oauth/Consumer.php

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class Consumer extends \Magento\Framework\Model\AbstractModel implements Consume
3131
/**
3232
* @var \Magento\Framework\Url\Validator
3333
*/
34-
protected $_urlValidator;
34+
protected $urlValidator;
3535

3636
/**
37-
* @var \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLengthFactory
37+
* @var \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength
3838
*/
39-
protected $_keyLengthFactory;
39+
protected $keyLengthValidator;
4040

4141
/**
4242
* @var \Magento\Integration\Helper\Oauth\Data
@@ -46,7 +46,7 @@ class Consumer extends \Magento\Framework\Model\AbstractModel implements Consume
4646
/**
4747
* @param \Magento\Framework\Model\Context $context
4848
* @param \Magento\Framework\Registry $registry
49-
* @param \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLengthFactory $keyLengthFactory
49+
* @param \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength $keyLength
5050
* @param \Magento\Framework\Url\Validator $urlValidator
5151
* @param \Magento\Integration\Helper\Oauth\Data $dataHelper
5252
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
@@ -56,15 +56,15 @@ class Consumer extends \Magento\Framework\Model\AbstractModel implements Consume
5656
public function __construct(
5757
\Magento\Framework\Model\Context $context,
5858
\Magento\Framework\Registry $registry,
59-
\Magento\Integration\Model\Oauth\Consumer\Validator\KeyLengthFactory $keyLengthFactory,
59+
\Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength $keyLength,
6060
\Magento\Framework\Url\Validator $urlValidator,
6161
\Magento\Integration\Helper\Oauth\Data $dataHelper,
6262
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
6363
\Magento\Framework\Data\Collection\Db $resourceCollection = null,
6464
array $data = []
6565
) {
66-
$this->_keyLengthFactory = $keyLengthFactory;
67-
$this->_urlValidator = $urlValidator;
66+
$this->keyLengthValidator = $keyLength;
67+
$this->urlValidator = $urlValidator;
6868
$this->dataHelper = $dataHelper;
6969
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
7070
}
@@ -87,9 +87,7 @@ protected function _construct()
8787
*/
8888
public function beforeSave()
8989
{
90-
if (!$this->getId()) {
91-
$this->setUpdatedAt(time());
92-
}
90+
$this->setUpdatedAt(time());
9391
$this->validate();
9492
parent::beforeSave();
9593
return $this;
@@ -104,29 +102,27 @@ public function validate()
104102
$this->setCallbackUrl(trim($this->getCallbackUrl()));
105103
$this->setRejectedCallbackUrl(trim($this->getRejectedCallbackUrl()));
106104

107-
if ($this->getCallbackUrl() && !$this->_urlValidator->isValid($this->getCallbackUrl())) {
105+
if ($this->getCallbackUrl() && !$this->urlValidator->isValid($this->getCallbackUrl())) {
108106
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Callback URL'));
109107
}
110-
if ($this->getRejectedCallbackUrl() && !$this->_urlValidator->isValid($this->getRejectedCallbackUrl())) {
108+
if ($this->getRejectedCallbackUrl() && !$this->urlValidator->isValid($this->getRejectedCallbackUrl())) {
111109
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid Rejected Callback URL'));
112110
}
113111
}
114112

115-
/** @var $validatorLength \Magento\Integration\Model\Oauth\Consumer\Validator\KeyLength */
116-
$validatorLength = $this->_keyLengthFactory->create(
117-
['options' => ['length' => \Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY]]
118-
);
119-
120-
$validatorLength->setName('Consumer Key');
121-
if (!$validatorLength->isValid($this->getKey())) {
122-
$messages = $validatorLength->getMessages();
113+
$this->keyLengthValidator
114+
->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_KEY)
115+
->setName('Consumer Key');
116+
if (!$this->keyLengthValidator->isValid($this->getKey())) {
117+
$messages = $this->keyLengthValidator->getMessages();
123118
throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages)));
124119
}
125120

126-
$validatorLength->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET);
127-
$validatorLength->setName('Consumer Secret');
128-
if (!$validatorLength->isValid($this->getSecret())) {
129-
$messages = $validatorLength->getMessages();
121+
$this->keyLengthValidator
122+
->setLength(\Magento\Framework\Oauth\Helper\Oauth::LENGTH_CONSUMER_SECRET)
123+
->setName('Consumer Secret');
124+
if (!$this->keyLengthValidator->isValid($this->getSecret())) {
125+
$messages = $this->keyLengthValidator->getMessages();
130126
throw new \Magento\Framework\Exception\LocalizedException(__(array_shift($messages)));
131127
}
132128
return true;

0 commit comments

Comments
 (0)