Source of file AddressBookCheckoutComponentTest.php
Size: 4,345 Bytes - Last Modified: 2021-12-24T06:35:03+00:00
/var/www/docs.ssmods.com/process/src/tests/php/Checkout/Component/AddressBookCheckoutComponentTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 | <?php namespace SilverShop\Tests\Checkout\Component; use SilverShop\Checkout\CheckoutComponentConfig; use SilverShop\Checkout\CheckoutConfig; use SilverShop\Checkout\Component\AddressBookBilling; use SilverShop\Model\Address; use SilverShop\Model\Order; use SilverShop\Tests\ShopTest; use SilverStripe\Security\Member; use SilverStripe\ORM\ValidationException; use SilverStripe\Dev\SapphireTest; use SilverStripe\Security\Security; class AddressBookCheckoutComponentTest extends SapphireTest { // Component namespace const COMPONENT_NS = 'SilverShop-Checkout-Component-AddressBookBilling'; protected static $fixture_file = array( '../../Fixtures/Orders.yml', '../../Fixtures/ShopMembers.yml', ); /** * @var Order $cart */ protected $cart; /** * @var Member $member */ protected $member; /** * @var Address $address1 */ protected $address1; /** * @var Address $address2 */ protected $address2; /** * @var CheckoutComponentConfig $config */ protected $config; protected $fixtureNewAddress = array( self::COMPONENT_NS . '_BillingAddressID' => 'newaddress', self::COMPONENT_NS . '_Country' => 'US', self::COMPONENT_NS . '_Address' => '123 Test St', self::COMPONENT_NS . '_AddressLine2' => 'Apt 4', self::COMPONENT_NS . '_City' => 'Siloam Springs', self::COMPONENT_NS . '_State' => 'AR', self::COMPONENT_NS . '_PostalCode' => '72761', self::COMPONENT_NS . '_Phone' => '11231231234', ); public function setUp() { ShopTest::setConfiguration(); CheckoutConfig::config()->membership_required = false; parent::setUp(); $this->member = $this->objFromFixture(Member::class, "jeremyperemy"); $this->cart = $this->objFromFixture(Order::class, "cart1"); $this->address1 = $this->objFromFixture(Address::class, "address1"); $this->address2 = $this->objFromFixture(Address::class, "address2"); $this->config = new CheckoutComponentConfig($this->cart, true); $this->config->addComponent(new AddressBookBilling()); $this->address1->MemberID = $this->member->ID; $this->address1->write(); } public function testCreateNewAddress() { $this->assertTrue( $this->config->validateData($this->fixtureNewAddress) ); } public function testIncompleteNewAddress() { $this->expectException(ValidationException::class); $data = $this->fixtureNewAddress; $data[self::COMPONENT_NS . '_Country'] = ''; $this->config->validateData($data); } public function testUseExistingAddress() { Security::setCurrentUser($this->member); $this->assertTrue( $this->config->validateData( array( self::COMPONENT_NS . '_BillingAddressID' => $this->address1->ID, ) ) ); } public function testShouldRejectExistingIfNotLoggedIn() { $this->expectException(ValidationException::class); $this->assertTrue( $this->config->validateData( array( self::COMPONENT_NS . '_BillingAddressID' => $this->address1->ID, ) ) ); } public function testShouldRejectExistingIfNotOwnedByMember() { $this->expectException(ValidationException::class); Security::setCurrentUser($this->member); $this->address1->MemberID = 0; $this->address1->write(); $this->assertTrue( $this->config->validateData( array( self::COMPONENT_NS . '_BillingAddressID' => $this->address1->ID, ) ) ); } public function testShouldNotCreateBlankAddresses() { $beforeCount = Address::get()->count(); $this->config->setData( array( self::COMPONENT_NS . '_BillingAddressID' => $this->address1->ID, ) ); $this->assertEquals($this->cart->BillingAddressID, $this->address1->ID); $this->assertEquals($beforeCount, Address::get()->count()); } } |