CustomerTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Model\TaxClass\Source;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. class CustomerTest extends \PHPUnit\Framework\TestCase
  9. {
  10. public function testGetAllOptions()
  11. {
  12. /** @var \Magento\Tax\Model\ResourceModel\TaxClass\Collection $collection */
  13. $collection = Bootstrap::getObjectManager()->get(\Magento\Tax\Model\ResourceModel\TaxClass\Collection::class);
  14. $expectedResult = [];
  15. /** @var \Magento\Tax\Model\ClassModel $taxClass */
  16. foreach ($collection as $taxClass) {
  17. if ($taxClass->getClassType() == \Magento\Tax\Api\TaxClassManagementInterface::TYPE_CUSTOMER) {
  18. $expectedResult[] = ['value' => $taxClass->getId(), 'label' => $taxClass->getClassName()];
  19. }
  20. }
  21. if (empty($expectedResult)) {
  22. $this->fail('Preconditions failed: At least one tax class should be available.');
  23. }
  24. /** @var \Magento\Tax\Model\TaxClass\Source\Product $source */
  25. $source = Bootstrap::getObjectManager()->get(\Magento\Tax\Model\TaxClass\Source\Customer::class);
  26. $this->assertEquals(
  27. $expectedResult,
  28. $source->getAllOptions(),
  29. 'Tax Class options are invalid.'
  30. );
  31. }
  32. public function testGetAllOptionsWithDefaultValues()
  33. {
  34. /** @var \Magento\Tax\Model\ResourceModel\TaxClass\Collection $collection */
  35. $collection = Bootstrap::getObjectManager()->get(\Magento\Tax\Model\ResourceModel\TaxClass\Collection::class);
  36. $expectedResult = [];
  37. /** @var \Magento\Tax\Model\ClassModel $taxClass */
  38. foreach ($collection as $taxClass) {
  39. if ($taxClass->getClassType() == \Magento\Tax\Api\TaxClassManagementInterface::TYPE_CUSTOMER) {
  40. $expectedResult[] = ['value' => $taxClass->getId(), 'label' => $taxClass->getClassName()];
  41. }
  42. }
  43. if (empty($expectedResult)) {
  44. $this->fail('Preconditions failed: At least one tax class should be available.');
  45. }
  46. /** @var \Magento\Tax\Model\TaxClass\Source\Product $source */
  47. $source = Bootstrap::getObjectManager()->get(\Magento\Tax\Model\TaxClass\Source\Customer::class);
  48. $this->assertEquals(
  49. $expectedResult,
  50. $source->getAllOptions(true),
  51. 'Tax Class options are invalid.'
  52. );
  53. }
  54. }