BooleanTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Model\Attribute\Backend;
  7. class BooleanTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Customer\Model\Attribute\Backend\Data\Boolean
  11. */
  12. protected $model;
  13. protected function setUp()
  14. {
  15. $this->model = new \Magento\Customer\Model\Attribute\Backend\Data\Boolean();
  16. }
  17. /**
  18. * @param mixed $value
  19. * @param mixed $defaultValue
  20. * @param string|mixed $result
  21. *
  22. * @dataProvider beforeSaveDataProvider
  23. */
  24. public function testBeforeSave($value, $defaultValue, $result)
  25. {
  26. $attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
  27. ->setMethods(['getName', 'getDefaultValue'])
  28. ->disableOriginalConstructor()
  29. ->getMockForAbstractClass();
  30. $customerMock = $this->getMockBuilder(\Magento\Customer\Model\Customer::class)
  31. ->disableOriginalConstructor()
  32. ->getMock();
  33. $this->model->setAttribute($attributeMock);
  34. $attributeMock->expects($this->once())
  35. ->method('getName')
  36. ->willReturn('attribute_name');
  37. $attributeMock->expects($this->any())
  38. ->method('getDefaultValue')
  39. ->willReturn($defaultValue);
  40. $customerMock->expects($this->once())
  41. ->method('getData')
  42. ->with('attribute_name', null)
  43. ->willReturn($value);
  44. $customerMock->expects($this->once())
  45. ->method('setData')
  46. ->with('attribute_name', $result)
  47. ->willReturnSelf();
  48. $this->assertEquals($this->model, $this->model->beforeSave($customerMock));
  49. }
  50. /**
  51. * @return array
  52. */
  53. public function beforeSaveDataProvider()
  54. {
  55. return [
  56. [null, null, '0'],
  57. [null, '', '0'],
  58. [null, '0', '0'],
  59. [null, '1', '1'],
  60. [null, 'Yes', '1'],
  61. ['', null, '0'],
  62. ['0', null, '0'],
  63. ['0', '1', '0'],
  64. ['1', null, '1'],
  65. ['1', 'Yes', '1'],
  66. ['Yes', null, '1'],
  67. ['Yes', 'Yes', '1'],
  68. ];
  69. }
  70. }