@@ -66,8 +74,8 @@ class=" today_amount (0), %2$s => total_amount, %3$s => i18n formatted due_date.
__( '%1$s today then %2$s on %3$s', 'alma-gateway-for-woocommerce' ),
- ToolsHelper::alma_format_price_from_cents( 0 ),
- ToolsHelper::alma_format_price_from_cents( $alma_step['total_amount'] ),
+ $alma_tools_helper->alma_format_price_from_cents( 0 ),
+ $alma_tools_helper->alma_format_price_from_cents( $alma_step['total_amount'] ),
date_i18n( get_option( 'date_format' ), $alma_step['due_date'] )
)
);
@@ -79,7 +87,7 @@ class="' . esc_html( date_i18n( get_option( 'date_format' ), $alma_step['due_date'] ) ) . '';
}
- echo wp_kses_post( ToolsHelper::alma_format_price_from_cents( $alma_step['total_amount'] ) );
+ echo wp_kses_post( $alma_tools_helper->alma_format_price_from_cents( $alma_step['total_amount'] ) );
}
?>
@@ -91,7 +99,7 @@ class="
-
+
alma_format_price_from_cents( $alma_step['customer_fee'] ) ); ?>
getInstallmentsCount() > 4 ) {
- $alma_cart_helper = new CartHelper();
+ $alma_cart_helper_builder = new CartHelperBuilder();
+ $alma_cart_helper = $alma_cart_helper_builder->get_instance();
+
?>
- get_total_in_cents() ) ); ?>
+ alma_format_price_from_cents( $alma_cart_helper->get_total_in_cents() ) ); ?>
- customerTotalCostAmount ) ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName ?>
+ alma_format_price_from_cents( $alma_eligibility->customerTotalCostAmount ) ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName ?>
getAnnualInterestRate();
@@ -144,7 +154,7 @@ class="
-
+
alma_format_percent_from_bps( $alma_annual_interest_rate ) ); ?>
- getCustomerTotalCostAmount() + $alma_cart_helper->get_total_in_cents() ) ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName ?>
+ alma_format_price_from_cents( $alma_eligibility->getCustomerTotalCostAmount() + $alma_cart_helper->get_total_in_cents() ) ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName ?>
customer_factory_builder = new CustomerFactoryBuilder();
+ }
+
+ public function test_get_instance() {
+ $this->assertInstanceOf(CustomerFactory::class, $this->customer_factory_builder->get_instance());
+ }
+
+ public function test_get_php_factory() {
+ $this->assertInstanceOf(PHPFactory::class, $this->customer_factory_builder->get_php_factory());
+ $this->assertInstanceOf(PHPFactory::class, $this->customer_factory_builder->get_php_factory( new PHPFactory()) );
+ }
+}
+
+
+
diff --git a/src/tests/Builders/Helpers/CartHelperBuilderTest.php b/src/tests/Builders/Helpers/CartHelperBuilderTest.php
new file mode 100644
index 00000000..7b7b60d5
--- /dev/null
+++ b/src/tests/Builders/Helpers/CartHelperBuilderTest.php
@@ -0,0 +1,85 @@
+cart_helper_builder = new CartHelperBuilder();
+ }
+
+ public function test_get_instance() {
+ $this->assertInstanceOf(CartHelper::class, $this->cart_helper_builder->get_instance());
+ }
+
+ public function test_get_tools_helper() {
+ $this->assertInstanceOf(ToolsHelper::class, $this->cart_helper_builder->get_tools_helper());
+ $this->assertInstanceOf(ToolsHelper::class, $this->cart_helper_builder->get_tools_helper(
+ new ToolsHelper(
+ new AlmaLogger(),
+ new PriceFactory(),
+ new CurrencyFactory()
+ )
+ ));
+ }
+
+ public function test_get_session_factory() {
+ $this->assertInstanceOf(SessionFactory::class, $this->cart_helper_builder->get_session_factory());
+ $this->assertInstanceOf(SessionFactory::class, $this->cart_helper_builder->get_session_factory(new SessionFactory()));
+ }
+
+ public function test_get_version_factory() {
+ $this->assertInstanceOf(VersionFactory::class, $this->cart_helper_builder->get_version_factory());
+ $this->assertInstanceOf(VersionFactory::class, $this->cart_helper_builder->get_version_factory(new VersionFactory()));
+ }
+
+ public function test_get_cart_factory() {
+ $this->assertInstanceOf(CartFactory::class, $this->cart_helper_builder->get_cart_factory());
+ $this->assertInstanceOf(CartFactory::class, $this->cart_helper_builder->get_cart_factory(new CartFactory()));
+ }
+
+ public function test_get_alma_settings() {
+ $this->assertInstanceOf(AlmaSettings::class, $this->cart_helper_builder->get_alma_settings());
+ $this->assertInstanceOf(AlmaSettings::class, $this->cart_helper_builder->get_alma_settings(new AlmaSettings()));
+ }
+
+ public function test_get_customer_helper() {
+ $this->assertInstanceOf(CustomerHelper::class, $this->cart_helper_builder->get_customer_helper());
+ $this->assertInstanceOf(CustomerHelper::class, $this->cart_helper_builder->get_customer_helper(\Mockery::mock(CustomerHelper::class)));
+ }
+
+
+}
+
+
+
diff --git a/src/tests/Builders/Helpers/CustomerHelperBuilderTest.php b/src/tests/Builders/Helpers/CustomerHelperBuilderTest.php
new file mode 100644
index 00000000..9ed3481a
--- /dev/null
+++ b/src/tests/Builders/Helpers/CustomerHelperBuilderTest.php
@@ -0,0 +1,48 @@
+customer_helper_builder = new CustomerHelperBuilder();
+ }
+
+ public function test_get_instance() {
+ $this->assertInstanceOf(CustomerHelper::class, $this->customer_helper_builder->get_instance());
+ }
+
+ public function test_get_customer_factory() {
+ $this->assertInstanceOf(CustomerFactory::class, $this->customer_helper_builder->get_customer_factory());
+ $this->assertInstanceOf(CustomerFactory::class, $this->customer_helper_builder->get_customer_factory(
+ new CustomerFactory(new PHPFactory())
+ ));
+ }
+}
+
+
+
diff --git a/src/tests/Builders/Helpers/GatewayHelperBuilderTest.php b/src/tests/Builders/Helpers/GatewayHelperBuilderTest.php
new file mode 100644
index 00000000..06d53ab3
--- /dev/null
+++ b/src/tests/Builders/Helpers/GatewayHelperBuilderTest.php
@@ -0,0 +1,70 @@
+gateway_helper_builder = new GatewayHelperBuilder();
+ }
+
+ public function test_get_instance() {
+ $this->assertInstanceOf(GatewayHelper::class, $this->gateway_helper_builder->get_instance());
+ }
+
+ public function test_get_payment_helpery() {
+ $this->assertInstanceOf(PaymentHelper::class, $this->gateway_helper_builder->get_payment_helper());
+ $this->assertInstanceOf(PaymentHelper::class, $this->gateway_helper_builder->get_payment_helper(new PaymentHelper()));
+ }
+
+ public function test_get_checkout_helper() {
+ $this->assertInstanceOf(CheckoutHelper::class, $this->gateway_helper_builder->get_checkout_helper());
+ $this->assertInstanceOf(CheckoutHelper::class, $this->gateway_helper_builder->get_checkout_helper(new CheckoutHelper()));
+ }
+
+ public function test_get_product_helper() {
+ $this->assertInstanceOf(ProductHelper::class, $this->gateway_helper_builder->get_product_helper());
+ $this->assertInstanceOf(ProductHelper::class, $this->gateway_helper_builder->get_product_helper( \Mockery::mock(ProductHelper::class)));
+ }
+
+ public function test_get_cart_helper() {
+ $this->assertInstanceOf(CartHelper::class, $this->gateway_helper_builder->get_cart_helper());
+ $this->assertInstanceOf(CartHelper::class, $this->gateway_helper_builder->get_cart_helper( \Mockery::mock(CartHelper::class)));
+ }
+
+ public function test_get_php_helper() {
+ $this->assertInstanceOf(PHPHelper::class, $this->gateway_helper_builder->get_php_helper());
+ $this->assertInstanceOf(PHPHelper::class, $this->gateway_helper_builder->get_php_helper(new PHPHelper()));
+ }
+
+}
+
+
+
diff --git a/src/tests/Builders/Helpers/PlanHelperBuilderTest.php b/src/tests/Builders/Helpers/PlanHelperBuilderTest.php
new file mode 100644
index 00000000..4d6119ab
--- /dev/null
+++ b/src/tests/Builders/Helpers/PlanHelperBuilderTest.php
@@ -0,0 +1,54 @@
+plan_helper_builder = new PlanHelperBuilder();
+ }
+
+ public function test_get_instance() {
+ $this->assertInstanceOf(PlanHelper::class, $this->plan_helper_builder->get_instance());
+ }
+
+ public function test_get_gateway_helper() {
+ $this->assertInstanceOf(GatewayHelper::class, $this->plan_helper_builder->get_gateway_helper());
+ $this->assertInstanceOf(GatewayHelper::class, $this->plan_helper_builder->get_gateway_helper(
+ \Mockery::mock(GatewayHelper::class)
+ ));
+ }
+
+ public function test_get_template_loader_helper() {
+ $this->assertInstanceOf(TemplateLoaderHelper::class, $this->plan_helper_builder->get_template_loader_helper());
+ $this->assertInstanceOf(TemplateLoaderHelper::class, $this->plan_helper_builder->get_template_loader_helper(new TemplateLoaderHelper()));
+ }
+
+}
+
+
+
diff --git a/src/tests/Builders/Helpers/ProductHelperBuilderTest.php b/src/tests/Builders/Helpers/ProductHelperBuilderTest.php
new file mode 100644
index 00000000..f17108e9
--- /dev/null
+++ b/src/tests/Builders/Helpers/ProductHelperBuilderTest.php
@@ -0,0 +1,44 @@
+product_helper_builder = new ProductHelperBuilder();
+ }
+
+ public function test_get_instance() {
+ $this->assertInstanceOf(ProductHelper::class, $this->product_helper_builder->get_instance());
+ }
+
+ public function test_get_core_factory() {
+ $this->assertInstanceOf(CoreFactory::class, $this->product_helper_builder->get_core_factory());
+ $this->assertInstanceOf(CoreFactory::class, $this->product_helper_builder->get_core_factory(new CoreFactory()));
+ }
+
+}
+
+
+
diff --git a/src/tests/Builders/Helpers/SettingsHelperBuilderTest.php b/src/tests/Builders/Helpers/SettingsHelperBuilderTest.php
new file mode 100644
index 00000000..a0e020cc
--- /dev/null
+++ b/src/tests/Builders/Helpers/SettingsHelperBuilderTest.php
@@ -0,0 +1,77 @@
+settings_helper_builder = new SettingsHelperBuilder();
+ }
+
+ public function test_get_instance() {
+ $this->assertInstanceOf(SettingsHelper::class, $this->settings_helper_builder->get_instance());
+ }
+
+ public function test_get_internationalization_helper() {
+ $this->assertInstanceOf(InternationalizationHelper::class, $this->settings_helper_builder->get_internalionalization_helper());
+ $this->assertInstanceOf(InternationalizationHelper::class, $this->settings_helper_builder->get_internalionalization_helper(new InternationalizationHelper()));
+ }
+
+ public function test_get_version_factory() {
+ $this->assertInstanceOf(VersionFactory::class, $this->settings_helper_builder->get_version_factory());
+ $this->assertInstanceOf(VersionFactory::class, $this->settings_helper_builder->get_version_factory(new VersionFactory()));
+ }
+
+ public function test_get_tools_helper() {
+ $this->assertInstanceOf(ToolsHelper::class, $this->settings_helper_builder->get_tools_helper());
+ $this->assertInstanceOf(ToolsHelper::class, $this->settings_helper_builder->get_tools_helper(
+ new ToolsHelper(
+ new AlmaLogger(),
+ new PriceFactory(),
+ new CurrencyFactory()
+ )
+ ));
+ }
+
+ public function test_get_assets_helper() {
+ $this->assertInstanceOf(AssetsHelper::class, $this->settings_helper_builder->get_assets_helper());
+ $this->assertInstanceOf(AssetsHelper::class, $this->settings_helper_builder->get_assets_helper(new AssetsHelper()));
+ }
+
+ public function test_get_plugin_factory() {
+ $this->assertInstanceOf(PluginFactory::class, $this->settings_helper_builder->get_plugin_factory());
+ $this->assertInstanceOf(PluginFactory::class, $this->settings_helper_builder->get_plugin_factory(new PluginFactory()));
+ }
+}
+
+
+
diff --git a/src/tests/Builders/Helpers/ToolsHelperBuilderTest.php b/src/tests/Builders/Helpers/ToolsHelperBuilderTest.php
new file mode 100644
index 00000000..122bd29c
--- /dev/null
+++ b/src/tests/Builders/Helpers/ToolsHelperBuilderTest.php
@@ -0,0 +1,58 @@
+tools_helper_builder = new ToolsHelperBuilder();
+ }
+
+ public function test_get_instance() {
+ $this->assertInstanceOf(ToolsHelper::class, $this->tools_helper_builder->get_instance());
+ }
+
+ public function test_get_price_factory() {
+ $this->assertInstanceOf(PriceFactory::class, $this->tools_helper_builder->get_price_factory());
+ $this->assertInstanceOf(PriceFactory::class, $this->tools_helper_builder->get_price_factory(new PriceFactory()));
+ }
+
+ public function test_get_alma_logger() {
+ $this->assertInstanceOf(AlmaLogger::class, $this->tools_helper_builder->get_alma_logger());
+ $this->assertInstanceOf(AlmaLogger::class, $this->tools_helper_builder->get_alma_logger(new AlmaLogger()));
+ }
+
+ public function test_get_currency_factory() {
+ $this->assertInstanceOf(CurrencyFactory::class, $this->tools_helper_builder->get_currency_factory());
+ $this->assertInstanceOf(CurrencyFactory::class, $this->tools_helper_builder->get_currency_factory( new CurrencyFactory()));
+ }
+
+}
+
+
+
diff --git a/src/tests/Factories/CartFactoryTest.php b/src/tests/Factories/CartFactoryTest.php
new file mode 100644
index 00000000..7f935ae0
--- /dev/null
+++ b/src/tests/Factories/CartFactoryTest.php
@@ -0,0 +1,45 @@
+cart_factory = new CartFactory();
+ }
+
+ public function test_get_cart() {
+ $this->assertInstanceOf(\WC_Cart::class, $this->cart_factory->get_cart());
+ }
+
+ public function test_get_cart_items() {
+ $cart_factory = \Mockery::mock(CartFactory::class)->makePartial();
+ $cart_factory->shouldReceive('get_cart')->andReturn(null);
+
+ $this->assertEquals(array(), $this->cart_factory->get_cart_items());
+ }
+
+}
+
+
+
diff --git a/src/tests/Factories/CoreFactoryTest.php b/src/tests/Factories/CoreFactoryTest.php
new file mode 100644
index 00000000..a516ad52
--- /dev/null
+++ b/src/tests/Factories/CoreFactoryTest.php
@@ -0,0 +1,37 @@
+core_factory = new CoreFactory();
+ }
+
+ public function test_has_term()
+ {
+ $this->assertFalse($this->core_factory->has_term('test', 'product_cat', 1));
+ }
+}
+
+
+
diff --git a/src/tests/Factories/CurrencyFactoryTest.php b/src/tests/Factories/CurrencyFactoryTest.php
new file mode 100644
index 00000000..aec2f171
--- /dev/null
+++ b/src/tests/Factories/CurrencyFactoryTest.php
@@ -0,0 +1,37 @@
+currency_factory = new CurrencyFactory();
+ }
+
+ public function test_get_currency() {
+ $this->assertEquals('USD', $this->currency_factory->get_currency());
+ }
+
+}
+
+
+
diff --git a/src/tests/Factories/CustomerFactoryTest.php b/src/tests/Factories/CustomerFactoryTest.php
new file mode 100644
index 00000000..cd953948
--- /dev/null
+++ b/src/tests/Factories/CustomerFactoryTest.php
@@ -0,0 +1,325 @@
+customer_factory = new CustomerFactory(new PHPFactory());
+
+ $this->customer = new WC_Customer();
+ $this->customer->set_first_name('FirstName');
+ $this->customer->set_last_name('LastName');
+ $this->customer->set_email('firstname@alma.com');
+ $this->customer->set_billing_phone('33000000000');
+ $this->customer->set_billing_first_name('BillingFirstName');
+ $this->customer->set_shipping_first_name('ShippingFirstName');
+ $this->customer->set_billing_last_name('BillingLastName');
+ $this->customer->set_shipping_last_name('ShippingLastName');
+ $this->customer->set_billing_address('BillingAddress');
+ $this->customer->set_shipping_address('ShippingAddress');
+ $this->customer->set_billing_address_2('BillingAddress2');
+ $this->customer->set_shipping_address_2('ShippingAddress2');
+ $this->customer->set_billing_postcode('BillingPostcode');
+ $this->customer->set_shipping_postcode('ShippingPostcode');
+ $this->customer->set_billing_city('BillingCity');
+ $this->customer->set_shipping_city('ShippingCity');
+ $this->customer->set_billing_country('BillingCountry');
+ $this->customer->set_shipping_country('ShippingCountry');
+ $this->customer->set_billing_email('billingemail@alma.com');
+ }
+
+ public function test_get_customer() {
+ $this->assertInstanceOf(\WC_Customer::class, $this->customer_factory->get_customer());
+
+ \WC()->customer = null;
+ $this->assertNull( $this->customer_factory->get_customer());
+
+ }
+
+ public function test_get_first_name() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_first_name());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('FirstName', $customer_factory->get_first_name());
+ }
+
+ public function test_get_last_name() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_last_name());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('LastName', $customer_factory->get_last_name());
+ }
+
+ public function test_get_email() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_email());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('firstname@alma.com', $customer_factory->get_email());
+ }
+
+ public function test_get_billing_phone() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_billing_phone());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('33000000000', $customer_factory->get_billing_phone());
+ }
+
+ public function test_get_billing_first_name() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_billing_first_name());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('BillingFirstName', $customer_factory->get_billing_first_name());
+ }
+
+ public function test_get_shipping_first_name() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_shipping_first_name());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('ShippingFirstName', $customer_factory->get_shipping_first_name());
+ }
+
+ public function test_get_billing_last_name() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_billing_last_name());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('BillingLastName', $customer_factory->get_billing_last_name());
+ }
+
+ public function test_get_shipping_last_name() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_shipping_last_name());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('ShippingLastName', $customer_factory->get_shipping_last_name());
+ }
+
+ public function test_get_shipping_address() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_shipping_address());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('ShippingAddress', $customer_factory->get_shipping_address());
+ }
+
+ public function test_get_billing_address() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_billing_address());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('BillingAddress', $customer_factory->get_billing_address());
+ }
+
+ public function test_get_shipping_address_2() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_shipping_address_2());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('ShippingAddress2', $customer_factory->get_shipping_address_2());
+ }
+
+ public function test_get_billing_address_2() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_billing_address());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('BillingAddress2', $customer_factory->get_billing_address_2());
+ }
+
+ public function test_get_billing_postcode() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_billing_postcode());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('BillingPostcode', $customer_factory->get_billing_postcode());
+ }
+
+ public function test_get_shipping_postcode() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_shipping_postcode());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('ShippingPostcode', $customer_factory->get_shipping_postcode());
+ }
+
+ public function test_get_billing_city() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_billing_city());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('BillingCity', $customer_factory->get_billing_city());
+ }
+
+ public function test_get_shipping_city() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_shipping_city());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('ShippingCity', $customer_factory->get_shipping_city());
+ }
+
+
+ public function test_get_billing_country() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_billing_country());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('BillingCountry', $customer_factory->get_billing_country());
+ }
+
+ public function test_get_shipping_country() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_shipping_country());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('ShippingCountry', $customer_factory->get_shipping_country());
+ }
+
+ public function test_get_billing_email() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertNull( $customer_factory->get_billing_email());
+
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+ $this->assertEquals('billingemail@alma.com', $customer_factory->get_billing_email());
+ }
+
+ public function test_call_method() {
+ $customer_factory = Mockery::mock( CustomerFactory::class )->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(null);
+
+ $this->assertFalse( $customer_factory->call_method('get_first_name'));
+
+ $php_factory = Mockery::mock( PHPFactory::class )->makePartial();
+ $php_factory->shouldReceive('call_method', 'get_first_name')->andReturn('FirstName');
+
+ $customer_factory = Mockery::mock( CustomerFactory::class , [$php_factory])->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn($this->customer);
+
+
+ $this->assertEquals('FirstName', $customer_factory->call_method('get_first_name'));
+
+ $php_factory = Mockery::mock( PHPFactory::class )->makePartial();
+ $php_factory->shouldReceive('call_method', 'get_first_name')->andReturn('FirstName');
+
+ $customer_factory = Mockery::mock( CustomerFactory::class , [$php_factory])->makePartial();
+ $customer_factory->shouldReceive('get_customer')->andReturn(false);
+
+ $this->assertFalse( $customer_factory->call_method('get_great_first_name'));
+ }
+}
+
+
+
diff --git a/src/tests/Factories/PHPFactoryTest.php b/src/tests/Factories/PHPFactoryTest.php
new file mode 100644
index 00000000..0966bf6b
--- /dev/null
+++ b/src/tests/Factories/PHPFactoryTest.php
@@ -0,0 +1,39 @@
+php_factory = new PHPFactory();
+ }
+
+ public function test_method_exists() {
+ $customer = new \WC_Customer();
+ $this->assertTrue($this->php_factory->method_exists($customer, 'get_first_name'));
+ $this->assertFalse($this->php_factory->method_exists($customer, 'get_my_great_customer_id'));
+ }
+
+}
+
+
+
diff --git a/src/tests/Factories/PluginFactoryTest.php b/src/tests/Factories/PluginFactoryTest.php
new file mode 100644
index 00000000..deca36a2
--- /dev/null
+++ b/src/tests/Factories/PluginFactoryTest.php
@@ -0,0 +1,39 @@
+plugin_factory = new PluginFactory();
+ }
+
+ public function test_get_plugin_admin_notice() {
+ $this->assertInstanceOf(NoticesService::class, $this->plugin_factory->get_plugin_admin_notice());
+ }
+
+}
+
+
+
diff --git a/src/tests/Factories/PriceFactoryTest.php b/src/tests/Factories/PriceFactoryTest.php
new file mode 100644
index 00000000..6366368f
--- /dev/null
+++ b/src/tests/Factories/PriceFactoryTest.php
@@ -0,0 +1,48 @@
+price_factory = new PriceFactory();
+ }
+
+ public function test_get_woo_decimal_separator() {
+ $this->assertEquals('.', $this->price_factory->get_woo_decimal_separator());
+ }
+
+ public function test_get_woo_thousand_separator() {
+ $this->assertEquals(',', $this->price_factory->get_woo_thousand_separator());
+ }
+
+ public function test_get_woo_decimals() {
+ $this->assertEquals('2', $this->price_factory->get_woo_decimals());
+ }
+
+ public function test_get_get_woo_format() {
+ $this->assertEquals('%1$s%2$s', $this->price_factory->get_woo_format());
+ }
+}
+
+
+
diff --git a/src/tests/Factories/SessionFactoryTest.php b/src/tests/Factories/SessionFactoryTest.php
new file mode 100644
index 00000000..08b3fc88
--- /dev/null
+++ b/src/tests/Factories/SessionFactoryTest.php
@@ -0,0 +1,37 @@
+session_factory = new SessionFactory();
+ }
+
+ public function test_get_session_factory() {
+ $this->assertInstanceOf(\WC_Session::class, $this->session_factory->get_session());
+ }
+
+}
+
+
+
diff --git a/src/tests/Factories/VersionFactoryTest.php b/src/tests/Factories/VersionFactoryTest.php
new file mode 100644
index 00000000..36a56e96
--- /dev/null
+++ b/src/tests/Factories/VersionFactoryTest.php
@@ -0,0 +1,37 @@
+version_factory = new VersionFactory();
+ }
+
+ public function test_get_session_factory() {
+ $this->assertEquals(\WooCommerce::instance()->version, $this->version_factory->get_version());
+ }
+
+}
+
+
+
diff --git a/src/tests/Helpers/AssetsHelperTest.php b/src/tests/Helpers/AssetsHelperTest.php
new file mode 100644
index 00000000..1b329546
--- /dev/null
+++ b/src/tests/Helpers/AssetsHelperTest.php
@@ -0,0 +1,38 @@
+assets_helper = new AssetsHelper();
+ }
+ public function test_alma_domains_whitelist() {
+ $this->assertEquals(array(
+ 'testdomain',
+ 'pay.getalma.eu',
+ 'pay.sandbox.getalma.eu'
+ ), $this->assets_helper->alma_domains_whitelist(array('testdomain')));
+ }
+}
+
+
+
diff --git a/src/tests/Helpers/CartHelperTest.php b/src/tests/Helpers/CartHelperTest.php
new file mode 100644
index 00000000..3ced81bc
--- /dev/null
+++ b/src/tests/Helpers/CartHelperTest.php
@@ -0,0 +1,174 @@
+shouldReceive('get_cart')
+ ->andReturn(null);
+ $cart_helper_builder = \Mockery::mock(CartHelperBuilder::class)->makePartial();
+ $cart_helper_builder->shouldReceive('get_cart_factory')
+ ->andReturn($cart_factory);
+
+ $cart_helper = $cart_helper_builder->get_instance();
+
+ $this->assertEquals('0', $cart_helper->get_total_from_cart());
+
+ // Test Cart version < 3.2.0
+ $version_factory = \Mockery::mock(VersionFactory::class);
+ $version_factory->shouldReceive('get_version')
+ ->andReturn('2.0.0');
+
+ $cart = new \stdClass();
+ $cart->total = '1.0000';
+
+ $cart_factory = \Mockery::mock(CartFactory::class);
+ $cart_factory->shouldReceive('get_cart')
+ ->andReturn($cart);
+
+ $cart_helper_builder = \Mockery::mock(CartHelperBuilder::class)->makePartial();
+ $cart_helper_builder->shouldReceive('get_cart_factory')
+ ->andReturn($cart_factory);
+ $cart_helper_builder->shouldReceive('get_version_factory')
+ ->andReturn($version_factory);
+
+ $cart_helper = $cart_helper_builder->get_instance();
+
+ $this->assertEquals('1.0000', $cart_helper->get_total_from_cart());
+
+ // Test Cart version >3.2.0 and cart total not null
+
+ $wc_cart = \Mockery::mock(\WC_Cart::class);
+ $wc_cart->shouldReceive('get_total')
+ ->andReturn('2.0000');
+
+ $cart_factory = \Mockery::mock(CartFactory::class);
+ $cart_factory->shouldReceive('get_cart')
+ ->andReturn($wc_cart);
+
+ $cart_helper_builder = \Mockery::mock(CartHelperBuilder::class)->makePartial();
+ $cart_helper_builder->shouldReceive('get_cart_factory')
+ ->andReturn($cart_factory);
+
+ $cart_helper = $cart_helper_builder->get_instance();
+
+ $this->assertEquals('2.0000', $cart_helper->get_total_from_cart());
+
+
+ // Test Cart version >3.2.0 and cart total null and session cart_totals null
+ $session = \Mockery::mock(\WC_Session::class);
+ $session->shouldReceive('get', ['cart_totals'])
+ ->andReturn(null);
+
+ $session_factory = \Mockery::mock(SessionFactory::class);
+ $session_factory->shouldReceive('get_session')
+ ->andReturn($session);
+
+
+ $wc_cart = \Mockery::mock(\WC_Cart::class);
+ $wc_cart->shouldReceive('get_total')
+ ->andReturn('0');
+
+ $cart_factory = \Mockery::mock(CartFactory::class);
+ $cart_factory->shouldReceive('get_cart')
+ ->andReturn($wc_cart);
+
+ $cart_helper_builder = \Mockery::mock(CartHelperBuilder::class)->makePartial();
+ $cart_helper_builder->shouldReceive('get_cart_factory')
+ ->andReturn($cart_factory);
+ $cart_helper_builder->shouldReceive('get_session_factory')
+ ->andReturn($session_factory);
+
+ $cart_helper = $cart_helper_builder->get_instance();
+
+
+ $this->assertEquals(0, $cart_helper->get_total_from_cart());
+
+ // Test Cart version >3.2.0 and cart total null and session cart_totals not null
+ $session = \Mockery::mock(\WC_Session::class);
+ $session->shouldReceive('get', ['cart_totals'])
+ ->andReturn(array('total' => '3.000'));
+
+ $session_factory = \Mockery::mock(SessionFactory::class);
+ $session_factory->shouldReceive('get_session')
+ ->andReturn($session);
+
+ $wc_cart = \Mockery::mock(\WC_Cart::class);
+ $wc_cart->shouldReceive('get_total')
+ ->andReturn('0');
+
+ $cart_factory = \Mockery::mock(CartFactory::class);
+ $cart_factory->shouldReceive('get_cart')
+ ->andReturn($wc_cart);
+
+ $cart_helper_builder = \Mockery::mock(CartHelperBuilder::class)->makePartial();
+ $cart_helper_builder->shouldReceive('get_cart_factory')
+ ->andReturn($cart_factory);
+ $cart_helper_builder->shouldReceive('get_session_factory')
+ ->andReturn($session_factory);
+
+ $cart_helper = $cart_helper_builder->get_instance();
+
+
+ $this->assertEquals('3.000', $cart_helper->get_total_from_cart());
+
+ }
+
+ /**
+ *
+ * @covers \Alma\Woocommerce\Helpers\CartHelper::get_total_in_cents
+ *
+ * @return void
+ */
+ public function test_get_total_in_cents() {
+ $tools_helper_builder = new ToolsHelperBuilder();
+ $tools_helper = $tools_helper_builder->get_tools_helper();
+
+ $cart_helper = \Mockery::mock(
+ CartHelper::class,
+ [
+ $tools_helper,
+ new SessionFactory(),
+ new VersionFactory(),
+ new CartFactory(),
+ new AlmaSettings(),
+ new AlmaLogger(),
+ \Mockery::mock(CustomerHelper::class)
+ ])->makePartial();
+ $cart_helper->shouldReceive('get_total_from_cart')
+ ->andReturn('4.000');
+
+ $this->assertEquals('400', $cart_helper->get_total_in_cents());
+ }
+}
+
+
+
diff --git a/src/tests/Helpers/CustomerHelperTest.php b/src/tests/Helpers/CustomerHelperTest.php
new file mode 100644
index 00000000..f0cd502c
--- /dev/null
+++ b/src/tests/Helpers/CustomerHelperTest.php
@@ -0,0 +1,174 @@
+customer = new \WC_Customer();
+ $this->customer->set_first_name('FirstName');
+ $this->customer->set_last_name('LastName');
+ $this->customer->set_email('firstname@alma.com');
+ $this->customer->set_billing_phone('+33000000000');
+ $this->customer->set_billing_first_name('BillingFirstName');
+ $this->customer->set_shipping_first_name('ShippingFirstName');
+ $this->customer->set_billing_last_name('BillingLastName');
+ $this->customer->set_shipping_last_name('ShippingLastName');
+ $this->customer->set_billing_address('BillingAddress');
+ $this->customer->set_shipping_address('ShippingAddress');
+ $this->customer->set_billing_address_2('BillingAddress2');
+ $this->customer->set_shipping_address_2('ShippingAddress2');
+ $this->customer->set_billing_postcode('BillingPostcode');
+ $this->customer->set_shipping_postcode('ShippingPostcode');
+ $this->customer->set_billing_city('BillingCity');
+ $this->customer->set_shipping_city('ShippingCity');
+ $this->customer->set_billing_country('BillingCountry');
+ $this->customer->set_shipping_country('ShippingCountry');
+ $this->customer->set_billing_email('billingemail@alma.com');
+
+ $customer_factory = \Mockery::mock(CustomerFactory::class)->makePartial();
+ $customer_factory->shouldReceive('get_first_name')->andReturn($this->customer->get_first_name());
+ $customer_factory->shouldReceive('get_last_name')->andReturn($this->customer->get_last_name());
+ $customer_factory->shouldReceive('get_email')->andReturn($this->customer->get_email());
+ $customer_factory->shouldReceive('get_billing_phone')->andReturn($this->customer->get_billing_phone());
+ $customer_factory->shouldReceive('get_billing_first_name')->andReturn($this->customer->get_billing_first_name());
+ $customer_factory->shouldReceive('get_billing_last_name')->andReturn($this->customer->get_billing_last_name());
+ $customer_factory->shouldReceive('get_billing_address')->andReturn($this->customer->get_billing_address());
+ $customer_factory->shouldReceive('get_billing_address_2')->andReturn($this->customer->get_billing_address_2());
+ $customer_factory->shouldReceive('get_billing_postcode')->andReturn($this->customer->get_billing_postcode());
+ $customer_factory->shouldReceive('get_billing_city')->andReturn($this->customer->get_billing_city());
+ $customer_factory->shouldReceive('get_billing_country')->andReturn($this->customer->get_billing_country());
+ $customer_factory->shouldReceive('get_billing_email')->andReturn($this->customer->get_billing_email());
+ $customer_factory->shouldReceive('get_shipping_first_name')->andReturn($this->customer->get_shipping_first_name());
+ $customer_factory->shouldReceive('get_shipping_last_name')->andReturn($this->customer->get_shipping_last_name());
+ $customer_factory->shouldReceive('get_shipping_address')->andReturn($this->customer->get_shipping_address());
+ $customer_factory->shouldReceive('get_shipping_address_2')->andReturn($this->customer->get_shipping_address_2());
+ $customer_factory->shouldReceive('get_shipping_postcode')->andReturn($this->customer->get_shipping_postcode());
+ $customer_factory->shouldReceive('get_shipping_city')->andReturn($this->customer->get_shipping_city());
+ $customer_factory->shouldReceive('get_shipping_country')->andReturn($this->customer->get_shipping_country());
+
+ $this->customer_helper = \Mockery::mock(CustomerHelper::class, [$customer_factory])->makePartial();
+
+ $this->result_data = array(
+ 'first_name' => $this->customer->get_first_name(),
+ 'last_name' => $this->customer->get_last_name(),
+ 'email' => $this->customer->get_email(),
+ 'phone' => $this->customer->get_billing_phone(),
+ 'addresses' => array(
+ array(
+ 'first_name' => $this->customer->get_billing_first_name(),
+ 'last_name' => $this->customer->get_billing_last_name(),
+ 'line1' => $this->customer->get_billing_address(),
+ 'line2' => $this->customer->get_billing_address_2(),
+ 'postal_code' => $this->customer->get_billing_postcode(),
+ 'city' => $this->customer->get_billing_city(),
+ 'country' => $this->customer->get_billing_country(),
+ 'email' => $this->customer->get_billing_email(),
+ 'phone' => $this->customer->get_billing_phone(),
+ ),
+ array(
+ 'first_name' => $this->customer->get_shipping_first_name(),
+ 'last_name' => $this->customer->get_shipping_last_name(),
+ 'line1' => $this->customer->get_shipping_address(),
+ 'line2' => $this->customer->get_shipping_address_2(),
+ 'postal_code' => $this->customer->get_shipping_postcode(),
+ 'city' => $this->customer->get_shipping_city(),
+ 'country' => $this->customer->get_shipping_country(),
+ )
+ )
+ );
+ }
+
+ public function test_get_data() {
+ $this->assertEquals($this->result_data, $this->customer_helper->get_data());
+ }
+
+ public function test_get_customer_data() {
+ $data = array(
+ 'maclé' => 'mavaleur'
+ );
+
+ $customer_factory = \Mockery::mock(CustomerFactory::class)->makePartial();
+ $customer_factory->shouldReceive('call_method')->andReturn('LastName');
+
+ $customer_helper = \Mockery::mock(CustomerHelper::class, [$customer_factory])->makePartial();
+
+ $this->assertEquals(array(
+ 'maclé' => 'mavaleur',
+ 'last_name' => 'LastName'
+ ), $customer_helper->get_customer_data('get_last_name', $data, 'last_name'));
+
+ $customer_factory = \Mockery::mock(CustomerFactory::class)->makePartial();
+ $customer_factory->shouldReceive('call_method')->andReturn(false);
+
+ $customer_helper = \Mockery::mock(CustomerHelper::class, [$customer_factory])->makePartial();
+
+ $this->assertEquals(array(
+ 'maclé' => 'mavaleur',
+ ), $customer_helper->get_customer_data('get_last_name', $data, 'last_name'));
+
+ $customer_factory = \Mockery::mock(CustomerFactory::class)->makePartial();
+ $customer_factory->shouldReceive('call_method')->andReturn('LastName');
+
+ $customer_helper = \Mockery::mock(CustomerHelper::class, [$customer_factory])->makePartial();
+
+ $data = array(
+ 'maclé' => 'mavaleur',
+ 'last_name' => 'NoLastName'
+ );
+
+ $this->assertEquals(array(
+ 'maclé' => 'mavaleur',
+ 'last_name' => 'NoLastName'
+ ), $customer_helper->get_customer_data('get_last_name', $data, 'last_name'));
+ }
+
+ public function test_get_billing_address() {
+ $this->assertEquals($this->result_data['addresses'][0], $this->customer_helper->get_billing_address());
+ }
+
+ public function test_get_shipping_address() {
+ $this->assertEquals($this->result_data['addresses'][1], $this->customer_helper->get_shipping_address());
+ }
+}
+
+
+
diff --git a/src/tests/Helpers/FeePlanHelperTest.php b/src/tests/Helpers/FeePlanHelperTest.php
new file mode 100644
index 00000000..787b50f7
--- /dev/null
+++ b/src/tests/Helpers/FeePlanHelperTest.php
@@ -0,0 +1,105 @@
+fee_plan_helper = new FeePlanHelper();
+ }
+
+ public function test_get_fee_plan() {
+ $fee_plan = new FeePlan(
+ [
+ 'installments_count' => 1,
+ 'min_purchase_amount' => 500,
+ ]
+ );
+
+ $this->assertEquals('100', $this->fee_plan_helper->get_min_purchase_amount($fee_plan) );
+
+ $fee_plan = new FeePlan(
+ [
+ 'installments_count' => 1,
+ 'deferred_days' => 10,
+ 'deferred_months' => 0,
+ 'min_purchase_amount' => 500,
+ ]
+ );
+
+ $this->assertEquals('500', $this->fee_plan_helper->get_min_purchase_amount($fee_plan) );
+ }
+
+ public function test_alma_usort_plan_keys() {
+ $plan_key_1 = 'general_1_0_0';
+ $plan_key_2 = 'general_1_0_0';
+
+ $this->assertEquals(0, $this->fee_plan_helper->alma_usort_plans_keys($plan_key_1, $plan_key_2));
+
+ $plan_key_1 = 'test_1_0_0';
+ $this->assertEquals(0, $this->fee_plan_helper->alma_usort_plans_keys($plan_key_1, $plan_key_2));
+
+ $plan_key_1 = 'general_1_0_0';
+ $plan_key_2 = 'test_1_0_0';
+ $this->assertEquals(0, $this->fee_plan_helper->alma_usort_plans_keys($plan_key_1, $plan_key_2));
+
+ $plan_key_1 = 'general_1_10_0';
+ $plan_key_2 = 'general_1_0_0';
+ $this->assertEquals(1, $this->fee_plan_helper->alma_usort_plans_keys($plan_key_1, $plan_key_2));
+
+ $plan_key_1 = 'general_1_0_0';
+ $plan_key_2 = 'general_1_15_0';
+ $this->assertEquals(-1, $this->fee_plan_helper->alma_usort_plans_keys($plan_key_1, $plan_key_2));
+
+ $plan_key_1 = 'general_1_30_0';
+ $plan_key_2 = 'general_1_15_1';
+ $this->assertEquals(-1, $this->fee_plan_helper->alma_usort_plans_keys($plan_key_1, $plan_key_2));
+
+ $plan_key_1 = 'general_1_15_0';
+ $plan_key_2 = 'general_1_30_0';
+ $this->assertEquals(-1, $this->fee_plan_helper->alma_usort_plans_keys($plan_key_1, $plan_key_2));
+
+ $plan_key_1 = 'general_1_15_0';
+ $plan_key_2 = 'general_2_30_0';
+ $this->assertEquals(-1, $this->fee_plan_helper->alma_usort_plans_keys($plan_key_1, $plan_key_2));
+
+ $plan_key_1 = 'general_2_30_0';
+ $plan_key_2 = 'general_1_15_0';
+ $this->assertEquals(1, $this->fee_plan_helper->alma_usort_plans_keys($plan_key_1, $plan_key_2));
+ }
+
+ public function test_alma_match_plan_key_pattern() {
+ $plan_key_1 = 'general_4_0_0';
+
+ $this->assertFalse($this->fee_plan_helper->alma_match_plan_key_pattern($plan_key_1, '/^(test)_([0-9]{1,2})_([0-9]{1,2})_([0-9]{1,2})$/'));
+
+ $this->assertEquals(array(
+ 'key' => $plan_key_1,
+ 'kind' => 'general',
+ 'installments' => '4',
+ 'deferred_days' => '0',
+ 'deferred_months' => '0',
+ ) , $this->fee_plan_helper->alma_match_plan_key_pattern($plan_key_1));
+
+ }
+}
+
+
+
diff --git a/src/tests/Helpers/GatewayHelperTest.php b/src/tests/Helpers/GatewayHelperTest.php
new file mode 100644
index 00000000..858029dd
--- /dev/null
+++ b/src/tests/Helpers/GatewayHelperTest.php
@@ -0,0 +1,381 @@
+gateway_helper_builder = \Mockery::mock( GatewayHelperBuilder::class )->makePartial();
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $this->core_factory = \Mockery::mock( CoreFactory::class )->makePartial();
+ $this->product_helper = \Mockery::mock( ProductHelper::class )->makePartial();
+ $this->cart_helper = \Mockery::mock( CartHelper::class )->makePartial();
+ $this->cart_factory = \Mockery::mock( CartFactory::class )->makePartial();
+ $this->alma_settings = \Mockery::mock( AlmaSettings::class )->makePartial();
+ $this->php_helper = \Mockery::mock( PHPHelper::class )->makePartial();
+ }
+
+ public function tear_down() {
+ $this->gateway_helper = null;
+ $this->gateway_helper_builder = null;
+ $this->core_factory = null;
+ $this->product_helper = null;
+ $this->alma_settings = null;
+ $this->cart_helper = null;
+ $this->cart_factory = null;
+ $this->php_helper = null;
+ \Mockery::close();
+ }
+
+ public function test_woocommerce_available_payment_gateways_is_admin() {
+ $this->core_factory->shouldReceive( 'is_admin' )->andReturn( true );
+
+ $this->gateway_helper_builder->shouldReceive('get_core_factory' )->andReturn( $this->core_factory );
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $result = array(
+ ConstantsHelper::GATEWAY_ID,
+ ConstantsHelper::GATEWAY_ID_PAY_LATER
+ );
+
+ $this->assertEquals($result, $this->gateway_helper->woocommerce_available_payment_gateways($result));
+ }
+
+ public function test_woocommerce_available_payment_gateways_no_product_excluded() {
+ $this->core_factory->shouldReceive( 'is_admin' )->andReturn( false );
+ $this->product_helper->shouldReceive( 'cart_has_excluded_product' )->andReturn( false);
+
+ $this->gateway_helper_builder->shouldReceive('get_core_factory' )->andReturn( $this->core_factory );
+ $this->gateway_helper_builder->shouldReceive('get_product_helper' )->andReturn( $this->product_helper );
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $gateway_alma = \Mockery::mock(StandardGateway::class)->makePartial();
+ $gateway_alma->id = ConstantsHelper::GATEWAY_ID;
+
+ $result = array(
+ ConstantsHelper::GATEWAY_ID => $gateway_alma
+ );
+
+ $this->assertEquals($result, $this->gateway_helper->woocommerce_available_payment_gateways($result));
+ }
+
+ public function test_woocommerce_available_payment_gateways_with_product_excluded() {
+ $this->core_factory->shouldReceive( 'is_admin' )->andReturn( false );
+ $this->product_helper->shouldReceive( 'cart_has_excluded_product' )->andReturn( true);
+
+ $this->gateway_helper_builder->shouldReceive('get_core_factory' )->andReturn( $this->core_factory );
+ $this->gateway_helper_builder->shouldReceive('get_product_helper' )->andReturn( $this->product_helper );
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $gateway_alma = \Mockery::mock(StandardGateway::class)->makePartial();
+ $gateway_alma->id = ConstantsHelper::GATEWAY_ID;
+
+ $result = array(
+ ConstantsHelper::GATEWAY_ID => $gateway_alma
+ );
+
+ $this->assertEquals(array(), $this->gateway_helper->woocommerce_available_payment_gateways($result));
+ }
+
+ public function test_woocommerce_gateway_title_with_settings() {
+ $this->alma_settings->shouldReceive( 'get_title' )->with(ConstantsHelper::GATEWAY_ID)->andReturn( 'My title' );
+
+ $this->gateway_helper_builder->shouldReceive('get_alma_settings' )->andReturn( $this->alma_settings );
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+
+ $this->assertEquals('My title', $this->gateway_helper->woocommerce_gateway_title('Default title', ConstantsHelper::GATEWAY_ID));
+ }
+
+ public function test_woocommerce_gateway_title_without_settings() {
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+
+ $this->assertEquals('Default title', $this->gateway_helper->woocommerce_gateway_title('Default title', 'gateway_id'));
+ }
+
+ public function test_woocommerce_gateway_description_with_settings() {
+ $this->alma_settings->shouldReceive( 'get_description' )->with(ConstantsHelper::GATEWAY_ID)->andReturn( 'My description' );
+
+ $this->gateway_helper_builder->shouldReceive('get_alma_settings' )->andReturn( $this->alma_settings );
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+
+ $this->assertEquals('My description', $this->gateway_helper->woocommerce_gateway_description('Default title', ConstantsHelper::GATEWAY_ID));
+ }
+
+ public function test_woocommerce_gateway_description_without_settings() {
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+
+ $this->assertEquals('Default description', $this->gateway_helper->woocommerce_gateway_description('Default description', 'gateway_id'));
+ }
+
+ public function test_woocommerce_alma_gateway_title_with_settings() {
+ $this->alma_settings->shouldReceive( 'get_title' )->with(ConstantsHelper::GATEWAY_ID, true)->andReturn( 'My title Block' );
+
+ $this->gateway_helper_builder->shouldReceive('get_alma_settings' )->andReturn( $this->alma_settings );
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+
+ $this->assertEquals('My title Block', $this->gateway_helper->get_alma_gateway_title(ConstantsHelper::GATEWAY_ID, true));
+ }
+
+ public function test_woocommerce_alma_gateway_title_with_settings_and_no_blocks() {
+ $this->alma_settings->shouldReceive( 'get_title' )->with(ConstantsHelper::GATEWAY_ID, false)->andReturn( 'My title Block' );
+
+ $this->gateway_helper_builder->shouldReceive('get_alma_settings' )->andReturn( $this->alma_settings );
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+
+ $this->assertEquals('My title Block', $this->gateway_helper->get_alma_gateway_title(ConstantsHelper::GATEWAY_ID, false));
+ }
+
+ public function test_woocommerce_alma_gateway_title_with_wrong_gateway_id() {
+
+ $this->expectException(AlmaException::class);
+ $this->expectExceptionMessage('Unknown gateway id : fake_id');
+ $this->gateway_helper->get_alma_gateway_title('fake_id', true);
+ }
+
+ public function test_get_alma_logo_text_wrong_id() {
+ $this->assertEquals('null', $this->gateway_helper->get_alma_gateway_logo_text(ConstantsHelper::GATEWAY_ID_PAY_LATER));
+ }
+
+ public function test_get_alma_logo_text() {
+ $this->assertEquals('Pay Now', $this->gateway_helper->get_alma_gateway_logo_text(ConstantsHelper::GATEWAY_ID_PAY_NOW));
+ $this->assertEquals('Pay Now', $this->gateway_helper->get_alma_gateway_logo_text(ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW));
+ }
+
+ public function test_is_in_page_gateway_not_an_inpage() {
+ $this->assertFalse($this->gateway_helper->is_in_page_gateway(ConstantsHelper::GATEWAY_ID_PAY_LATER));
+ }
+
+ public function test_is_in_page_gateway() {
+ $this->assertTrue($this->gateway_helper->is_in_page_gateway(ConstantsHelper::GATEWAY_ID_IN_PAGE));
+ }
+
+ public function test_woocommerce_alma_gateway_description_with_settings() {
+ $this->alma_settings->shouldReceive( 'get_description' )->with(ConstantsHelper::GATEWAY_ID, true)->andReturn( 'My description Block' );
+
+ $this->gateway_helper_builder->shouldReceive('get_alma_settings' )->andReturn( $this->alma_settings );
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+
+ $this->assertEquals('My description Block', $this->gateway_helper->get_alma_gateway_description(ConstantsHelper::GATEWAY_ID, true));
+ }
+
+ public function test_woocommerce_alma_gateway_description_with_settings_and_no_blocks() {
+ $this->alma_settings->shouldReceive( 'get_description' )->with(ConstantsHelper::GATEWAY_ID, false)->andReturn( 'My description Block' );
+
+ $this->gateway_helper_builder->shouldReceive('get_alma_settings' )->andReturn( $this->alma_settings );
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+
+ $this->assertEquals('My description Block', $this->gateway_helper->get_alma_gateway_description(ConstantsHelper::GATEWAY_ID, false));
+ }
+
+ public function test_woocommerce_alma_gateway_description_with_wrong_gateway_id() {
+
+ $this->expectException(AlmaException::class);
+ $this->expectExceptionMessage('Unknown gateway id : fake_id');
+ $this->gateway_helper->get_alma_gateway_description('fake_id', true);
+ }
+
+ public function test_is_there_eligibility_in_cart_no_eligibility_found() {
+ $this->cart_helper->shouldReceive( 'get_eligible_plans_keys_for_cart' )->andReturn( array());
+ $this->gateway_helper_builder->shouldReceive('get_cart_helper' )->andReturn( $this->cart_helper );
+
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $this->assertFalse($this->gateway_helper->is_there_eligibility_in_cart());
+ }
+
+ public function test_get_default_plans_no_plans() {
+ $this->assertNull($this->gateway_helper->get_default_plan(array()));
+ }
+
+ public function test_get_default_plans_default_plan_found() {
+ $this->assertEquals(
+ ConstantsHelper::DEFAULT_FEE_PLAN,
+ $this->gateway_helper->get_default_plan(
+ array(ConstantsHelper::DEFAULT_FEE_PLAN,
+ ConstantsHelper::PAY_NOW_FEE_PLAN
+ )
+ )
+ );
+ }
+
+ public function test_get_default_plans_default_plan_array_found() {
+ $this->assertEquals(
+ ConstantsHelper::DEFAULT_FEE_PLAN,
+ $this->gateway_helper->get_default_plan(
+ array(
+ array(ConstantsHelper::DEFAULT_FEE_PLAN ),
+ array(ConstantsHelper::PAY_NOW_FEE_PLAN)
+ )
+ )
+ );
+ }
+
+ public function test_get_default_plans_default_plan() {
+ $this->assertEquals(
+ ConstantsHelper::DEFAULT_FEE_PLAN,
+ $this->gateway_helper->get_default_plan(
+ array(
+ ConstantsHelper::DEFAULT_FEE_PLAN ,
+ ConstantsHelper::PAY_NOW_FEE_PLAN
+ )
+ )
+ );
+ }
+
+ public function test_cart_contains_excluded_category_empty_cart()
+ {
+ $this->cart_factory->shouldReceive('get_cart')->andReturn(null);
+ $this->gateway_helper_builder->shouldReceive('get_cart_factory')->andReturn($this->cart_factory);
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $this->assertFalse($this->gateway_helper->cart_contains_excluded_category());
+ }
+
+ public function test_cart_contains_excluded_category_setting_property_not_exists()
+ {
+ $this->cart_factory->shouldReceive('get_cart')->andReturn(\Mockery::mock(\WC_Cart::class));
+ $this->php_helper->shouldReceive('property_exists')->andReturn(false);
+ $this->gateway_helper_builder->shouldReceive('get_php_helper')->andReturn($this->php_helper);
+ $this->gateway_helper_builder->shouldReceive('get_cart_factory')->andReturn($this->cart_factory);
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $this->assertFalse($this->gateway_helper->cart_contains_excluded_category());
+ }
+
+ public function test_cart_contains_excluded_category_setting_property_not_an_array()
+ {
+ $this->cart_factory->shouldReceive('get_cart')->andReturn(\Mockery::mock(\WC_Cart::class));
+ $this->alma_settings->excluded_products_list = 'not_an_array';
+ $this->php_helper->shouldReceive('property_exists')->andReturn(true);
+ $this->gateway_helper_builder->shouldReceive('get_php_helper')->andReturn($this->php_helper);
+ $this->gateway_helper_builder->shouldReceive('get_cart_factory')->andReturn($this->cart_factory);
+ $this->gateway_helper_builder->shouldReceive('get_alma_settings')->andReturn($this->alma_settings);
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $this->assertFalse($this->gateway_helper->cart_contains_excluded_category());
+ }
+
+ public function test_cart_contains_excluded_category_setting_property_no_exclusion()
+ {
+ $this->cart_factory->shouldReceive('get_cart')->andReturn(\Mockery::mock(\WC_Cart::class));
+ $cart_item = array('product_id' => 1);
+
+ $this->cart_factory->shouldReceive('get_cart_items')->andReturn(array($cart_item));
+
+ $this->alma_settings->excluded_products_list = array( 'slug2' );
+
+ $this->core_factory->shouldReceive('has_term')->andReturn(false);
+ $this->php_helper->shouldReceive('property_exists')->andReturn(true);
+ $this->gateway_helper_builder->shouldReceive('get_php_helper')->andReturn($this->php_helper);
+ $this->gateway_helper_builder->shouldReceive('get_cart_factory')->andReturn($this->cart_factory);
+ $this->gateway_helper_builder->shouldReceive('get_alma_settings')->andReturn($this->alma_settings);
+ $this->gateway_helper_builder->shouldReceive('get_core_factory')->andReturn($this->core_factory);
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $this->assertFalse($this->gateway_helper->cart_contains_excluded_category());
+ }
+
+ public function test_cart_contains_excluded_category_setting_property_with_exclusion()
+ {
+ $this->cart_factory->shouldReceive('get_cart')->andReturn(\Mockery::mock(\WC_Cart::class));
+ $cart_item = array('product_id' => '1');
+
+ $this->cart_factory->shouldReceive('get_cart_items')->andReturn(array($cart_item));
+ $this->alma_settings->excluded_products_list = array( 'slug1' );
+
+ $this->core_factory->shouldReceive('has_term')->andReturn(true);
+
+ $this->php_helper->shouldReceive('property_exists')->andReturn(true);
+ $this->gateway_helper_builder->shouldReceive('get_php_helper')->andReturn($this->php_helper);
+ $this->gateway_helper_builder->shouldReceive('get_cart_factory')->andReturn($this->cart_factory);
+ $this->gateway_helper_builder->shouldReceive('get_alma_settings')->andReturn($this->alma_settings);
+ $this->gateway_helper_builder->shouldReceive('get_core_factory')->andReturn($this->core_factory);
+ $this->gateway_helper = $this->gateway_helper_builder->get_instance();
+
+ $this->assertTrue($this->gateway_helper->cart_contains_excluded_category());
+ }
+}
diff --git a/src/tests/Helpers/InternationalizationHelperTest.php b/src/tests/Helpers/InternationalizationHelperTest.php
new file mode 100644
index 00000000..983ef011
--- /dev/null
+++ b/src/tests/Helpers/InternationalizationHelperTest.php
@@ -0,0 +1,35 @@
+internationalization_helper = new InternationalizationHelper();
+ }
+
+ public function test_get_display_texts_keys_and_values() {
+ $this->assertEquals(array( 'at_shipping' => 'At shipping'), $this->internationalization_helper->get_display_texts_keys_and_values());
+ }
+}
+
+
+
diff --git a/src/tests/Helpers/PlanHelperTest.php b/src/tests/Helpers/PlanHelperTest.php
new file mode 100644
index 00000000..7f56215e
--- /dev/null
+++ b/src/tests/Helpers/PlanHelperTest.php
@@ -0,0 +1,336 @@
+alma_settings_mock = \Mockery::mock(AlmaSettings::class)->makePartial();
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::DEFAULT_FEE_PLAN, ConstantsHelper::GATEWAY_ID_MORE_THAN_FOUR)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::GATEWAY_ID_MORE_THAN_FOUR)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::DEFAULT_FEE_PLAN, ConstantsHelper::GATEWAY_ID_PAY_LATER)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::GATEWAY_ID_PAY_LATER)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_LATER)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::DEFAULT_FEE_PLAN, ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_LATER)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::GATEWAY_ID_PAY_NOW)->andReturn(true);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::GATEWAY_ID)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW)->andReturn(true);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::GATEWAY_ID_IN_PAGE)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::DEFAULT_FEE_PLAN, ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::DEFAULT_FEE_PLAN, ConstantsHelper::GATEWAY_ID_IN_PAGE)->andReturn(true);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::DEFAULT_FEE_PLAN, ConstantsHelper::GATEWAY_ID_PAY_NOW)->andReturn(false);
+ $this->alma_settings_mock->shouldReceive('should_display_plan')->with(ConstantsHelper::DEFAULT_FEE_PLAN, ConstantsHelper::GATEWAY_ID)->andReturn(true);
+
+ $this->gateway_helper_mock = \Mockery::mock(GatewayHelper::class)->makePartial();
+ $this->price_factory_mock = \Mockery::mock(PriceFactory::class)->makePartial();
+ $this->eligibility_mock = \Mockery::mock(Eligibility::class);
+
+ $this->template_loader_helper_mock = \Mockery::mock(TemplateLoaderHelper::class);
+ $this->template_loader_helper_mock->shouldReceive('get_template')->andReturn('');
+
+ $this->plan_builder_helper = \Mockery::mock(PlanHelperBuilder::class)->makePartial();
+ $this->plan_builder_helper->shouldReceive('get_alma_settings')->andReturn($this->alma_settings_mock);
+ $this->plan_builder_helper->shouldReceive('get_gateway_helper')->andReturn($this->gateway_helper_mock);
+ $this->plan_builder_helper->shouldReceive('get_template_loader_helper')->andReturn($this->template_loader_helper_mock);
+ $this->plan_builder_helper->shouldReceive('get_price_factory')->andReturn($this->price_factory_mock);
+
+ $this->alma_plan_helper = $this->plan_builder_helper->get_instance();
+
+ }
+
+ public function test_get_plans_by_keys_empty_plans() {
+ $this->assertEquals(array(), $this->alma_plan_helper->get_plans_by_keys());
+ }
+
+ public function test_get_plans_by_keys_empty_eligibilities() {
+ $this->assertEquals(array(), $this->alma_plan_helper->get_plans_by_keys(
+ array(
+ ConstantsHelper::PAY_NOW_FEE_PLAN,
+ )
+ ));
+ }
+
+ public function test_get_plans_by_keys_empty_eligibilities_plans() {
+ $this->assertEquals(
+ array(),
+ $this->alma_plan_helper->get_plans_by_keys(
+ array(),
+ array(
+ ConstantsHelper::PAY_NOW_FEE_PLAN => $this->eligibility_mock ,
+ ConstantsHelper::DEFAULT_FEE_PLAN => $this->eligibility_mock
+ )
+ ));
+ }
+
+ public function test_get_plans_by_keys() {
+ $this->assertEquals(
+ array( ConstantsHelper::PAY_NOW_FEE_PLAN => $this->eligibility_mock ),
+ $this->alma_plan_helper->get_plans_by_keys(
+ array(
+ ConstantsHelper::PAY_NOW_FEE_PLAN,
+ ),
+ array(
+ ConstantsHelper::PAY_NOW_FEE_PLAN => $this->eligibility_mock ,
+ ConstantsHelper::DEFAULT_FEE_PLAN => $this->eligibility_mock
+ )
+ ));
+ }
+
+ public function test_order_plans_empty_array() {
+ $this->assertEquals(array(), $this->alma_plan_helper->order_plans());
+ }
+ public function test_order_plans_empty_plans() {
+ $this->assertEquals(array(), $this->alma_plan_helper->order_plans(array(), ConstantsHelper::GATEWAY_ID));
+ }
+
+ public function test_order_plans_empty_gateway_id() {
+ $alma_settings_mock = \Mockery::mock(AlmaSettings::class)->makePartial();
+ $alma_settings_mock->settings['display_in_page'] = 'no';
+ $alma_settings_mock->shouldReceive('should_display_plan')->andReturn(false);
+
+ $plan_builder_helper = \Mockery::mock(PlanHelperBuilder::class)->makePartial();
+ $plan_builder_helper->shouldReceive('get_alma_settings')->andReturn($alma_settings_mock);
+ $plan_helper = $plan_builder_helper->get_instance();
+ $this->assertEquals(array(), $plan_helper->order_plans(array(ConstantsHelper::PAY_NOW_FEE_PLAN)));
+ }
+
+ public function test_order_plans_no_gateway_id_no_in_page_display_plan_ok() {
+ $this->alma_settings_mock->settings['display_in_page'] = 'no';
+ $this->plan_builder_helper->shouldReceive('get_alma_settings')->andReturn($this->alma_settings_mock);
+ $plan_helper = $this->plan_builder_helper->get_instance();
+
+ $this->assertEquals(array(
+ ConstantsHelper::GATEWAY_ID_PAY_NOW => array(ConstantsHelper::PAY_NOW_FEE_PLAN),
+ ConstantsHelper::GATEWAY_ID => array(ConstantsHelper::DEFAULT_FEE_PLAN),
+ ), $plan_helper->order_plans(array(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::DEFAULT_FEE_PLAN)));
+ }
+
+ public function test_order_plans_no_gateway_id_with_in_page_display_plan_ok() {
+ $this->alma_settings_mock->settings['display_in_page'] = 'yes';
+ $this->plan_builder_helper->shouldReceive('get_alma_settings')->andReturn($this->alma_settings_mock);
+ $plan_helper = $this->plan_builder_helper->get_instance();
+
+ $this->assertEquals(array(
+ ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW => array(ConstantsHelper::PAY_NOW_FEE_PLAN),
+ ConstantsHelper::GATEWAY_ID_IN_PAGE => array(ConstantsHelper::DEFAULT_FEE_PLAN),
+ ), $plan_helper->order_plans(array(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::DEFAULT_FEE_PLAN)));
+ }
+
+ public function test_order_plans_gateway_id_exclude_with_in_page_display_plan_ok() {
+ $this->alma_settings_mock->settings['display_in_page'] = 'yes';
+ $this->plan_builder_helper->shouldReceive('get_alma_settings')->andReturn($this->alma_settings_mock);
+ $plan_helper = $this->plan_builder_helper->get_instance();
+
+ $this->assertEquals(array(), $plan_helper->order_plans(array(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::DEFAULT_FEE_PLAN), ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_LATER));
+ }
+
+ public function test_order_plans_gateway_id_exclude_no_in_page_display_plan_ok() {
+ $this->alma_settings_mock->settings['display_in_page'] = 'no';
+ $this->plan_builder_helper->shouldReceive('get_alma_settings')->andReturn($this->alma_settings_mock);
+ $plan_helper = $this->plan_builder_helper->get_instance();
+
+ $this->assertEquals(array( ), $plan_helper->order_plans(array(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::DEFAULT_FEE_PLAN),ConstantsHelper::GATEWAY_ID_PAY_LATER));
+ }
+
+ public function test_order_plans_gateway_id_with_in_page_display_plan_ok() {
+ $this->alma_settings_mock->settings['display_in_page'] = 'yes';
+ $this->plan_builder_helper->shouldReceive('get_alma_settings')->andReturn($this->alma_settings_mock);
+ $plan_helper = $this->plan_builder_helper->get_instance();
+
+ $this->assertEquals(array(ConstantsHelper::PAY_NOW_FEE_PLAN), $plan_helper->order_plans(array(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::DEFAULT_FEE_PLAN), ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW));
+ }
+
+ public function test_order_plans_gateway_id_no_in_page_display_plan_ok() {
+ $this->alma_settings_mock->settings['display_in_page'] = 'no';
+ $this->plan_builder_helper->shouldReceive('get_alma_settings')->andReturn($this->alma_settings_mock);
+ $plan_helper = $this->plan_builder_helper->get_instance();
+
+ $this->assertEquals(array(ConstantsHelper::DEFAULT_FEE_PLAN ), $plan_helper->order_plans(array(ConstantsHelper::PAY_NOW_FEE_PLAN, ConstantsHelper::DEFAULT_FEE_PLAN),ConstantsHelper::GATEWAY_ID));
+ }
+
+ public function test_render_field_classic_no_default_plan() {
+ $this->assertNull($this->alma_plan_helper->render_fields_classic(
+ array( ConstantsHelper::PAY_NOW_FEE_PLAN ),
+ array( ConstantsHelper::GATEWAY_ID_PAY_NOW => array( ConstantsHelper::PAY_NOW_FEE_PLAN) ),
+ ConstantsHelper::GATEWAY_ID_PAY_NOW
+ ));
+ }
+ public function test_render_field_classic_default_plan() {
+ $this->assertNull($this->alma_plan_helper->render_fields_classic(
+ array( ConstantsHelper::PAY_NOW_FEE_PLAN ),
+ array( ConstantsHelper::GATEWAY_ID_PAY_NOW => array( ConstantsHelper::PAY_NOW_FEE_PLAN) ),
+ ConstantsHelper::GATEWAY_ID_PAY_NOW,
+ ConstantsHelper::DEFAULT_FEE_PLAN
+ ));
+ }
+
+ public function test_render_field_in_page_no_default_plan() {
+ $this->expectOutputString('
');
+ $this->alma_plan_helper->render_fields_in_page(
+ array( ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW => array( ConstantsHelper::PAY_NOW_FEE_PLAN ) ),
+ ConstantsHelper::GATEWAY_ID_IN_PAGE_PAY_NOW
+ ) ;
+ }
+
+ public function test_render_field_in_page_default_plan() {
+ $this->expectOutputString('