silvercommerce /
tax-admin
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SilverCommerce\TaxAdmin\Tests; |
||
| 4 | |||
| 5 | use SilverStripe\i18n\i18n; |
||
| 6 | use SilverStripe\Dev\SapphireTest; |
||
| 7 | use SilverStripe\Security\Security; |
||
| 8 | use SilverStripe\Core\Config\Config; |
||
| 9 | use SilverCommerce\GeoZones\Model\Region; |
||
| 10 | use SilverCommerce\TaxAdmin\Model\TaxCategory; |
||
| 11 | use SilverCommerce\TaxAdmin\Tests\Model\TestProduct; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Test functionality of postage extension |
||
| 15 | * |
||
| 16 | */ |
||
| 17 | class TaxCategoryTest extends SapphireTest |
||
| 18 | { |
||
| 19 | |||
| 20 | protected static $fixture_file = 'TaxData.yml'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Setup test only objects |
||
| 24 | * |
||
| 25 | * @var array |
||
| 26 | */ |
||
| 27 | protected static $extra_dataobjects = [ |
||
| 28 | TestProduct::class |
||
| 29 | ]; |
||
| 30 | |||
| 31 | public function setUp() |
||
| 32 | { |
||
| 33 | parent::setUp(); |
||
| 34 | Config::inst()->set(Region::class, "create_on_build", false); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 35 | |||
| 36 | // Setup default locale |
||
| 37 | i18n::set_locale("en_GB"); |
||
| 38 | $member = Security::getCurrentUser(); |
||
| 39 | $member->Locale = "en_GB"; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Test category valid tax retursn the correct value |
||
| 44 | */ |
||
| 45 | public function testValidTax() |
||
| 46 | { |
||
| 47 | $obj = $this->objFromFixture(TaxCategory::class, "uk"); |
||
| 48 | |||
| 49 | // Test default location (when logged in) |
||
| 50 | $this->assertEquals("VAT", $obj->ValidTax()->Title); |
||
| 51 | |||
| 52 | // Test default location (when not logged in) |
||
| 53 | Security::setCurrentUser(null); |
||
| 54 | $this->assertEquals("VAT", $obj->ValidTax()->Title); |
||
| 55 | |||
| 56 | // Test VAT location |
||
| 57 | $this->assertEquals("VAT", $obj->ValidTax("GB")->Title); |
||
| 58 | |||
| 59 | // Test VAT location for country and region |
||
| 60 | $this->assertEquals("VAT", $obj->ValidTax("GB", "GLS")->Title); |
||
| 61 | |||
| 62 | // Test reduced location |
||
| 63 | $this->assertEquals("reduced", $obj->ValidTax("US")->Title); |
||
| 64 | |||
| 65 | // Test location for valid country and invalid region |
||
| 66 | $this->assertNull($obj->ValidTax("GB", "HDF")); |
||
| 67 | |||
| 68 | // Test unavailable location |
||
| 69 | $this->assertNull($obj->ValidTax("ES")); |
||
| 70 | } |
||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | /** |
||
| 75 | * Test category valid tax returns the correct value when using |
||
| 76 | * the global flag. |
||
| 77 | */ |
||
| 78 | public function testGlobalValidTax() |
||
| 79 | { |
||
| 80 | $obj = $this->objFromFixture(TaxCategory::class, "uk_global"); |
||
| 81 | |||
| 82 | // Test default location (when logged in) |
||
| 83 | $this->assertEquals("VAT Global", $obj->ValidTax()->Title); |
||
| 84 | |||
| 85 | // Test default location (when not logged in) |
||
| 86 | Security::setCurrentUser(null); |
||
| 87 | $this->assertEquals("VAT Global", $obj->ValidTax()->Title); |
||
| 88 | |||
| 89 | // Test VAT location |
||
| 90 | $this->assertEquals("VAT Global", $obj->ValidTax("GB")->Title); |
||
| 91 | |||
| 92 | // Test VAT location for country and region |
||
| 93 | $this->assertEquals("VAT Global", $obj->ValidTax("GB", "GLS")->Title); |
||
| 94 | |||
| 95 | // Test reduced location |
||
| 96 | $this->assertEquals("VAT Global", $obj->ValidTax("US")->Title); |
||
| 97 | |||
| 98 | // Test invalid location |
||
| 99 | $this->assertEquals("VAT Global", $obj->ValidTax("ES")->Title); |
||
| 100 | |||
| 101 | // Test location for valid country and invalid region |
||
| 102 | $this->assertNull($obj->ValidTax("GB", "HDF")); |
||
| 103 | } |
||
| 104 | } |
||
| 105 |