Skip to content

Commit fd51f54

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #722 from magento-tango/mb_bugs_pr
[Tango] Merchant Beta Bug Fixes
2 parents 6ea96b8 + 3189fe0 commit fd51f54

File tree

5 files changed

+208
-8
lines changed

5 files changed

+208
-8
lines changed

app/code/Magento/Theme/Block/Html/Title.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ public function getPageTitle()
3737
return $this->pageConfig->getTitle()->getShort();
3838
}
3939

40+
/**
41+
* Provide own page content heading
42+
*
43+
* @return string
44+
*/
45+
public function getPageHeading()
46+
{
47+
if (!empty($this->pageTitle)) {
48+
return $this->pageTitle;
49+
}
50+
return $this->pageConfig->getTitle()->getShortHeading();
51+
}
52+
4053
/**
4154
* Set own page title
4255
*
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Test\Unit\Block\Html;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
10+
class TitleTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var ObjectManagerHelper
14+
*/
15+
protected $objectManagerHelper;
16+
17+
/**
18+
* @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
protected $pageConfigMock;
21+
22+
/**
23+
* @var \Magento\Framework\View\Page\Title|\PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
protected $pageTitleMock;
26+
27+
/**
28+
* @var \Magento\Theme\Block\Html\Title
29+
*/
30+
protected $htmlTitle;
31+
32+
/**
33+
* @return void
34+
*/
35+
protected function setUp()
36+
{
37+
$this->objectManagerHelper = new ObjectManagerHelper($this);
38+
$this->pageConfigMock = $this->getMock('Magento\Framework\View\Page\Config', [], [], '', false);
39+
$this->pageTitleMock = $this->getMock('Magento\Framework\View\Page\Title', [], [], '', false);
40+
41+
$context = $this->objectManagerHelper->getObject(
42+
'Magento\Framework\View\Element\Template\Context',
43+
['pageConfig' => $this->pageConfigMock]
44+
);
45+
46+
$this->htmlTitle = $this->objectManagerHelper->getObject(
47+
'Magento\Theme\Block\Html\Title',
48+
['context' => $context]
49+
);
50+
}
51+
52+
/**
53+
* @return void
54+
*/
55+
public function testGetPageTitleWithSetPageTitle()
56+
{
57+
$title = 'some title';
58+
59+
$this->htmlTitle->setPageTitle($title);
60+
$this->pageConfigMock->expects($this->never())
61+
->method('getTitle');
62+
63+
$this->assertEquals($title, $this->htmlTitle->getPageTitle());
64+
}
65+
66+
/**
67+
* @return void
68+
*/
69+
public function testGetPageTitle()
70+
{
71+
$title = 'some title';
72+
73+
$this->pageTitleMock->expects($this->once())
74+
->method('getShort')
75+
->willReturn($title);
76+
$this->pageConfigMock->expects($this->once())
77+
->method('getTitle')
78+
->willReturn($this->pageTitleMock);
79+
80+
$this->assertEquals($title, $this->htmlTitle->getPageTitle());
81+
}
82+
83+
/**
84+
* @return void
85+
*/
86+
public function testGetPageHeadingWithSetPageTitle()
87+
{
88+
$title = 'some title';
89+
90+
$this->htmlTitle->setPageTitle($title);
91+
$this->pageConfigMock->expects($this->never())
92+
->method('getTitle');
93+
94+
$this->assertEquals($title, $this->htmlTitle->getPageHeading());
95+
}
96+
97+
/**
98+
* @return void
99+
*/
100+
public function testGetPageHeading()
101+
{
102+
$title = 'some title';
103+
104+
$this->pageTitleMock->expects($this->once())
105+
->method('getShortHeading')
106+
->willReturn($title);
107+
$this->pageConfigMock->expects($this->once())
108+
->method('getTitle')
109+
->willReturn($this->pageTitleMock);
110+
111+
$this->assertEquals($title, $this->htmlTitle->getPageHeading());
112+
}
113+
}

app/code/Magento/Theme/view/frontend/templates/html/title.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
*/
1212
$cssClass = $block->getCssClass() ? ' ' . $block->getCssClass() : '';
1313
$title = '';
14-
if (trim($block->getPageTitle())) {
14+
if (trim($block->getPageHeading())) {
1515
$title = '<span class="base" data-ui-id="page-title-wrapper" ' . $block->getAddBaseAttribute() . '>'
16-
. $block->escapeHtml($block->getPageTitle()) . '</span>';
16+
. $block->escapeHtml($block->getPageHeading()) . '</span>';
1717
}
1818
?>
1919
<?php if ($title): ?>

lib/internal/Magento/Framework/View/Page/Title.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,27 @@ public function getShort()
7777
}
7878

7979
/**
80+
* Same as getShort(), but return title without prefix and suffix
81+
*
82+
* @return mixed
83+
*/
84+
public function getShortHeading()
85+
{
86+
$title = $this->build(false);
87+
return reset($title);
88+
}
89+
90+
/**
91+
* @param bool $withConfigValues
8092
* @return array
8193
*/
82-
protected function build()
94+
protected function build($withConfigValues = true)
8395
{
84-
return array_merge($this->prependedValues, [$this->addConfigValues($this->textValue)], $this->appendedValues);
96+
return array_merge(
97+
$this->prependedValues,
98+
[$withConfigValues ? $this->addConfigValues($this->textValue) : $this->textValue],
99+
$this->appendedValues
100+
);
85101
}
86102

87103
/**

lib/internal/Magento/Framework/View/Test/Unit/Page/TitleTest.php

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class TitleTest extends \PHPUnit_Framework_TestCase
2323
*/
2424
protected $scopeConfigMock;
2525

26+
/**
27+
* @return void
28+
*/
2629
public function setUp()
2730
{
2831
$this->scopeConfigMock = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
@@ -36,13 +39,19 @@ public function setUp()
3639
);
3740
}
3841

42+
/**
43+
* @return void
44+
*/
3945
public function testSet()
4046
{
4147
$value = 'test_value';
4248
$this->title->set($value);
4349
$this->assertEquals($value, $this->title->get());
4450
}
4551

52+
/**
53+
* @return void
54+
*/
4655
public function testUnset()
4756
{
4857
$value = 'test';
@@ -52,6 +61,9 @@ public function testUnset()
5261
$this->assertEmpty($this->title->get());
5362
}
5463

64+
/**
65+
* @return void
66+
*/
5567
public function testGet()
5668
{
5769
$value = 'test';
@@ -61,16 +73,19 @@ public function testGet()
6173

6274
$this->scopeConfigMock->expects($this->any())
6375
->method('getValue')
64-
->will($this->returnValueMap(
76+
->willReturnMap(
6577
[
6678
['design/head/title_prefix', ScopeInterface::SCOPE_STORE, null, $prefix],
6779
['design/head/title_suffix', ScopeInterface::SCOPE_STORE, null, $suffix],
6880
]
69-
));
81+
);
7082
$this->title->set($value);
7183
$this->assertEquals($expected, $this->title->get());
7284
}
7385

86+
/**
87+
* @return void
88+
*/
7489
public function testGetShort()
7590
{
7691
$value = 'some_title';
@@ -81,6 +96,46 @@ public function testGetShort()
8196
$this->assertEquals($value, $this->title->getShort());
8297
}
8398

99+
/**
100+
* @return void
101+
*/
102+
public function testGetShortWithSuffixAndPrefix()
103+
{
104+
$value = 'some_title';
105+
$prefix = 'prefix';
106+
$suffix = 'suffix';
107+
$expected = $prefix . ' ' . $value . ' ' . $suffix;
108+
$this->title->set($value);
109+
110+
$this->scopeConfigMock->expects($this->any())
111+
->method('getValue')
112+
->willReturnMap(
113+
[
114+
['design/head/title_prefix', ScopeInterface::SCOPE_STORE, null, $prefix],
115+
['design/head/title_suffix', ScopeInterface::SCOPE_STORE, null, $suffix],
116+
]
117+
);
118+
119+
$this->assertEquals($expected, $this->title->getShort());
120+
}
121+
122+
/**
123+
* @return void
124+
*/
125+
public function testGetShortHeading()
126+
{
127+
$value = 'some_title';
128+
$this->title->set($value);
129+
130+
$this->scopeConfigMock->expects($this->never())
131+
->method('getValue');
132+
133+
$this->assertEquals($value, $this->title->getShortHeading());
134+
}
135+
136+
/**
137+
* @return void
138+
*/
84139
public function testGetDefault()
85140
{
86141
$defaultTitle = 'default title';
@@ -90,16 +145,19 @@ public function testGetDefault()
90145

91146
$this->scopeConfigMock->expects($this->any())
92147
->method('getValue')
93-
->will($this->returnValueMap(
148+
->willReturnMap(
94149
[
95150
['design/head/title_prefix', ScopeInterface::SCOPE_STORE, null, $prefix],
96151
['design/head/title_suffix', ScopeInterface::SCOPE_STORE, null, $suffix],
97152
['design/head/default_title', ScopeInterface::SCOPE_STORE, null, $defaultTitle],
98153
]
99-
));
154+
);
100155
$this->assertEquals($expected, $this->title->getDefault());
101156
}
102157

158+
/**
159+
* @return void
160+
*/
103161
public function testAppendPrepend()
104162
{
105163
$value = 'title';

0 commit comments

Comments
 (0)