-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update for scrutinizer issues. pt. 1 (#65)
* Update for scrutinizer issues. pt. 1 * Add check for Synonyms being pushed/deleted in Elastic * Ensure the set-up of synonym sets before testing * The rule ID is not the same as the set ID * Better testing of CRUD for synonyms
- Loading branch information
1 parent
87db121
commit b71501f
Showing
5 changed files
with
99 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,6 @@ | |
"email": "[email protected]", | ||
"homepage": "https://firesphere.dev", | ||
"role": "Lead developer" | ||
}, | ||
{ | ||
"name": "Marco `Sheepy` Hermo", | ||
"email": "[email protected]", | ||
"role": "Lead developer" | ||
} | ||
], | ||
"require": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Firesphere\ElasticSearch\Tests\unit\Extensions; | ||
|
||
use Elastic\Elasticsearch\Client; | ||
use Elastic\Elasticsearch\Exception\ClientResponseException; | ||
use Firesphere\ElasticSearch\Extensions\ElasticSynonymExtension; | ||
use Firesphere\ElasticSearch\Models\SynonymSet; | ||
use Firesphere\ElasticSearch\Services\ElasticCoreService; | ||
use Firesphere\ElasticSearch\Tasks\ElasticConfigureSynonymsTask; | ||
use Firesphere\SearchBackend\Models\SearchSynonym; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\Dev\SapphireTest; | ||
|
||
class ElasticSynonymExtensionTest extends SapphireTest | ||
{ | ||
|
||
public function testWriteUpdateDelete() | ||
{ | ||
(new SynonymSet())->requireDefaultRecords(); | ||
$request = new HTTPRequest('GET', 'dev/tasks/ElasticSynonymTask'); | ||
$task = new ElasticConfigureSynonymsTask(); | ||
|
||
$task->run($request); | ||
|
||
SynonymSet::singleton()->requireDefaultRecords(); | ||
/** @var SynonymSet $set */ | ||
$set = SynonymSet::get()->first(); | ||
/** @var SearchSynonym $synonym */ | ||
$synonym = SearchSynonym::create(['Keyword' => 'Simon', 'Synonym' => 'Firesphere']); | ||
$extension = new ElasticSynonymExtension(); | ||
$extension->setOwner($synonym); | ||
|
||
$synonym->write(); | ||
|
||
/** @var Client $client */ | ||
$client = Injector::inst()->get(ElasticCoreService::class)->getClient(); | ||
$synonymCheck = $client->synonyms()->getSynonymRule([ | ||
'set_id' => $set->Key, | ||
'rule_id' => $synonym->getModifiedID() | ||
]); | ||
|
||
$check = $synonymCheck->asArray(); | ||
|
||
$this->assertEquals(['id' => $synonym->getModifiedID(), 'synonyms' => $synonym->getCombinedSynonym()], $check); | ||
|
||
$synonym->Synonym = 'Firesphere,Hans'; | ||
$synonym->write(); | ||
|
||
$synonymCheck = $client->synonyms()->getSynonymRule([ | ||
'set_id' => $set->Key, | ||
'rule_id' => $synonym->getModifiedID() | ||
]); | ||
|
||
$check = $synonymCheck->asArray(); | ||
|
||
$this->assertEquals(['id' => $synonym->getModifiedID(), 'synonyms' => $synonym->getCombinedSynonym()], $check); | ||
|
||
|
||
$synonym->delete(); | ||
|
||
try { | ||
$client->synonyms()->getSynonymRule([ | ||
'set_id' => $set->Key, | ||
'rule_id' => $synonym->getModifiedID() | ||
]); | ||
} catch (ClientResponseException $e) { | ||
$this->assertEquals(404, $e->getCode()); | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters