diff --git a/framework/core/tests/integration/api/discussions/FulltextSearchTest.php b/framework/core/tests/integration/api/discussions/FulltextSearchTest.php deleted file mode 100644 index ca2de82ab..000000000 --- a/framework/core/tests/integration/api/discussions/FulltextSearchTest.php +++ /dev/null @@ -1,125 +0,0 @@ -database()->rollBack(); - - // We need to insert these outside of a transaction, because FULLTEXT indexing, - // which is needed for search, doesn't happen in transactions. - // 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', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1], - ['id' => 3, 'title' => 'not in title', 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'comment_count' => 1], - ]); - - $this->database()->table('posts')->insert([ - ['id' => 1, 'discussion_id' => 1, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '

not in text

'], - ['id' => 2, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '

lightsail in text

'], - ['id' => 3, 'discussion_id' => 3, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '

not in text

'], - ]); - - // We need to call these again, since we rolled back the transaction started by `::app()`. - $this->database()->beginTransaction(); - - $this->populateDatabase(); - } - - /** - * @inheritDoc - */ - protected function tearDown(): void - { - parent::tearDown(); - - $this->database()->table('discussions')->whereIn('id', [1, 2, 3])->delete(); - $this->database()->table('posts')->whereIn('id', [1, 2, 3])->delete(); - } - - /** - * @test - */ - public function can_search_for_word_or_title_in_post() - { - $response = $this->send( - $this->request('GET', '/api/discussions') - ->withQueryParams([ - 'filter' => ['q' => 'lightsail'], - 'include' => 'mostRelevantPost', - ]) - ); - - $data = json_decode($response->getBody()->getContents(), true); - - $this->assertEqualsCanonicalizing(['1', '2'], Arr::pluck($data['data'], 'id'), 'IDs do not match'); - } - - /** - * @test - */ - public function ignores_non_word_characters_when_searching() - { - $response = $this->send( - $this->request('GET', '/api/discussions') - ->withQueryParams([ - 'filter' => ['q' => 'lightsail+'], - 'include' => 'mostRelevantPost', - ]) - ); - - $data = json_decode($response->getBody()->getContents(), true); - - $this->assertEqualsCanonicalizing(['1', '2'], Arr::pluck($data['data'], 'id'), 'IDs do not match'); - } - - /** - * @test - */ - public function search_for_special_characters_gives_empty_result() - { - $response = $this->send( - $this->request('GET', '/api/discussions') - ->withQueryParams([ - 'filter' => ['q' => '*'], - 'include' => 'mostRelevantPost', - ]) - ); - - $data = json_decode($response->getBody()->getContents(), true); - $this->assertEquals([], $data['data']); - - $response = $this->send( - $this->request('GET', '/api/discussions') - ->withQueryParams([ - 'filter' => ['q' => '@'], - 'include' => 'mostRelevantPost', - ]) - ); - - $data = json_decode($response->getBody()->getContents(), true); - $this->assertEquals([], $data['data']); - } -} diff --git a/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php b/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php index 3e7ad5b73..1a4bf15c2 100644 --- a/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php +++ b/framework/core/tests/integration/api/discussions/ListWithFulltextSearchTest.php @@ -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' => '

lightsail in text

'], ['id' => 3, 'discussion_id' => 2, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '

another lightsail for discussion 2!

'], ['id' => 4, 'discussion_id' => 3, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '

just one lightsail for discussion 3.

'], + ['id' => 5, 'discussion_id' => 4, 'created_at' => Carbon::now()->toDateTimeString(), 'user_id' => 1, 'type' => 'comment', 'content' => '

not in title or text

'], ]); // 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'); } /**