1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/tests/Feature/ClientModelTest.php

113 lines
3.4 KiB
PHP
Raw Normal View History

2019-09-18 14:43:37 +02:00
<?php
2020-09-14 13:11:46 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
2019-09-18 14:43:37 +02:00
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;
2019-09-18 14:43:37 +02:00
use DatabaseTransactions;
public function setUp() :void
{
parent::setUp();
$this->makeTestData();
2019-09-18 14:43:37 +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()
{
$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.
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];
}
}
$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) {
$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
$this->assertEquals(4, count($payment_urls));
}
2019-09-18 14:43:37 +02:00
}