diff --git a/src/ColumnSortable/SortableLink.php b/src/ColumnSortable/SortableLink.php
index e4acd7a..320fd8f 100644
--- a/src/ColumnSortable/SortableLink.php
+++ b/src/ColumnSortable/SortableLink.php
@@ -261,6 +261,10 @@ private static function buildQueryString($queryParameters, $sortParameter, $dire
private static function buildAnchorAttributesString($anchorAttributes)
{
+ if (empty($anchorAttributes)) {
+ return '';
+ }
+
$attributes = [];
foreach ($anchorAttributes as $k => $v) {
$attributes[] = $k.('' != $v ? '="'.$v.'"' : '');
diff --git a/tests/SortableLinkTest.php b/tests/SortableLinkTest.php
index 5853f79..2113640 100644
--- a/tests/SortableLinkTest.php
+++ b/tests/SortableLinkTest.php
@@ -53,6 +53,20 @@ public function testInjectTitleInQueryStringsIsOff()
$this->assertEquals([], Request::all());
}
+ public function testGeneratingAnchorAttributes()
+ {
+ $link = SortableLink::render(['column', 'ColumnTitle', ['a' => 'b'], ['c' => 'd']]);
+
+ $this->assertSame('ColumnTitle', $link);
+ }
+
+ public function testGeneratingTitleWithoutFormattingFunction()
+ {
+ Config::set('columnsortable.formatting_function', null);
+ $link = SortableLink::render(['column']);
+
+ $this->assertSame('column', $link);
+ }
public function testGeneratingTitle()
{
@@ -60,7 +74,7 @@ public function testGeneratingTitle()
Config::set('columnsortable.format_custom_titles', true);
$link = SortableLink::render(['column']);
- $this->assertSame('Column', $link);
+ $this->assertSame('Column', $link);
}
@@ -70,7 +84,7 @@ public function testCustomTitle()
Config::set('columnsortable.format_custom_titles', true);
$link = SortableLink::render(['column', 'columnTitle']);
- $this->assertSame('ColumnTitle', $link);
+ $this->assertSame('ColumnTitle', $link);
}
@@ -80,7 +94,7 @@ public function testCustomTitleWithoutFormatting()
Config::set('columnsortable.format_custom_titles', false);
$link = SortableLink::render(['column', 'columnTitle']);
- $this->assertSame('columnTitle', $link);
+ $this->assertSame('columnTitle', $link);
}
@@ -90,7 +104,7 @@ public function testCustomTitleWithHTML()
Config::set('columnsortable.format_custom_titles', true);
$link = SortableLink::render(['column', new HtmlString('columnTitle')]);
- $this->assertSame('columnTitle', $link);
+ $this->assertSame('columnTitle', $link);
}