Files
monica/tests/Unit/DayTest.php
T
Tom RochetteandRégis Freyd d2c9c75644 Fix tests to prepare for foreign keys (#1289)
* Fix AccountTest tests.
Update the model factories not to expect a constant value for account_id.
Add various missing relationships in the model factories.

* Fix AddressTest after the addition of foreign keys.

* Fix ContactTest after the addition of foreign keys.
Set contact/account before saving a special date using Contact::setSpecialDate or Contact::setSpecialDateFromAge.

* Fix DayTest after the addition of foreign keys.

* Fix EntryTest after the addition of foreign keys.

* Fix GiftTest after the addition of foreign keys.

* Fix JournalEntryTest after the addition of foreign keys.

* Fix NoteTest after the addition of foreign keys.

* Fix NotificationTest after the addition of foreign keys.

* Fix PetTest after the addition of foreign keys.

* Return the account id and not the account object in many model factories definition.

* Fix ReminderTest after the addition of foreign keys.

* Fix SpecialDateTest after the addition of foreign keys.

* Fix UserTest after the addition of foreign keys.

* Make instead of creating in Contact::logEvent() as we cannot create an event without giving it an account_id.

* Fix ActivityTest after the addition of foreign keys.

* Fix SendNotificationsTest after the addition of foreign keys.

* Fix SendNotificationsTest after the addition of foreign keys.
- Remove the test_it_deletes_the_notification_if_contact_does_not_exist test because on deletion of a contact, all his associated notifications will be deleted due to cascade constraints.

* Fix SendRemindersTest after the addition of foreign keys.
- Remove the test_it_deletes_the_reminder_if_contact_doesnt_exist test because on deletion of a contact, all his associated reminders will be deleted due to cascade constraints.

* Fix TagTest after the addition of foreign keys.

* Update the logic in Contact::removeSpecialDate so that a foreign key constraint is not triggered when removing the associated relation.
Set a the partner gender before saving the partner as the gender is mandatory.
Add the ConvertEmptyStringsToNull middleware.
Set the metThroughId default option as empty so it is converted to null by the ConvertEmptyStringsToNull middleware.
Set the activity_type_id as empty so it is converted to null by the ConvertEmptyStringsToNull middleware.
Mark the Reminder title has required.
2018-05-08 21:33:12 -04:00

73 lines
3.2 KiB
PHP

<?php
namespace Tests\Unit;
use App\Day;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class DayTest extends TestCase
{
use DatabaseTransactions;
public function test_get_info_for_journal_entry_that_doesnt_happen_today()
{
$day = factory(Day::class)->make();
$day->id = 1;
$day->rate = 1;
$day->comment = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor.';
$day->date = '2017-01-01 00:00:00';
$day->created_at = '2017-01-01 00:00:00';
$day->save();
$data = [
'type' => 'day',
'id' => 1,
'rate' => 1,
'comment' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor.',
'day' => 1,
'day_name' => 'Sun',
'month' => 1,
'month_name' => 'JAN',
'year' => 2017,
'happens_today' => false,
];
$this->assertEquals(
$data,
$day->getInfoForJournalEntry()
);
}
public function test_get_info_for_journal_entry_that_happen_today()
{
$date = now();
$day = factory(Day::class)->make();
$day->id = 1;
$day->rate = 1;
$day->comment = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor.';
$day->date = $date;
$day->created_at = '2017-01-01 00:00:00';
$day->save();
$data = [
'type' => 'day',
'id' => 1,
'rate' => 1,
'comment' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor.',
'day' => $date->day,
'day_name' => $date->format('D'),
'month' => $date->month,
'month_name' => strtoupper($date->format('M')),
'year' => $date->year,
'happens_today' => true,
];
$this->assertEquals(
$data,
$day->getInfoForJournalEntry()
);
}
}