|
4 | 4 |
|
5 | 5 | use Illuminate\Support\Facades\DB;
|
6 | 6 | use Illuminate\Support\Str;
|
| 7 | +use Yajra\DataTables\Tests\Models\Post; |
7 | 8 | use Yajra\DataTables\Tests\Models\User;
|
8 | 9 | use Yajra\DataTables\Tests\TestCase;
|
9 | 10 |
|
@@ -111,10 +112,27 @@ public function test_simple_queries_with_complexe_select_are_not_wrapped()
|
111 | 112 | );
|
112 | 113 |
|
113 | 114 | $this->assertQueryWrapped(false, $dataTable->prepareCountQuery());
|
114 |
| - $this->assertQueryIsFromSub(false, $dataTable->prepareCountQuery()); |
115 | 115 | $this->assertEquals(20, $dataTable->count());
|
116 | 116 | }
|
117 | 117 |
|
| 118 | + public function test_simple_queries_with_complexe_where_are_not_wrapped() |
| 119 | + { |
| 120 | + /** @var \Yajra\DataTables\QueryDataTable $dataTable */ |
| 121 | + $dataTable = app('datatables')->of( |
| 122 | + DB::table('users') |
| 123 | + ->select('users.*') |
| 124 | + ->where( |
| 125 | + DB::table('posts') |
| 126 | + ->whereColumn('posts.user_id', 'users.id') |
| 127 | + ->orderBy('created_at') |
| 128 | + ->select('title'), 'User-1 Post-1' |
| 129 | + ) |
| 130 | + ); |
| 131 | + |
| 132 | + $this->assertQueryWrapped(false, $dataTable->prepareCountQuery()); |
| 133 | + $this->assertEquals(1, $dataTable->prepareCountQuery()->first()->row_count); |
| 134 | + } |
| 135 | + |
118 | 136 | public function test_simple_queries_are_not_wrapped_and_countable()
|
119 | 137 | {
|
120 | 138 | /** @var \Yajra\DataTables\QueryDataTable $dataTable */
|
@@ -160,16 +178,4 @@ public function assertQueryHasNoSelect($expected, $query)
|
160 | 178 |
|
161 | 179 | $this->assertSame($expected, Str::startsWith($sql, 'select count(*) from (select 1 as dt_row_count from'), "'{$sql}' has select");
|
162 | 180 | }
|
163 |
| - |
164 |
| - /** |
165 |
| - * @param $expected bool |
166 |
| - * @param $query \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder |
167 |
| - * @return void |
168 |
| - */ |
169 |
| - public function assertQueryIsFromSub($expected, $query) |
170 |
| - { |
171 |
| - $sql = $query->select(DB::raw('count(*)'))->toSql(); |
172 |
| - |
173 |
| - $this->assertSame($expected, Str::startsWith($sql, 'select count(*) from (select'), "'{$sql}' is from sub query"); |
174 |
| - } |
175 | 181 | }
|
0 commit comments