public function FacetapiTestCase::enableFacet in Facet API 6.3
Enables a facet in the block realm, adds it to the "sidebar_first" region.
The following tests are executed:
- DrupalTestCase::getPath(): Retrieves path to the administrative settings page for the block realm.
- DrupalTestCase::getPost(): Enables the facet in the block realm.
- DrupalTestCase::assertRaw(): Ensures the configuration options were successful by testing for the confirmation message.
- DrupalTestCase::assertTrue(): Double checks that the facet is enabled via the facetapi_facet_enabled() API function.
- DrupalTestCase::getPost(): Activates the facet block in the "sidebar_first" region.
- DrupalTestCase::getPath(): Retrieves path to the search page.
- DrupalTestCase::assertRaw(): Tests if the block is displayed by looking for it's title.
Parameters
string $facet_name: The machine readable name of the facet.
string $label: The title of the block whose existence is being tested.
string $realm_name: The machine readable name of the realm.
3 calls to FacetapiTestCase::enableFacet()
File
- tests/
facetapi.test, line 75 - Tests for the Facet API module.
Class
- FacetapiTestCase
- Base class for all Facet API test cases.
Code
public function enableFacet($facet_name, $label, $realm_name = 'block') {
$path = 'admin/settings/facetapi_test/facets/' . $realm_name;
// Posts the form, ensures it was successfully submitted.
$values = array(
'enabled_facets[' . $facet_name . ']' => $facet_name,
);
$this
->drupalGet($path);
$this
->drupalPost($path, $values, t('Save configuration'));
$this
->assertRaw(t('The configuration options have been saved.'), t('Facet form successfully submitted.'));
// We have to clear the static cache otherwise this test won't work. This is
// OK because the script execution persists when the form is submitted by
// the test unlike a real form post where the page has to reload.
ctools_static('facetapi_get_enabled_facets', array(), TRUE);
// Tests the status of the enabled facet.
// Visits search page, raw value mimics return from default theme function.
$this
->drupalGet('admin/build/block');
// Any block of facetapi in this listing is sign of a valid test
$this
->assertRaw(t('Facet API: Facet API Test'), t('Facet block displayed on block listings.'));
// Adds realm to block if we are testing the block realm.
if ('block' == $realm_name) {
// Generates the "key" by generating and hashing the delta.
module_load_include('inc', 'facetapi', 'facetapi.block');
$delta = facetapi_build_delta('facetapi_test', $realm_name, $facet_name);
$key = 'facetapi_' . facetapi_hash_delta($delta);
// Set the created block to a specific region.
$edit = array();
$edit[$key . '[region]'] = 'right';
$this
->drupalPost('admin/build/block', $edit, t('Save blocks'));
// Visits search page, raw value mimics return from default theme function.
$this
->drupalGet('facetapi_test/search');
$raw = t('Filter by @title:', array(
'@title' => drupal_strtolower($label),
));
$this
->assertRaw($raw, t('Facet block displayed on search page.'));
}
}