Commit 3b27b114 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2973743 by borisson_: Fix tests

parent f3ae4113
...@@ -122,49 +122,88 @@ class RestIntegrationTest extends FacetsTestBase { ...@@ -122,49 +122,88 @@ class RestIntegrationTest extends FacetsTestBase {
// Verify the facet "Type". // Verify the facet "Type".
$results = [ $results = [
'article' => [ 'article' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=type%3Aarticle', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=type%3Aarticle',
],
'count' => 2, 'count' => 2,
], ],
'item' => [ 'item' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=type%3Aitem', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=type%3Aitem',
],
'count' => 3, 'count' => 3,
], ],
]; ];
foreach ($json_decoded->facets[1][0]->type as $result) { foreach ($json_decoded->facets[1][0]->type as $result) {
$value = $result->values->value; $value = $result->values->value;
$this->assertEquals($result->url, $results[$value]['url']);
$this->assertEquals($result->values->count, $results[$value]['count']); $this->assertEquals($result->values->count, $results[$value]['count']);
foreach ($results[$value]['url'] as $url_part) {
$this->assertNotFalse(strpos($result->url, $url_part));
}
} }
// Verify the facet "Keywords". // Verify the facet "Keywords".
$results = [ $results = [
'banana' => [ 'banana' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=keywords%3Abanana', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=keywords%3Abanana',
],
'count' => 1, 'count' => 1,
], ],
'strawberry' => [ 'strawberry' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=keywords%3Astrawberry', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=keywords%3Astrawberry',
],
'count' => 2, 'count' => 2,
], ],
'apple' => [ 'apple' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=keywords%3Aapple', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=keywords%3Aapple',
],
'count' => 2, 'count' => 2,
], ],
'orange' => [ 'orange' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=keywords%3Aorange', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=keywords%3Aorange',
],
'count' => 3, 'count' => 3,
], ],
'grape' => [ 'grape' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=keywords%3Agrape', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=keywords%3Agrape',
],
'count' => 3, 'count' => 3,
], ],
]; ];
foreach ($json_decoded->facets[0][0]->keywords as $result) { foreach ($json_decoded->facets[0][0]->keywords as $result) {
$value = $result->values->value; $value = $result->values->value;
$this->assertEquals($result->url, $results[$value]['url']);
$this->assertEquals($result->values->count, $results[$value]['count']); $this->assertEquals($result->values->count, $results[$value]['count']);
foreach ($results[$value]['url'] as $url_part) {
$this->assertNotFalse(strpos($result->url, $url_part));
}
} }
// Filter and verify that the results are correct. // Filter and verify that the results are correct.
...@@ -177,45 +216,79 @@ class RestIntegrationTest extends FacetsTestBase { ...@@ -177,45 +216,79 @@ class RestIntegrationTest extends FacetsTestBase {
$results = [ $results = [
'article' => [ 'article' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=type%3Aitem&f%5B1%5D=type%3Aarticle', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=type%3Aitem&f%5B1%5D=type%3Aarticle',
],
'count' => 2, 'count' => 2,
], ],
'item' => [ 'item' => [
'url' => $base_url . '/facets-rest?_format=json&', 'url' => [$base_url, '/facets-rest', '_format=json'],
'count' => 3, 'count' => 3,
], ],
'banana' => [ 'banana' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Abanana', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Abanana',
],
'count' => 0, 'count' => 0,
], ],
'strawberry' => [ 'strawberry' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Astrawberry', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Astrawberry',
],
'count' => 0, 'count' => 0,
], ],
'apple' => [ 'apple' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Aapple', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Aapple',
],
'count' => 1, 'count' => 1,
], ],
'orange' => [ 'orange' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Aorange', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Aorange',
],
'count' => 2, 'count' => 2,
], ],
'grape' => [ 'grape' => [
'url' => $base_url . '/facets-rest?_format=json&f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Agrape', 'url' => [
$base_url,
'/facets-rest',
'_format=json',
'f%5B0%5D=type%3Aitem&f%5B1%5D=keywords%3Agrape',
],
'count' => 1, 'count' => 1,
], ],
]; ];
foreach ($json_decoded->facets[1][0]->type as $result) { foreach ($json_decoded->facets[1][0]->type as $result) {
$value = $result->values->value; $value = $result->values->value;
$this->assertEquals($results[$value]['url'], $result->url);
$this->assertEquals($results[$value]['count'], $result->values->count); $this->assertEquals($results[$value]['count'], $result->values->count);
foreach ($results[$value]['url'] as $url_part) {
$this->assertNotFalse(strpos($result->url, $url_part));
}
} }
foreach ($json_decoded->facets[0][0]->keywords as $result) { foreach ($json_decoded->facets[0][0]->keywords as $result) {
$value = $result->values->value; $value = $result->values->value;
$this->assertEquals($results[$value]['url'], $result->url);
$this->assertEquals($results[$value]['count'], $result->values->count); $this->assertEquals($results[$value]['count'], $result->values->count);
foreach ($results[$value]['url'] as $url_part) {
$this->assertNotFalse(strpos($result->url, $url_part));
}
} }
} }
......
...@@ -195,7 +195,7 @@ class FacetFacetSourceTest extends EntityKernelTestBase { ...@@ -195,7 +195,7 @@ class FacetFacetSourceTest extends EntityKernelTestBase {
/** /**
* Test the data definitions. * Test the data definitions.
* *
* @covers \Drupal\facets\FacetSource\FacetSourcePluginInterface::getDataDefinition * @covers \Drupal\facets\Plugin\facets\facet_source\SearchApiDisplay::getDataDefinition
*/ */
public function testDataDefinitions() { public function testDataDefinitions() {
// Create and configure facet. // Create and configure facet.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment