Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Notifynder/Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getCustomFillableFields()
*/
protected function mergeFillables()
{
$fillables = array_unique($this->getFillable() + $this->getCustomFillableFields());
$fillables = array_unique(array_merge($this->getFillable(), $this->getCustomFillableFields()));

return $fillables;
}
Expand Down
22 changes: 22 additions & 0 deletions src/Notifynder/Traits/Notifable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ trait Notifable
{
use NotifableBasic;

/**
* Define a polymorphic one-to-many relationship.
*
* @param string $related
* @param string $name
* @param string $type
* @param string $id
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);

/**
* Define a one-to-many relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
abstract public function hasMany($related, $foreignKey = null, $localKey = null);

/**
* Get the notifications Relationship.
*
Expand Down
22 changes: 22 additions & 0 deletions src/Notifynder/Traits/NotifableLaravel53.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ trait NotifableLaravel53
{
use NotifableBasic;

/**
* Define a polymorphic one-to-many relationship.
*
* @param string $related
* @param string $name
* @param string $type
* @param string $id
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);

/**
* Define a one-to-many relationship.
*
* @param string $related
* @param string $foreignKey
* @param string $localKey
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
abstract public function hasMany($related, $foreignKey = null, $localKey = null);

/**
* Get the notifications Relationship.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/Collections/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ public function testGetNotifiedModelFail()
}

public function testGetAdditionalFields()
{
$config = app('notifynder.config');
$config->set('additional_fields.fillable', ['fillable_field']);
$config->set('additional_fields.required', ['required_field']);
$this->assertInternalType('array', $config->getAdditionalFields());
$this->assertCount(2, $config->getAdditionalFields());
$this->assertSame(['required_field', 'fillable_field'], $config->getAdditionalFields());
}

public function testGetAdditionalFieldsFillable()
{
$config = app('notifynder.config');
$config->set('additional_fields.fillable', ['fillable_field']);
$this->assertInternalType('array', $config->getAdditionalFields());
$this->assertSame(['fillable_field'], $config->getAdditionalFields());
}

public function testGetAdditionalFieldsRequired()
{
$config = app('notifynder.config');
$config->set('additional_fields.required', ['required_field']);
$this->assertInternalType('array', $config->getAdditionalFields());
$this->assertSame(['required_field'], $config->getAdditionalFields());
}

public function testGetAdditionalFieldsEmpty()
{
$config = app('notifynder.config');
$this->assertInternalType('array', $config->getAdditionalFields());
Expand Down
89 changes: 89 additions & 0 deletions tests/integration/Models/NotificationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

use Fenos\Notifynder\Models\Notification;

class NotificationTest extends NotifynderTestCase
{
public function testFillablesEmpty()
{
$notification = new Notification();
$this->assertInternalType('array', $notification->getFillable());
$this->assertSame([
'to_id',
'to_type',
'from_id',
'from_type',
'category_id',
'read',
'url',
'extra',
'expires_at',
'stack_id',
], $notification->getFillable());
}

public function testFillablesCustomFillables()
{
$config = app('notifynder.config');
$config->set('additional_fields.fillable', ['fillable_field']);
$notification = new Notification();
$this->assertInternalType('array', $notification->getFillable());
$this->assertSame([
'to_id',
'to_type',
'from_id',
'from_type',
'category_id',
'read',
'url',
'extra',
'expires_at',
'stack_id',
'fillable_field',
], $notification->getFillable());
}

public function testFillablesCustomRequired()
{
$config = app('notifynder.config');
$config->set('additional_fields.required', ['required_field']);
$notification = new Notification();
$this->assertInternalType('array', $notification->getFillable());
$this->assertSame([
'to_id',
'to_type',
'from_id',
'from_type',
'category_id',
'read',
'url',
'extra',
'expires_at',
'stack_id',
'required_field',
], $notification->getFillable());
}

public function testFillablesCustom()
{
$config = app('notifynder.config');
$config->set('additional_fields.fillable', ['fillable_field']);
$config->set('additional_fields.required', ['required_field']);
$notification = new Notification();
$this->assertInternalType('array', $notification->getFillable());
$this->assertSame([
'to_id',
'to_type',
'from_id',
'from_type',
'category_id',
'read',
'url',
'extra',
'expires_at',
'stack_id',
'required_field',
'fillable_field',
], $notification->getFillable());
}
}