Skip to content
Snippets Groups Projects
Commit f48a9c35 authored by José Manuel Rodríguez Vélez's avatar José Manuel Rodríguez Vélez Committed by Joris Vercammen
Browse files

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

parent 9cb3a2aa
No related branches found
No related tags found
No related merge requests found
......@@ -154,6 +154,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
break;
case 'created':
case 'changed':
$query_types['string'] = 'core_node_search_date';
break;
......@@ -236,6 +237,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
'uid' => $this->t('Author'),
'langcode' => $this->t('Language'),
'created' => $this->t('Post date'),
'changed' => $this->t('Updated date'),
];
}
......
......@@ -3,6 +3,7 @@
namespace Drupal\core_search_facets\Tests;
use Drupal\facets\Tests\ExampleContentTrait;
use Drupal\node\Entity\Node;
/**
* Tests the admin UI with the core search facet source.
......@@ -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_id = 'tardigrade';
......@@ -135,6 +136,38 @@ class IntegrationTest extends WebTestBase {
$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.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment