BooleanTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Test\Unit\Model\Attribute\Data;
  7. class BooleanTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Eav\Model\Attribute\Data\Boolean
  11. */
  12. protected $model;
  13. protected function setUp()
  14. {
  15. $timezoneMock = $this->createMock(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
  16. $loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
  17. $localeResolverMock = $this->createMock(\Magento\Framework\Locale\ResolverInterface::class);
  18. $this->model = new \Magento\Eav\Model\Attribute\Data\Boolean($timezoneMock, $loggerMock, $localeResolverMock);
  19. }
  20. /**
  21. * @covers \Magento\Eav\Model\Attribute\Data\Boolean::_getOptionText
  22. *
  23. * @param string $format
  24. * @param mixed $value
  25. * @param mixed $expectedResult
  26. * @dataProvider getOptionTextDataProvider
  27. */
  28. public function testOutputValue($format, $value, $expectedResult)
  29. {
  30. $entityMock = $this->createMock(\Magento\Framework\Model\AbstractModel::class);
  31. $entityMock->expects($this->once())->method('getData')->will($this->returnValue($value));
  32. $attributeMock = $this->createMock(\Magento\Eav\Model\Attribute::class);
  33. $this->model->setEntity($entityMock);
  34. $this->model->setAttribute($attributeMock);
  35. $this->assertEquals($expectedResult, $this->model->outputValue($format));
  36. }
  37. /**
  38. * @return array
  39. */
  40. public function getOptionTextDataProvider()
  41. {
  42. return [
  43. [
  44. 'format' => \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_TEXT,
  45. 'value' => '0',
  46. 'expectedResult' => 'No',
  47. ],
  48. [
  49. 'format' => \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_TEXT,
  50. 'value' => '1',
  51. 'expectedResult' => 'Yes'
  52. ],
  53. [
  54. 'format' => \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_TEXT,
  55. 'value' => '2',
  56. 'expectedResult' => ''
  57. ],
  58. ];
  59. }
  60. }