Skip to content

Commit

Permalink
Merge pull request magento#343 from magento-ogre/PR_Branch
Browse files Browse the repository at this point in the history
[Ogre's] Synonym Management, Public PRs and Bugs
  • Loading branch information
mazhalai committed Jan 29, 2016
2 parents 01141f4 + 08b9b15 commit d1847bd
Show file tree
Hide file tree
Showing 67 changed files with 3,308 additions and 161 deletions.
34 changes: 27 additions & 7 deletions app/code/Magento/Backend/Model/Locale/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,30 @@ class Manager
* @var \Magento\Framework\TranslateInterface
*/
protected $_translator;

/**
* @var \Magento\Backend\App\ConfigInterface
*/
protected $_backendConfig;

/**
* Constructor
*
* @param \Magento\Backend\Model\Session $session
* @param \Magento\Backend\Model\Auth\Session $authSession
* @param \Magento\Framework\TranslateInterface $translator
* @param \Magento\Backend\App\ConfigInterface $backendConfig
*/
public function __construct(
\Magento\Backend\Model\Session $session,
\Magento\Backend\Model\Auth\Session $authSession,
\Magento\Framework\TranslateInterface $translator
\Magento\Framework\TranslateInterface $translator,
\Magento\Backend\App\ConfigInterface $backendConfig
) {
$this->_session = $session;
$this->_authSession = $authSession;
$this->_translator = $translator;
$this->_backendConfig = $backendConfig;
}

/**
Expand All @@ -53,28 +61,40 @@ public function __construct(
public function switchBackendInterfaceLocale($localeCode)
{
$this->_session->setSessionLocale(null);

$this->_authSession->getUser()->setInterfaceLocale($localeCode);

$this->_translator->setLocale($localeCode)->loadData(null, true);

return $this;
}

/**
* Get general interface locale
*
* @return string
*/
public function getGeneralLocale()
{
return $this->_backendConfig->getValue('general/locale/code');
}

/**
* Get user interface locale stored in session data
*
* @return string
*/
public function getUserInterfaceLocale()
{
$interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE;

$userData = $this->_authSession->getUser();
$interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE;

if ($userData && $userData->getInterfaceLocale()) {
$interfaceLocale = $userData->getInterfaceLocale();
} elseif ($this->getGeneralLocale()) {
$interfaceLocale = $this->getGeneralLocale();
}

return $interfaceLocale;
}
}
29 changes: 25 additions & 4 deletions app/code/Magento/Backend/Test/Unit/Model/Locale/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
protected $_model;

/**
* @var \Magento\Framework\TranslateInterface
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\TranslateInterface
*/
protected $_translator;

Expand All @@ -25,9 +25,14 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
protected $_session;

/**
* @var \Magento\Backend\Model\Auth\Session
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Auth\Session
*/
protected $_authSession;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\App\ConfigInterface
*/
protected $_backendConfig;

protected function setUp()
{
Expand All @@ -40,7 +45,9 @@ protected function setUp()
'',
false
);


$this->_backendConfig = $this->getMockForAbstractClass('Magento\Backend\App\ConfigInterface', [], '', false);

$userMock = new \Magento\Framework\DataObject();

$this->_authSession->expects($this->any())->method('getUser')->will($this->returnValue($userMock));
Expand All @@ -54,7 +61,8 @@ protected function setUp()
$this->_model = new \Magento\Backend\Model\Locale\Manager(
$this->_session,
$this->_authSession,
$this->_translator
$this->_translator,
$this->_backendConfig
);
}

Expand Down Expand Up @@ -102,4 +110,17 @@ public function testGetUserInterfaceLocale()

$this->assertEquals($locale, 'de_DE');
}

/**
* @covers \Magento\Backend\Model\Locale\Manager::getUserInterfaceLocale
*/
public function testGetUserInterfaceGeneralLocale()
{
$this->_backendConfig->expects($this->any())
->method('getValue')
->with('general/locale/code')
->willReturn('test_locale');
$locale = $this->_model->getUserInterfaceLocale();
$this->assertEquals($locale, 'test_locale');
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Cms/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<route url="/V1/cmsPage/:pageId" method="GET">
<service class="Magento\Cms\Api\PageRepositoryInterface" method="getById"/>
<resources>
<resource ref="Magento_Cms::page"/>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/cmsPage/search" method="GET">
Expand Down Expand Up @@ -42,7 +42,7 @@
<route url="/V1/cmsBlock/:blockId" method="GET">
<service class="Magento\Cms\Api\BlockRepositoryInterface" method="getById"/>
<resources>
<resource ref="Magento_Cms::block"/>
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/cmsBlock/search" method="GET">
Expand Down
72 changes: 72 additions & 0 deletions app/code/Magento/Search/Api/Data/SynonymGroupInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Search\Api\Data;

/**
* @api
*/
interface SynonymGroupInterface
{
/**
* Gets group id
*
* @return int
*/
public function getGroupId();

/**
* Sets group id
*
* @param int $groupId
* @return $this
*/
public function setGroupId($groupId);

/**
* Gets synonym group
*
* @return string
*/
public function getSynonymGroup();

/**
* Sets synonym group
*
* @param string $synonymGroup
* @return $this
*/
public function setSynonymGroup($synonymGroup);

/**
* Gets store id
*
* @return int
*/
public function getStoreId();

/**
* Sets store id
*
* @param int $id
* @return $this
*/
public function setStoreId($id);

/**
* Gets website id
*
* @return int
*/
public function getWebsiteId();

/**
* Sets website id
*
* @param int $id
* @return $this
*/
public function setWebsiteId($id);
}
2 changes: 1 addition & 1 deletion app/code/Magento/Search/Api/SynonymAnalyzerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface SynonymAnalyzerInterface
/**
* Get synonyms for specified phrase
*
* For phrase: "Elizabeth is the English queen" correct output is an array of arrays containing synonyms for each
* For phrase: "Elizabeth is the English queen" example output is an array of arrays containing synonyms for each
* word in the phrase:
*
* [
Expand Down
28 changes: 28 additions & 0 deletions app/code/Magento/Search/Api/SynonymGroupRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Search\Api;

/**
* @api
*/
interface SynonymGroupRepositoryInterface
{
/**
* Save synonym group data
*
* @param \Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup
* @return \Magento\Search\Api\Data\SynonymGroupInterface saved attribute set
*/
public function save(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup);

/**
* Remove given synonym group data
*
* @param \Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup
* @return bool
*/
public function delete(\Magento\Search\Api\Data\SynonymGroupInterface $synonymGroup);
}
25 changes: 25 additions & 0 deletions app/code/Magento/Search/Block/Adminhtml/Synonyms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Search\Block\Adminhtml;


/**
* Adminhtml synonym group content block
*/
class Synonyms extends \Magento\Backend\Block\Widget\Grid\Container
{
/**
* @return void
*/
protected function _construct()
{
$this->_blockGroup = 'Magento_Search';
$this->_controller = 'adminhtml_synonyms';
$this->_headerText = __('Search Synonyms');
$this->_addButtonLabel = __('New Synonym Group');
parent::_construct();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Search\Block\Adminhtml\Synonyms\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Class BackButton
*/
class BackButton extends GenericButton implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
return [
'label' => __('Back'),
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
'class' => 'back',
'sort_order' => 10
];
}

/**
* Get URL for back (reset) button
*
* @return string
*/
public function getBackUrl()
{
return $this->getUrl('*/*/');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Search\Block\Adminhtml\Synonyms\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

/**
* Class DeleteButton
*/
class DeleteButton extends GenericButton implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
$data = [];
if ($this->getGroupId()) {
$data = [
'label' => __('Delete Synonym Group'),
'class' => 'delete',
'on_click' => 'deleteConfirm(\''
. __('Are you sure you want to delete this synonym group?')
. '\', \'' . $this->getDeleteUrl() . '\')',
'sort_order' => 20,
];
}
return $data;
}

/**
* @return string
*/
public function getDeleteUrl()
{
return $this->getUrl('*/*/delete', ['group_id' => $this->getGroupId()]);
}
}
Loading

0 comments on commit d1847bd

Please sign in to comment.