-
Notifications
You must be signed in to change notification settings - Fork 68
feat(datatables): add tooltip support and custom button helper #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <?php | ||
|
|
||
| namespace Sebastienheyd\Boilerplate\Tests\Datatables; | ||
|
|
||
| use Sebastienheyd\Boilerplate\Datatables\Button; | ||
| use Sebastienheyd\Boilerplate\Tests\TestCase; | ||
|
|
||
| class ButtonTest extends TestCase | ||
| { | ||
| public function testTooltipMethod() | ||
| { | ||
| $button = Button::add('Test Button') | ||
| ->link('/test') | ||
| ->tooltip('This is a tooltip') | ||
| ->make(); | ||
|
|
||
| $this->assertStringContainsString('title="This is a tooltip"', $button); | ||
| } | ||
|
|
||
| public function testTooltipNotAddedWhenEmpty() | ||
| { | ||
| $button = Button::add('Test Button') | ||
| ->link('/test') | ||
| ->make(); | ||
|
|
||
| $this->assertStringNotContainsString('title=', $button); | ||
| } | ||
|
|
||
| public function testTooltipMethodChaining() | ||
| { | ||
| $button = Button::add('Test') | ||
| ->link('/test') | ||
| ->tooltip('Tooltip text') | ||
| ->color('primary') | ||
| ->icon('star') | ||
| ->make(); | ||
|
|
||
| $this->assertStringContainsString('title="Tooltip text"', $button); | ||
| $this->assertStringContainsString('btn-primary', $button); | ||
| $this->assertStringContainsString('fa-star', $button); | ||
| } | ||
|
|
||
| public function testButtonHtmlStructure() | ||
| { | ||
| $button = Button::add('Click me') | ||
| ->link('/action') | ||
| ->tooltip('Button tooltip') | ||
| ->color('success') | ||
| ->make(); | ||
|
|
||
| $this->assertMatchesRegularExpression('/<a href="\/action" title="Button tooltip" class="btn btn-sm btn-success/', $button); | ||
| } | ||
|
|
||
| public function testCustomButtonWithRoute() | ||
| { | ||
| // Define a test route | ||
| $this->app['router']->get('/test/{id}', function () { | ||
| return 'test'; | ||
| })->name('test.route'); | ||
|
|
||
| $button = Button::custom( | ||
| 'test.route', | ||
| ['id' => 1], | ||
| 'star', | ||
| 'Custom tooltip', | ||
| 'success' | ||
| ); | ||
|
|
||
| $this->assertStringContainsString('title="Custom tooltip"', $button); | ||
| $this->assertStringContainsString('btn-success', $button); | ||
| $this->assertStringContainsString('fa-star', $button); | ||
| $this->assertStringContainsString('/test/1', $button); | ||
| } | ||
|
|
||
| public function testCustomButtonWithAttributes() | ||
| { | ||
| $this->app['router']->get('/test', function () { | ||
| return 'test'; | ||
| })->name('test.route2'); | ||
|
|
||
| $button = Button::custom( | ||
| 'test.route2', | ||
| [], | ||
| 'heart', | ||
| 'Custom tooltip', | ||
| 'primary', | ||
| ['data-action' => 'custom-action', 'data-id' => '123'] | ||
| ); | ||
|
|
||
| $this->assertStringContainsString('data-action="custom-action"', $button); | ||
| $this->assertStringContainsString('data-id="123"', $button); | ||
| $this->assertStringContainsString('btn-primary', $button); | ||
| $this->assertStringContainsString('fa-heart', $button); | ||
| } | ||
|
|
||
| public function testCustomButtonWithDefaults() | ||
| { | ||
| $this->app['router']->get('/default', function () { | ||
| return 'test'; | ||
| })->name('test.default'); | ||
|
|
||
| $button = Button::custom('test.default'); | ||
|
|
||
| $this->assertStringNotContainsString('title=', $button); | ||
| $this->assertStringContainsString('btn-default', $button); | ||
| $this->assertStringNotContainsString('fa-', $button); // No icon by default | ||
| } | ||
|
|
||
| public function testCustomButtonArgumentOrder() | ||
| { | ||
| // Test that $icon comes before $tooltip in the method signature | ||
| $this->app['router']->get('/order', function () { | ||
| return 'test'; | ||
| })->name('test.order'); | ||
|
|
||
| $button = Button::custom( | ||
| 'test.order', | ||
| [], | ||
| 'cog', // $icon (3rd parameter) | ||
| 'Tooltip', // $tooltip (4th parameter) | ||
| 'warning' // $color (5th parameter) | ||
| ); | ||
|
|
||
| $this->assertStringContainsString('fa-cog', $button); | ||
| $this->assertStringContainsString('title="Tooltip"', $button); | ||
| $this->assertStringContainsString('btn-warning', $button); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Button::custom()narrows$argstoarray|string, which breaks the model-object usage that existing helpers already support (for exampleButton::edit(..., $role)in the codebase). In PHP this can coerce an Eloquent model to a JSON string via__toString(), soroute()receives the wrong parameter value and generates incorrect URLs; for non-stringable objects it will throw aTypeError. Matching themixedbehavior used byshow/edit/deleteavoids this regression.Useful? React with 👍 / 👎.