Skip to content

Commit 7139ed8

Browse files
committed
Fix tests
1 parent 1910214 commit 7139ed8

File tree

7 files changed

+95
-168
lines changed

7 files changed

+95
-168
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"autoload-dev": {
3434
"psr-4": {
35-
"Yajra\\DataTables\\Tests\\": "tests/"
35+
"Yajra\\DataTables\\Html\\Tests\\": "tests/"
3636
}
3737
},
3838
"extra": {

phpunit.xml

-6
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
>
1312
<testsuites>
1413
<testsuite name="Package Test Suite">
1514
<directory suffix=".php">./tests/</directory>
1615
</testsuite>
1716
</testsuites>
18-
<filter>
19-
<blacklist>
20-
<directory suffix=".php">./vendor</directory>
21-
</blacklist>
22-
</filter>
2317
</phpunit>

src/Html/Builder.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Builder
5555
* @param Factory $view
5656
* @param HtmlBuilder $html
5757
*/
58-
public function __construct(protected Repository $config, protected Factory $view, protected HtmlBuilder $html)
58+
public function __construct(public Repository $config, public Factory $view, public HtmlBuilder $html)
5959
{
6060
/** @var array $defaults */
6161
$defaults = $this->config->get('datatables-html.table', []);
@@ -74,28 +74,26 @@ public function __construct(protected Repository $config, protected Factory $vie
7474
* @param string|null $script
7575
* @param array $attributes
7676
* @return \Illuminate\Support\HtmlString
77-
* @throws \Exception
7877
*/
7978
public function scripts(string $script = null, array $attributes = ['type' => 'text/javascript']): HtmlString
8079
{
8180
$script = $script ?: $this->generateScripts();
8281
$attributes = $this->html->attributes($attributes);
8382

84-
return new HtmlString("<script{$attributes}>{$script}</script>\n");
83+
return new HtmlString("<script{$attributes}>$script</script>");
8584
}
8685

8786
/**
8887
* Get generated raw scripts.
8988
*
9089
* @return \Illuminate\Support\HtmlString
91-
* @throws \Exception
9290
*/
9391
public function generateScripts(): HtmlString
9492
{
9593
$parameters = $this->generateJson();
9694

9795
return new HtmlString(
98-
sprintf($this->template(), $this->getTableAttribute('id'), $parameters)
96+
trim(sprintf($this->template(), $this->getTableAttribute('id'), $parameters))
9997
);
10098
}
10199

@@ -172,7 +170,7 @@ public function table(array $attributes = [], bool $drawFooter = false, bool $dr
172170
$th = $this->compileTableHeaders();
173171
$htmlAttr = $this->html->attributes($this->tableAttributes);
174172

175-
$tableHtml = '<table '.$htmlAttr.'>';
173+
$tableHtml = '<table'.$htmlAttr.'>';
176174
$searchHtml = $drawSearch ? '<tr class="search-filter">'.implode('',
177175
$this->compileTableSearchHeaders()).'</tr>' : '';
178176
$tableHtml .= '<thead><tr>'.implode('', $th).'</tr>'.$searchHtml.'</thead>';

src/Html/HasTable.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,19 @@ protected function compileTableHeaders(): array
129129
$th = [];
130130

131131
$this->collection->each(function (Column $column) use (&$th) {
132-
$thAttr = $this->html->attributes(array_merge(
133-
Arr::only($column->toArray(), ['class', 'id', 'title', 'width', 'style', 'data-class', 'data-hide']),
134-
$column->getAttributes(),
132+
$only = Arr::only(
133+
$column->toArray(),
134+
['class', 'id', 'title', 'width', 'style', 'data-class', 'data-hide']
135+
);
136+
137+
$attributes = array_merge(
138+
$only,
139+
$column->attributes,
135140
isset($column['titleAttr']) ? ['title' => $column['titleAttr']] : []
136-
));
137-
$th[] = '<th '.$thAttr.'>'.$column['title'].'</th>';
141+
);
142+
143+
$thAttr = $this->html->attributes($attributes);
144+
$th[] = '<th'.$thAttr.'>'.$column['title'].'</th>';
138145
});
139146

140147
return $th;

tests/HtmlBuilderTest.php

+44-150
Large diffs are not rendered by default.

tests/TestCase.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Yajra\DataTables\Html\Tests;
4+
5+
use Orchestra\Testbench\TestCase as BaseTestCase;
6+
7+
abstract class TestCase extends BaseTestCase
8+
{
9+
/**
10+
* Set up the environment.
11+
*
12+
* @param \Illuminate\Foundation\Application $app
13+
*/
14+
protected function getEnvironmentSetUp($app)
15+
{
16+
$app['config']->set('app.debug', true);
17+
$app['config']->set('database.default', 'sqlite');
18+
$app['config']->set('database.connections.sqlite', [
19+
'driver' => 'sqlite',
20+
'database' => ':memory:',
21+
'prefix' => '',
22+
]);
23+
}
24+
25+
protected function getPackageProviders($app): array
26+
{
27+
return [
28+
\Yajra\DataTables\DataTablesServiceProvider::class,
29+
\Yajra\DataTables\HtmlServiceProvider::class,
30+
];
31+
}
32+
}

tests/helper.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace Yajra\DataTables\Html\Tests;
4+
35
use Illuminate\Support\Arr;
46
use Mockery as m;
57
use Yajra\DataTables\Factory;

0 commit comments

Comments
 (0)