2019-02-17 11:34:46 +01:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-14 13:11:46 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
2021-11-15 11:46:58 +01:00
|
|
|
use App\Factory\ClientContactFactory;
|
2021-10-24 22:25:14 +02:00
|
|
|
use App\Factory\InvoiceItemFactory;
|
2019-02-17 11:34:46 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
class CollectionMergingTest extends TestCase
|
|
|
|
{
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp() :void
|
2019-02-17 11:34:46 +01:00
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
parent::setUp();
|
2019-02-17 11:34:46 +01:00
|
|
|
}
|
|
|
|
|
2019-09-09 04:19:19 +02:00
|
|
|
public function testUniqueValues()
|
|
|
|
{
|
|
|
|
$methods[] = [1 => 1];
|
|
|
|
$methods[] = [1 => 2];
|
|
|
|
$methods[] = [1 => 3];
|
|
|
|
$methods[] = [1 => 4];
|
|
|
|
$methods[] = [1 => 5];
|
|
|
|
$methods[] = [1 => 6];
|
|
|
|
|
|
|
|
$other_methods[] = [2 => 1];
|
|
|
|
$other_methods[] = [2 => 7];
|
|
|
|
$other_methods[] = [2 => 8];
|
|
|
|
$other_methods[] = [2 => 9];
|
|
|
|
$other_methods[] = [2 => 10];
|
|
|
|
|
|
|
|
$array = array_merge($methods, $other_methods);
|
|
|
|
|
|
|
|
$this->assertEquals(11, count($array));
|
|
|
|
|
|
|
|
$collection = collect($array);
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$intersect = $collection->intersectByKeys($collection->flatten(1)->unique());
|
2019-09-09 04:19:19 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals(10, $intersect->count());
|
2019-09-09 04:19:19 +02:00
|
|
|
|
|
|
|
$third_methods[] = [3 => 1];
|
|
|
|
$third_methods[] = [2 => 11];
|
|
|
|
|
|
|
|
$array = array_merge($array, $third_methods);
|
|
|
|
|
|
|
|
$collection = collect($array);
|
2020-03-21 06:37:30 +01:00
|
|
|
$intersect = $collection->intersectByKeys($collection->flatten(1)->unique());
|
|
|
|
$this->assertEquals(11, $intersect->count());
|
2019-09-09 04:19:19 +02:00
|
|
|
}
|
2021-10-24 22:25:14 +02:00
|
|
|
|
|
|
|
public function testExistenceInCollection()
|
|
|
|
{
|
|
|
|
$items = InvoiceItemFactory::generate(5);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->assertFalse(collect($items)->contains('type_id', '3'));
|
2021-10-24 22:25:14 +02:00
|
|
|
$this->assertFalse(collect($items)->contains('type_id', 3));
|
|
|
|
|
|
|
|
$item = InvoiceItemFactory::create();
|
2022-06-21 11:57:17 +02:00
|
|
|
$item->type_id = '3';
|
2021-10-24 22:25:14 +02:00
|
|
|
$items[] = $item;
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->assertTrue(collect($items)->contains('type_id', '3'));
|
2021-10-24 22:25:14 +02:00
|
|
|
$this->assertTrue(collect($items)->contains('type_id', 3));
|
|
|
|
}
|
2021-11-15 11:46:58 +01:00
|
|
|
|
|
|
|
public function testClientContactSendEmailExists()
|
|
|
|
{
|
|
|
|
$new_collection = collect();
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$cc = ClientContactFactory::create(1, 1);
|
2021-11-15 11:46:58 +01:00
|
|
|
$cc->send_email = true;
|
|
|
|
|
|
|
|
$new_collection->push($cc);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$cc_false = ClientContactFactory::create(1, 1);
|
2021-11-15 11:46:58 +01:00
|
|
|
$cc_false->send_email = false;
|
|
|
|
|
|
|
|
$new_collection->push($cc_false);
|
|
|
|
|
|
|
|
$this->assertTrue($new_collection->contains('send_email', true));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testClientContactSendEmailDoesNotExists()
|
|
|
|
{
|
|
|
|
$new_collection = collect();
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$cc = ClientContactFactory::create(1, 1);
|
2021-11-15 11:46:58 +01:00
|
|
|
$cc->send_email = false;
|
|
|
|
|
|
|
|
$new_collection->push($cc);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$cc_false = ClientContactFactory::create(1, 1);
|
2021-11-15 11:46:58 +01:00
|
|
|
$cc_false->send_email = false;
|
|
|
|
|
|
|
|
$new_collection->push($cc_false);
|
|
|
|
|
|
|
|
$this->assertFalse($new_collection->contains('send_email', true));
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
}
|