Skip to content

Commit 6cebc7f

Browse files
committed
Add missing tests - correct attribute to respect defaults
1 parent 90900d8 commit 6cebc7f

File tree

2 files changed

+75
-17
lines changed

2 files changed

+75
-17
lines changed

src/Traits/Core/HasCustomAttributes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function getCustomAttributes(string $propertyName, bool $default = false,
2121
return $vals;
2222
}
2323

24-
return ['default' => true, 'default-colors' => true, 'default-styling' => true];
24+
return ['default' => $default, 'default-colors' => $default, 'default-styling' => $default];
2525
} else {
2626
if ($this->hasCustomAttributes($propertyName)) {
2727
$vals = array_merge(['default-colors' => $default, 'default-styling' => $default], $this->{$propertyName});
@@ -30,7 +30,7 @@ public function getCustomAttributes(string $propertyName, bool $default = false,
3030
return $vals;
3131
}
3232

33-
return ['default-colors' => true, 'default-styling' => true];
33+
return ['default-colors' => $default, 'default-styling' => $default];
3434

3535
}
3636
}

tests/Traits/Core/CustomAttributesTest.php

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,99 @@
33
namespace Rappasoft\LaravelLivewireTables\Tests\Traits\Core;
44

55
use PHPUnit\Framework\Attributes\DataProvider;
6+
use PHPUnit\Framework\Attributes\Depends;
67
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
8+
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
79

810
final class CustomAttributesTest extends TestCase
911
{
12+
1013
public function test_can_get_custom_attribute_defaults_false_standard_mode(): void
1114
{
15+
$mock = new class extends PetsTable
16+
{
17+
public ?array $testAttributesArray;
18+
19+
public function configure(): void
20+
{
21+
$this->setDataTableFingerprint('test');
22+
}
23+
};
24+
25+
$mock->configure();
26+
$mock->boot();
27+
28+
1229
$this->assertSame([
13-
'default' => false,
14-
'default-colors' => true,
15-
'default-styling' => true,
16-
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', false, true));
30+
'default' => false,
31+
'default-colors' => false,
32+
'default-styling' => false
33+
], $mock->getCustomAttributes('testAttributesArray', false, true));
1734
}
1835

1936
public function test_can_get_custom_attribute_defaults_false_classic_mode(): void
2037
{
38+
$mock = new class extends PetsTable
39+
{
40+
public ?array $testAttributesArray;
41+
42+
public function configure(): void
43+
{
44+
$this->setDataTableFingerprint('test');
45+
}
46+
};
47+
48+
$mock->configure();
49+
$mock->boot();
50+
2151
$this->assertSame([
22-
'default-colors' => true,
23-
'default-styling' => true,
24-
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', false, false));
52+
'default-colors' => false,
53+
'default-styling' => false
54+
], $mock->getCustomAttributes('testAttributesArray', false, false));
2555
}
2656

2757
public function test_can_get_custom_attribute_defaults_true_standard_mode(): void
2858
{
59+
$mock = new class extends PetsTable
60+
{
61+
public ?array $testAttributesArray;
62+
63+
public function configure(): void
64+
{
65+
$this->setDataTableFingerprint('test');
66+
}
67+
};
68+
69+
$mock->configure();
70+
$mock->boot();
71+
2972
$this->assertSame([
30-
'default' => true,
31-
'default-colors' => true,
32-
'default-styling' => true,
33-
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', true, true));
73+
'default' => true,
74+
'default-colors' => true,
75+
'default-styling' => true
76+
], $mock->getCustomAttributes('testAttributesArray', true, true));
3477
}
3578

3679
public function test_can_get_custom_attribute_defaults_true_classic_mode(): void
3780
{
81+
$mock = new class extends PetsTable
82+
{
83+
public ?array $testAttributesArray;
84+
85+
public function configure(): void
86+
{
87+
$this->setDataTableFingerprint('test');
88+
}
89+
};
90+
91+
$mock->configure();
92+
$mock->boot();
93+
3894
$this->assertSame([
39-
'default-colors' => true,
40-
'default-styling' => true,
41-
], $this->basicTable->getCustomAttributes('bulkActionsButtonAttributes', true, false));
95+
'default-colors' => true,
96+
'default-styling' => true
97+
], $mock->getCustomAttributes('testAttributesArray', true, false));
4298
}
43-
}
99+
100+
101+
}

0 commit comments

Comments
 (0)