mirror of
https://github.com/flarum/core.git
synced 2025-08-09 09:57:06 +02:00
Combine search tests
#b62debf031f1d3aec9cb5e92d9df54cb8ab3a3b1 and #b6f0b01307884b11388eff1ae2d814b7f57715aa both added/improved searching tests, but did so in separate files. As a result, the tests did not consider each other, and when both were merged, started failing. This commit combines the tests into one file that tests both order and search in titles.
This commit is contained in:
@@ -31,8 +31,9 @@ class ListWithFulltextSearchTest extends TestCase
|
||||
// We clean it up explcitly at the end.
|
||||
$this->database()->table('discussions')->insert([
|
||||
['id' => 1, 'title' => 'lightsail in title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
|
||||
['id' => 2, 'title' => 'not in title and older', 'created_at' => Carbon::createFromDate(2020, 01, 01)->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
|
||||
['id' => 2, 'title' => 'lightsail in title too', 'created_at' => Carbon::createFromDate(2020, 01, 01)->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
|
||||
['id' => 3, 'title' => 'not in title either', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
|
||||
['id' => 4, 'title' => 'not in title or text', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1],
|
||||
]);
|
||||
|
||||
$this->database()->table('posts')->insert([
|
||||
@@ -40,6 +41,7 @@ class ListWithFulltextSearchTest extends TestCase
|
||||
['id' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '<t><p>lightsail in text</p></t>'],
|
||||
['id' => 3, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '<t><p>another lightsail for discussion 2!</p></t>'],
|
||||
['id' => 4, 'discussion_id' => 3, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '<t><p>just one lightsail for discussion 3.</p></t>'],
|
||||
['id' => 5, 'discussion_id' => 4, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '<t><p>not in title or text</p></t>'],
|
||||
]);
|
||||
|
||||
// We need to call these again, since we rolled back the transaction started by `::app()`.
|
||||
@@ -55,14 +57,14 @@ class ListWithFulltextSearchTest extends TestCase
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
$this->database()->table('discussions')->whereIn('id', [1, 2, 3])->delete();
|
||||
$this->database()->table('posts')->whereIn('id', [1, 2, 3, 4])->delete();
|
||||
$this->database()->table('discussions')->delete();
|
||||
$this->database()->table('posts')->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function can_search_for_word_in_post()
|
||||
public function can_search_for_word_or_title_in_post()
|
||||
{
|
||||
$response = $this->send(
|
||||
$this->request('GET', '/api/discussions')
|
||||
@@ -77,7 +79,7 @@ class ListWithFulltextSearchTest extends TestCase
|
||||
return $row['id'];
|
||||
}, $data['data']);
|
||||
|
||||
$this->assertEquals(['2', '3'], $ids, 'IDs do not match');
|
||||
$this->assertEquals(['2', '1', '3'], $ids, 'IDs do not match');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +100,7 @@ class ListWithFulltextSearchTest extends TestCase
|
||||
return $row['id'];
|
||||
}, $data['data']);
|
||||
|
||||
$this->assertEquals(['2', '3'], $ids, 'IDs do not match');
|
||||
$this->assertEquals(['2', '1', '3'], $ids, 'IDs do not match');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user