Skip to content

Commit

Permalink
Add more tests & improve anchor attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyslik committed Mar 1, 2020
1 parent d157986 commit 29f7c90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/ColumnSortable/SortableLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'"' : '');
Expand Down
22 changes: 18 additions & 4 deletions tests/SortableLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,28 @@ public function testInjectTitleInQueryStringsIsOff()
$this->assertEquals([], Request::all());
}

public function testGeneratingAnchorAttributes()
{
$link = SortableLink::render(['column', 'ColumnTitle', ['a' => 'b'], ['c' => 'd']]);

$this->assertSame('<a href="http://localhost?a=b&sort=column&direction=asc" c="d">ColumnTitle</a><i class=""></i>', $link);
}

public function testGeneratingTitleWithoutFormattingFunction()
{
Config::set('columnsortable.formatting_function', null);
$link = SortableLink::render(['column']);

$this->assertSame('<a href="http://localhost?sort=column&direction=asc">column</a><i class=""></i>', $link);
}

public function testGeneratingTitle()
{
Config::set('columnsortable.formatting_function', 'ucfirst');
Config::set('columnsortable.format_custom_titles', true);
$link = SortableLink::render(['column']);

$this->assertSame('<a href="http://localhost?sort=column&direction=asc" >Column</a><i class=""></i>', $link);
$this->assertSame('<a href="http://localhost?sort=column&direction=asc">Column</a><i class=""></i>', $link);
}


Expand All @@ -70,7 +84,7 @@ public function testCustomTitle()
Config::set('columnsortable.format_custom_titles', true);
$link = SortableLink::render(['column', 'columnTitle']);

$this->assertSame('<a href="http://localhost?sort=column&direction=asc" >ColumnTitle</a><i class=""></i>', $link);
$this->assertSame('<a href="http://localhost?sort=column&direction=asc">ColumnTitle</a><i class=""></i>', $link);
}


Expand All @@ -80,7 +94,7 @@ public function testCustomTitleWithoutFormatting()
Config::set('columnsortable.format_custom_titles', false);
$link = SortableLink::render(['column', 'columnTitle']);

$this->assertSame('<a href="http://localhost?sort=column&direction=asc" >columnTitle</a><i class=""></i>', $link);
$this->assertSame('<a href="http://localhost?sort=column&direction=asc">columnTitle</a><i class=""></i>', $link);
}


Expand All @@ -90,7 +104,7 @@ public function testCustomTitleWithHTML()
Config::set('columnsortable.format_custom_titles', true);
$link = SortableLink::render(['column', new HtmlString('<em>columnTitle</em>')]);

$this->assertSame('<a href="http://localhost?sort=column&direction=asc" ><em>columnTitle</em></a><i class=""></i>', $link);
$this->assertSame('<a href="http://localhost?sort=column&direction=asc"><em>columnTitle</em></a><i class=""></i>', $link);
}


Expand Down

0 comments on commit 29f7c90

Please sign in to comment.