Commit f48a9c35 authored by marthinal's avatar marthinal Committed by borisson_

Issue #2696643 by marthinal: Updated date facet for core search

parent 9cb3a2aa
...@@ -154,6 +154,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea ...@@ -154,6 +154,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
break; break;
case 'created': case 'created':
case 'changed':
$query_types['string'] = 'core_node_search_date'; $query_types['string'] = 'core_node_search_date';
break; break;
...@@ -236,6 +237,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea ...@@ -236,6 +237,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
'uid' => $this->t('Author'), 'uid' => $this->t('Author'),
'langcode' => $this->t('Language'), 'langcode' => $this->t('Language'),
'created' => $this->t('Post date'), 'created' => $this->t('Post date'),
'changed' => $this->t('Updated date'),
]; ];
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\core_search_facets\Tests; namespace Drupal\core_search_facets\Tests;
use Drupal\facets\Tests\ExampleContentTrait; use Drupal\facets\Tests\ExampleContentTrait;
use Drupal\node\Entity\Node;
/** /**
* Tests the admin UI with the core search facet source. * Tests the admin UI with the core search facet source.
...@@ -100,9 +101,9 @@ class IntegrationTest extends WebTestBase { ...@@ -100,9 +101,9 @@ class IntegrationTest extends WebTestBase {
} }
/** /**
* Tests the date integration. * Tests the "Post date" facets.
*/ */
public function testDate() { public function testPostDate() {
$facet_name = 'Tardigrade'; $facet_name = 'Tardigrade';
$facet_id = 'tardigrade'; $facet_id = 'tardigrade';
...@@ -135,6 +136,38 @@ class IntegrationTest extends WebTestBase { ...@@ -135,6 +136,38 @@ class IntegrationTest extends WebTestBase {
$this->assertLink('April 2, 2016 (1)'); $this->assertLink('April 2, 2016 (1)');
} }
/**
* Tests the "Updated date" facets.
*/
public function testUpdatedDate() {
$facet_name = 'Tardigrade';
$facet_id = 'tardigrade';
$this->addFacet($facet_id, $facet_name, 'changed');
$this->createFacetBlock($facet_id);
$this->setShowAmountOfResults($facet_id, TRUE);
// Update the changed date. The nodes were created on February/March 2016
// and the changed date is December 2016.
$node = Node::load(1);
$changed_date = new \DateTime('December 3 2016 1PM');
$node->changed = $changed_date->format('U');
$node->save();
// Index the content.
\Drupal::service('plugin.manager.search')->createInstance('node_search')->updateIndex();
search_update_totals();
$this->drupalGet('search/node', ['query' => ['keys' => 'test']]);
$this->assertLink('December 2016 (1)');
$this->clickLink('December 2016 (1)');
$this->assertResponse(200);
$this->assertLink('December 3, 2016 (1)');
$this->clickLink('December 3, 2016 (1)');
$this->assertResponse(200);
}
/** /**
* Tests for CRUD operations. * Tests for CRUD operations.
*/ */
......
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