|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * Tests for \Magento\Framework\Data\Form\Field\Regexceptions |
| 9 | + */ |
| 10 | +namespace Magento\Config\Test\Unit\Block\System\Config\Form\Field; |
| 11 | + |
| 12 | +class RegexceptionsTest extends \PHPUnit_Framework_TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var array |
| 16 | + */ |
| 17 | + protected $cellParameters; |
| 18 | + |
| 19 | + /** |
| 20 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 21 | + */ |
| 22 | + protected $labelFactoryMock; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 26 | + */ |
| 27 | + protected $labelMock; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 31 | + */ |
| 32 | + protected $elementFactoryMock; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 36 | + */ |
| 37 | + protected $elementMock; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var \Magento\Config\Block\System\Config\Form\Field\Regexceptions |
| 41 | + */ |
| 42 | + protected $object; |
| 43 | + |
| 44 | + protected function setUp() |
| 45 | + { |
| 46 | + $this->cellParameters = [ |
| 47 | + 'label' => 'testLabel', |
| 48 | + 'size' => 'testSize', |
| 49 | + 'style' => 'testStyle', |
| 50 | + 'class' => 'testClass', |
| 51 | + ]; |
| 52 | + |
| 53 | + $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 54 | + |
| 55 | + $this->labelFactoryMock = $this->getMock('Magento\Framework\View\Design\Theme\LabelFactory', [], [], '', false); |
| 56 | + $this->labelMock = $this->getMock('Magento\Framework\View\Design\Theme\Label', [], [], '', false); |
| 57 | + |
| 58 | + $this->elementFactoryMock = $this->getMock('Magento\Framework\Data\Form\Element\Factory', [], [], '', false); |
| 59 | + $this->elementMock = $this->getMock( |
| 60 | + 'Magento\Framework\Data\Form\Element\AbstractElement', |
| 61 | + ['setForm', 'setName', 'setHtmlId', 'setValues', 'getName', 'getHtmlId', 'getValues', 'getElementHtml'], |
| 62 | + [], |
| 63 | + '', |
| 64 | + false |
| 65 | + ); |
| 66 | + $data = [ |
| 67 | + 'elementFactory' => $this->elementFactoryMock, |
| 68 | + 'labelFactory' => $this->labelFactoryMock, |
| 69 | + 'data' => [ |
| 70 | + 'element' => $this->elementMock |
| 71 | + ], |
| 72 | + ]; |
| 73 | + $this->object = $helper->getObject('Magento\Config\Block\System\Config\Form\Field\Regexceptions', $data); |
| 74 | + } |
| 75 | + |
| 76 | + public function testRenderCellTemplateValueColumn() |
| 77 | + { |
| 78 | + $columnName = 'value'; |
| 79 | + $expectedResult = 'testValueElementHtml'; |
| 80 | + |
| 81 | + $this->elementFactoryMock->expects($this->once())->method('create')->willReturn($this->elementMock); |
| 82 | + $this->elementMock->expects($this->once())->method('setForm')->willReturn($this->elementMock); |
| 83 | + $this->elementMock->expects($this->once())->method('setName')->willReturn($this->elementMock); |
| 84 | + $this->elementMock->expects($this->once())->method('setHtmlId')->willReturn($this->elementMock); |
| 85 | + $this->elementMock->expects($this->once())->method('setValues')->willReturn($this->elementMock); |
| 86 | + $this->elementMock->expects($this->once())->method('getElementHtml')->willReturn($expectedResult); |
| 87 | + |
| 88 | + $this->labelFactoryMock->expects($this->once())->method('create')->willReturn($this->labelMock); |
| 89 | + $this->labelMock->expects($this->once())->method('getLabelsCollection')->willReturn([]); |
| 90 | + |
| 91 | + $this->object->addColumn( |
| 92 | + $columnName, |
| 93 | + $this->cellParameters |
| 94 | + ); |
| 95 | + |
| 96 | + $this->assertEquals( |
| 97 | + $expectedResult, |
| 98 | + $this->object->renderCellTemplate($columnName) |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public function testRenderCellTemplateOtherColumn() |
| 103 | + { |
| 104 | + $columnName = 'testCellName'; |
| 105 | + $expectedResult = '<input type="text" id="<%- _id %>_testCellName" name="[<%- _id %>][testCellName]"' . |
| 106 | + ' value="<%- testCellName %>" size="testSize" class="testClass" style="testStyle"/>'; |
| 107 | + |
| 108 | + $this->object->addColumn( |
| 109 | + $columnName, |
| 110 | + $this->cellParameters |
| 111 | + ); |
| 112 | + |
| 113 | + $this->assertEquals( |
| 114 | + $expectedResult, |
| 115 | + $this->object->renderCellTemplate($columnName) |
| 116 | + ); |
| 117 | + } |
| 118 | + |
| 119 | + public function testRenderCellTemplateWrongColumnName() |
| 120 | + { |
| 121 | + $columnName = 'testCellName'; |
| 122 | + |
| 123 | + $this->object->addColumn( |
| 124 | + $columnName . 'Wrong', |
| 125 | + $this->cellParameters |
| 126 | + ); |
| 127 | + |
| 128 | + $this->setExpectedException('\Exception', 'Wrong column name specified.'); |
| 129 | + |
| 130 | + $this->object->renderCellTemplate($columnName); |
| 131 | + } |
| 132 | +} |
0 commit comments