CheckoutFieldsTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\CustomerData;
  6. use Magento\TestFramework\Helper\Bootstrap;
  7. use Temando\Shipping\Model\Checkout\Schema\CheckoutField;
  8. /**
  9. * Temando Customer Data Checkout Fields Test
  10. *
  11. * @codingStandardsIgnoreFile
  12. *
  13. * @package Temando\Shipping\Test\Integration
  14. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  15. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  16. * @link http://www.temando.com/
  17. */
  18. class CheckoutFieldsTest extends \PHPUnit\Framework\TestCase
  19. {
  20. /**
  21. * @test
  22. * @magentoConfigFixture default/carriers/temando/active 0
  23. * @magentoConfigFixture default/carriers/temando/additional_checkout_fields [{"id":"signature","label":"Signature","fieldType":"checkbox","orderPath":"#/address/type"}]
  24. */
  25. public function sectionDataIsEmptyWhenShippingIsDisabledInCheckout()
  26. {
  27. /** @var CheckoutFields $customerData */
  28. $customerData = Bootstrap::getObjectManager()->create(CheckoutFields::class);
  29. $sectionData = $customerData->getSectionData();
  30. $this->assertArrayHasKey('fields', $sectionData);
  31. $this->assertInternalType('array', $sectionData['fields']);
  32. $this->assertEmpty($sectionData['fields']);
  33. }
  34. /**
  35. * @test
  36. * @magentoConfigFixture default_store carriers/temando/active 1
  37. * @magentoConfigFixture default/carriers/temando/additional_checkout_fields [{"id":"signature","label":"Signature","fieldType":"checkbox","orderPath":"#/address/type"}]
  38. */
  39. public function sectionDataIsNotEmptyWhenShippingIsEnabledInCheckout()
  40. {
  41. /** @var CheckoutFields $customerData */
  42. $customerData = Bootstrap::getObjectManager()->create(CheckoutFields::class);
  43. $sectionData = $customerData->getSectionData();
  44. $this->assertArrayHasKey('fields', $sectionData);
  45. $this->assertInternalType('array', $sectionData['fields']);
  46. $this->assertNotEmpty($sectionData['fields']);
  47. }
  48. /**
  49. * @test
  50. * @magentoConfigFixture default_store carriers/temando/active 1
  51. * @magentoConfigFixture default/carriers/temando/additional_checkout_fields [{"id":"signature","label":"Signature","fieldType":"checkbox","orderPath":"#/address/type","defaultValue": true}]
  52. */
  53. public function checkboxTypeIsPrepared()
  54. {
  55. /** @var CheckoutFields $customerData */
  56. $customerData = Bootstrap::getObjectManager()->create(CheckoutFields::class);
  57. $sectionData = $customerData->getSectionData();
  58. $fields = $sectionData['fields'];
  59. $this->assertInternalType('array', $fields);
  60. $this->assertCount(1, $fields);
  61. /** @var CheckoutField $checkboxField */
  62. $checkboxField = $fields['signature'];
  63. $this->assertEquals('signature', $checkboxField['id']);
  64. $this->assertEquals('Signature', $checkboxField['label']);
  65. $this->assertEquals('checkbox', $checkboxField['type']);
  66. $this->assertEquals('#/address/type', $checkboxField['orderPath']);
  67. $this->assertTrue($checkboxField['defaultValue']);
  68. $this->assertEmpty($checkboxField['options']);
  69. }
  70. /**
  71. * @test
  72. * @magentoConfigFixture default_store carriers/temando/active 1
  73. * @magentoConfigFixture default/carriers/temando/additional_checkout_fields [{"id": "text","label": "Text","orderPath": "#/address/text","fieldType": "inputText","defaultValue": "Default"}]
  74. */
  75. public function textTypeIsPrepared()
  76. {
  77. /** @var CheckoutFields $customerData */
  78. $customerData = Bootstrap::getObjectManager()->create(CheckoutFields::class);
  79. $sectionData = $customerData->getSectionData();
  80. $fields = $sectionData['fields'];
  81. $this->assertInternalType('array', $fields);
  82. $this->assertCount(1, $fields);
  83. /** @var CheckoutField $textField */
  84. $textField = $fields['text'];
  85. $this->assertEquals('text', $textField['id']);
  86. $this->assertEquals('Text', $textField['label']);
  87. $this->assertEquals('text', $textField['type']);
  88. $this->assertEquals('#/address/text', $textField['orderPath']);
  89. $this->assertEquals('Default', $textField['defaultValue']);
  90. $this->assertEmpty($textField['options']);
  91. }
  92. /**
  93. * @test
  94. * @magentoConfigFixture default_store carriers/temando/active 1
  95. * @magentoConfigFixture default/carriers/temando/additional_checkout_fields [{"id": "select","label": "Select","orderPath": "#/address/select","fieldType": "select","defaultValue": "Two","options": [{"name": "One","value": "one"},{"name": "Two","value": "two"}]}]
  96. */
  97. public function selectTypeIsPrepared()
  98. {
  99. /** @var CheckoutFields $customerData */
  100. $customerData = Bootstrap::getObjectManager()->create(CheckoutFields::class);
  101. $sectionData = $customerData->getSectionData();
  102. $fields = $sectionData['fields'];
  103. $this->assertInternalType('array', $fields);
  104. $this->assertCount(1, $fields);
  105. /** @var CheckoutField $selectField */
  106. $selectField = $fields['select'];
  107. $this->assertEquals('select', $selectField['id']);
  108. $this->assertEquals('Select', $selectField['label']);
  109. $this->assertEquals('select', $selectField['type']);
  110. $this->assertEquals('#/address/select', $selectField['orderPath']);
  111. $this->assertEquals('Two', $selectField['defaultValue']);
  112. $this->assertNotEmpty($selectField['options']);
  113. $this->assertInternalType('array', $selectField['options']);
  114. }
  115. }