1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/tests/Feature/ClientModelTest.php

109 lines
3.0 KiB
PHP
Raw Normal View History

2019-09-18 14:43:37 +02:00
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\URL;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
* @covers App\Models\Client
*/
class ClientModelTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
public function setUp() :void
{
parent::setUp();
$this->makeTestData();
2019-10-07 13:05:06 +02:00
if(config('ninja.testvars.travis') !== false)
2019-10-07 08:43:19 +02:00
$this->markTestSkipped('Skip test for Travis');
if(!config('ninja.testvars.stripe'))
$this->markTestSkipped('Skip test no company gateways installed');
2019-09-18 14:43:37 +02:00
}
public function testPaymentMethods()
{
2019-10-04 12:20:02 +02:00
$amount = 40;
2019-09-18 14:43:37 +02:00
$company_gateways = $this->client->getSetting('company_gateway_ids');
2019-09-18 14:43:37 +02:00
//todo create a test where we actually SET a value in the settings->company_gateways object and test if we can harvest.
2019-09-18 14:43:37 +02:00
if($company_gateways)
$gateways = $this->company->company_gateways->whereIn('id', $payment_gateways);
else
$gateways = $this->company->company_gateways;
2019-09-18 14:43:37 +02:00
$this->assertNotNull($gateways);
2019-09-18 14:43:37 +02:00
$pre_count = $gateways->count();
2019-09-18 14:43:37 +02:00
$gateways->filter(function ($method) use ($amount){
if($method->min_limit !== null && $amount < $method->min_limit)
return false;
2019-09-18 14:43:37 +02:00
if($method->max_limit !== null && $amount > $method->min_limit)
return false;
});
2019-09-18 14:43:37 +02:00
$post_count = $gateways->count();
2019-09-18 14:43:37 +02:00
$this->assertEquals($pre_count, $post_count);
2019-09-18 14:43:37 +02:00
$payment_methods = [];
2019-09-18 14:43:37 +02:00
foreach($gateways as $gateway)
foreach($gateway->driver($this->client)->gatewayTypes() as $type)
$payment_methods[] = [$gateway->id => $type];
2019-09-18 14:43:37 +02:00
$this->assertEquals(8, count($payment_methods));
2019-09-18 14:43:37 +02:00
$payment_methods_collections = collect($payment_methods);
2019-09-18 14:43:37 +02:00
//** Plucks the remaining keys into its own collection
$payment_methods_intersect = $payment_methods_collections->intersectByKeys( $payment_methods_collections->flatten(1)->unique() );
2019-09-18 14:43:37 +02:00
$this->assertEquals(4, $payment_methods_intersect->count());
2019-09-18 14:43:37 +02:00
$payment_urls = [];
2019-09-18 14:43:37 +02:00
foreach($payment_methods_intersect as $key => $child_array)
{
foreach($child_array as $gateway_id => $gateway_type_id)
{
2019-09-18 14:43:37 +02:00
$gateway = $gateways->where('id', $gateway_id)->first();
2019-09-18 14:43:37 +02:00
$this->assertNotNull($gateway);
2019-09-18 14:43:37 +02:00
$fee_label = $gateway->calcGatewayFeeLabel($amount, $this->client);
2019-09-18 14:43:37 +02:00
$payment_urls[] = [
'label' => ctrans('texts.' . $gateway->getTypeAlias($gateway_type_id)) . $fee_label,
'url' => URL::signedRoute('client.payments.process', [
'company_gateway_id' => $gateway_id,
'gateway_type_id' => $gateway_type_id])
];
}
2019-09-18 14:43:37 +02:00
}
2019-09-18 14:43:37 +02:00
$this->assertEquals(4, count($payment_urls));
}
2019-09-18 14:43:37 +02:00
}