Files
monica/tests/Unit/RelationshipTypeTest.php
T
2018-04-05 00:02:43 +02:00

142 lines
4.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class RelationshipTypeTest extends TestCase
{
use DatabaseTransactions;
public function test_it_belongs_to_an_account()
{
$account = factory('App\Account')->create([]);
$relationshipType = factory('App\RelationshipType')->create([
'account_id' => $account->id,
]);
$this->assertTrue($relationshipType->account()->exists());
}
public function test_it_belongs_to_an_relationship_type_group()
{
$account = factory('App\Account')->create([]);
$relationshipTypeGroup = factory('App\RelationshipTypeGroup')->create([
'account_id' => $account->id,
]);
$this->assertTrue($relationshipTypeGroup->account()->exists());
}
public function test_it_gets_the_masculine_short_name_of_the_relationship_type()
{
$account = factory('App\Account')->create([]);
$relationshipType = factory('App\RelationshipType')->create([
'account_id' => $account->id,
'name' => 'uncle',
'name_reverse_relationship' => 'nephew',
]);
$this->assertEquals(
'uncle',
$relationshipType->getLocalizedName()
);
}
public function test_it_gets_the_feminine_short_name_of_the_relationship_type()
{
$account = factory('App\Account')->create([]);
$relationshipType = factory('App\RelationshipType')->create([
'account_id' => $account->id,
'name' => 'uncle',
'name_reverse_relationship' => 'nephew',
]);
$this->assertEquals(
'aunt',
$relationshipType->getLocalizedName(null, false, 'woman')
);
}
public function test_it_gets_the_masculine_name_of_the_relationship_type_with_the_name_of_the_contact()
{
$account = factory('App\Account')->create([]);
$relationshipType = factory('App\RelationshipType')->create([
'account_id' => $account->id,
'name' => 'uncle',
'name_reverse_relationship' => 'nephew',
]);
$contact = factory('App\Contact')->create([
'account_id' => $account->id,
'first_name' => 'Mark',
'last_name' => 'Twain',
]);
$this->assertEquals(
'Mark Twains uncle',
$relationshipType->getLocalizedName($contact, false, 'man')
);
}
public function test_it_gets_the_feminine_name_of_the_relationship_type_with_the_name_of_the_contact()
{
$account = factory('App\Account')->create([]);
$relationshipType = factory('App\RelationshipType')->create([
'account_id' => $account->id,
'name' => 'uncle',
'name_reverse_relationship' => 'nephew',
]);
$contact = factory('App\Contact')->create([
'account_id' => $account->id,
'first_name' => 'Mark',
'last_name' => 'Twain',
]);
$this->assertEquals(
'Mark Twains aunt',
$relationshipType->getLocalizedName($contact, false, 'woman')
);
}
public function test_it_gets_both_names_of_the_relationship_type_with_the_name_of_the_contact_and_the_opposite_version()
{
$account = factory('App\Account')->create([]);
$relationshipType = factory('App\RelationshipType')->create([
'account_id' => $account->id,
'name' => 'uncle',
'name_reverse_relationship' => 'nephew',
]);
$contact = factory('App\Contact')->create([
'account_id' => $account->id,
'first_name' => 'Mark',
'last_name' => 'Twain',
]);
$this->assertEquals(
'Mark Twains uncle/aunt',
$relationshipType->getLocalizedName($contact, true)
);
}
public function test_it_gets_only_one_name_of_the_relationship_type_if_name_and_name_reverse_are_similar()
{
$account = factory('App\Account')->create([]);
$relationshipType = factory('App\RelationshipType')->create([
'account_id' => $account->id,
'name' => 'partner',
'name_reverse_relationship' => 'partner',
]);
$contact = factory('App\Contact')->create([
'account_id' => $account->id,
'first_name' => 'Mark',
'last_name' => 'Twain',
]);
$this->assertEquals(
'Mark Twains significant other',
$relationshipType->getLocalizedName($contact, true)
);
}
}