Skip to content

Commit fa9d1a3

Browse files
authored
Merge pull request #279 from fenos/develop
Develop
2 parents 0d536e6 + 21fff35 commit fa9d1a3

File tree

5 files changed

+160
-1
lines changed

5 files changed

+160
-1
lines changed

src/Notifynder/Models/Notification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function getCustomFillableFields()
119119
*/
120120
protected function mergeFillables()
121121
{
122-
$fillables = array_unique($this->getFillable() + $this->getCustomFillableFields());
122+
$fillables = array_unique(array_merge($this->getFillable(), $this->getCustomFillableFields()));
123123

124124
return $fillables;
125125
}

src/Notifynder/Traits/Notifable.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@ trait Notifable
1111
{
1212
use NotifableBasic;
1313

14+
/**
15+
* Define a polymorphic one-to-many relationship.
16+
*
17+
* @param string $related
18+
* @param string $name
19+
* @param string $type
20+
* @param string $id
21+
* @param string $localKey
22+
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
23+
*/
24+
abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);
25+
26+
/**
27+
* Define a one-to-many relationship.
28+
*
29+
* @param string $related
30+
* @param string $foreignKey
31+
* @param string $localKey
32+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
33+
*/
34+
abstract public function hasMany($related, $foreignKey = null, $localKey = null);
35+
1436
/**
1537
* Get the notifications Relationship.
1638
*

src/Notifynder/Traits/NotifableLaravel53.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@ trait NotifableLaravel53
1111
{
1212
use NotifableBasic;
1313

14+
/**
15+
* Define a polymorphic one-to-many relationship.
16+
*
17+
* @param string $related
18+
* @param string $name
19+
* @param string $type
20+
* @param string $id
21+
* @param string $localKey
22+
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
23+
*/
24+
abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);
25+
26+
/**
27+
* Define a one-to-many relationship.
28+
*
29+
* @param string $related
30+
* @param string $foreignKey
31+
* @param string $localKey
32+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
33+
*/
34+
abstract public function hasMany($related, $foreignKey = null, $localKey = null);
35+
1436
/**
1537
* Get the notifications Relationship.
1638
*

tests/integration/Collections/ConfigTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ public function testGetNotifiedModelFail()
3939
}
4040

4141
public function testGetAdditionalFields()
42+
{
43+
$config = app('notifynder.config');
44+
$config->set('additional_fields.fillable', ['fillable_field']);
45+
$config->set('additional_fields.required', ['required_field']);
46+
$this->assertInternalType('array', $config->getAdditionalFields());
47+
$this->assertCount(2, $config->getAdditionalFields());
48+
$this->assertSame(['required_field', 'fillable_field'], $config->getAdditionalFields());
49+
}
50+
51+
public function testGetAdditionalFieldsFillable()
52+
{
53+
$config = app('notifynder.config');
54+
$config->set('additional_fields.fillable', ['fillable_field']);
55+
$this->assertInternalType('array', $config->getAdditionalFields());
56+
$this->assertSame(['fillable_field'], $config->getAdditionalFields());
57+
}
58+
59+
public function testGetAdditionalFieldsRequired()
60+
{
61+
$config = app('notifynder.config');
62+
$config->set('additional_fields.required', ['required_field']);
63+
$this->assertInternalType('array', $config->getAdditionalFields());
64+
$this->assertSame(['required_field'], $config->getAdditionalFields());
65+
}
66+
67+
public function testGetAdditionalFieldsEmpty()
4268
{
4369
$config = app('notifynder.config');
4470
$this->assertInternalType('array', $config->getAdditionalFields());
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
use Fenos\Notifynder\Models\Notification;
4+
5+
class NotificationTest extends NotifynderTestCase
6+
{
7+
public function testFillablesEmpty()
8+
{
9+
$notification = new Notification();
10+
$this->assertInternalType('array', $notification->getFillable());
11+
$this->assertSame([
12+
'to_id',
13+
'to_type',
14+
'from_id',
15+
'from_type',
16+
'category_id',
17+
'read',
18+
'url',
19+
'extra',
20+
'expires_at',
21+
'stack_id',
22+
], $notification->getFillable());
23+
}
24+
25+
public function testFillablesCustomFillables()
26+
{
27+
$config = app('notifynder.config');
28+
$config->set('additional_fields.fillable', ['fillable_field']);
29+
$notification = new Notification();
30+
$this->assertInternalType('array', $notification->getFillable());
31+
$this->assertSame([
32+
'to_id',
33+
'to_type',
34+
'from_id',
35+
'from_type',
36+
'category_id',
37+
'read',
38+
'url',
39+
'extra',
40+
'expires_at',
41+
'stack_id',
42+
'fillable_field',
43+
], $notification->getFillable());
44+
}
45+
46+
public function testFillablesCustomRequired()
47+
{
48+
$config = app('notifynder.config');
49+
$config->set('additional_fields.required', ['required_field']);
50+
$notification = new Notification();
51+
$this->assertInternalType('array', $notification->getFillable());
52+
$this->assertSame([
53+
'to_id',
54+
'to_type',
55+
'from_id',
56+
'from_type',
57+
'category_id',
58+
'read',
59+
'url',
60+
'extra',
61+
'expires_at',
62+
'stack_id',
63+
'required_field',
64+
], $notification->getFillable());
65+
}
66+
67+
public function testFillablesCustom()
68+
{
69+
$config = app('notifynder.config');
70+
$config->set('additional_fields.fillable', ['fillable_field']);
71+
$config->set('additional_fields.required', ['required_field']);
72+
$notification = new Notification();
73+
$this->assertInternalType('array', $notification->getFillable());
74+
$this->assertSame([
75+
'to_id',
76+
'to_type',
77+
'from_id',
78+
'from_type',
79+
'category_id',
80+
'read',
81+
'url',
82+
'extra',
83+
'expires_at',
84+
'stack_id',
85+
'required_field',
86+
'fillable_field',
87+
], $notification->getFillable());
88+
}
89+
}

0 commit comments

Comments
 (0)