123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- /**
- * Test class for \Magento\Framework\View\Page\Config
- */
- namespace Magento\Framework\View\Test\Unit\Page;
- use Magento\Store\Model\ScopeInterface;
- class TitleTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Framework\View\Page\Title
- */
- protected $title;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $scopeConfigMock;
- /**
- * @return void
- */
- protected function setUp()
- {
- $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $this->title = $objectManagerHelper->getObject(
- \Magento\Framework\View\Page\Title::class,
- ['scopeConfig' => $this->scopeConfigMock]
- );
- }
- /**
- * @return void
- */
- public function testSet()
- {
- $value = 'test_value';
- $this->title->set($value);
- $this->assertEquals($value, $this->title->get());
- }
- /**
- * @return void
- */
- public function testUnset()
- {
- $value = 'test';
- $this->title->set($value);
- $this->assertEquals($value, $this->title->get());
- $this->title->unsetValue();
- $this->assertEmpty($this->title->get());
- }
- /**
- * @return void
- */
- public function testGet()
- {
- $value = 'test';
- $prefix = 'prefix';
- $suffix = 'suffix';
- $expected = 'prefix test suffix';
- $this->scopeConfigMock->expects($this->any())
- ->method('getValue')
- ->willReturnMap(
- [
- ['design/head/title_prefix', ScopeInterface::SCOPE_STORE, null, $prefix],
- ['design/head/title_suffix', ScopeInterface::SCOPE_STORE, null, $suffix],
- ]
- );
- $this->title->set($value);
- $this->assertEquals($expected, $this->title->get());
- }
- /**
- * @return void
- */
- public function testGetShort()
- {
- $value = 'some_title';
- $this->title->set($value);
- $this->title->prepend($value);
- $this->title->append($value);
- $this->assertEquals($value, $this->title->getShort());
- }
- /**
- * @return void
- */
- public function testGetShortWithSuffixAndPrefix()
- {
- $value = 'some_title';
- $prefix = 'prefix';
- $suffix = 'suffix';
- $expected = $prefix . ' ' . $value . ' ' . $suffix;
- $this->title->set($value);
- $this->scopeConfigMock->expects($this->any())
- ->method('getValue')
- ->willReturnMap(
- [
- ['design/head/title_prefix', ScopeInterface::SCOPE_STORE, null, $prefix],
- ['design/head/title_suffix', ScopeInterface::SCOPE_STORE, null, $suffix],
- ]
- );
- $this->assertEquals($expected, $this->title->getShort());
- }
- /**
- * @return void
- */
- public function testGetShortHeading()
- {
- $value = 'some_title';
- $this->title->set($value);
- $this->scopeConfigMock->expects($this->never())
- ->method('getValue');
- $this->assertEquals($value, $this->title->getShortHeading());
- }
- /**
- * @return void
- */
- public function testGetDefault()
- {
- $defaultTitle = 'default title';
- $prefix = 'prefix';
- $suffix = 'suffix';
- $expected = 'prefix default title suffix';
- $this->scopeConfigMock->expects($this->any())
- ->method('getValue')
- ->willReturnMap(
- [
- ['design/head/title_prefix', ScopeInterface::SCOPE_STORE, null, $prefix],
- ['design/head/title_suffix', ScopeInterface::SCOPE_STORE, null, $suffix],
- ['design/head/default_title', ScopeInterface::SCOPE_STORE, null, $defaultTitle],
- ]
- );
- $this->assertEquals($expected, $this->title->getDefault());
- }
- /**
- * @return void
- */
- public function testAppendPrepend()
- {
- $value = 'title';
- $prepend = 'prepend_title';
- $append = 'append_title';
- $expected = 'prepend_title / title / append_title';
- $this->title->set($value);
- $this->title->prepend($prepend);
- $this->title->append($append);
- $this->assertEquals($expected, $this->title->get());
- }
- }
|