Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function resetCache(array $ids = NULL)
 {
     drupal_static_reset('taxonomy_term_count_nodes');
     $this->parents = array();
     $this->parentsAll = array();
     $this->children = array();
     $this->treeChildren = array();
     $this->treeParents = array();
     $this->treeTerms = array();
     $this->trees = array();
     parent::resetCache($ids);
 }
Ejemplo n.º 2
0
 /**
  * Test the redirect UI.
  */
 public function testRedirectUI()
 {
     $this->drupalLogin($this->adminUser);
     // Test populating the redirect form with predefined values.
     $this->drupalGet('admin/config/search/redirect/add', array('query' => array('source' => 'non-existing', 'source_query' => array('key' => 'val', 'key1' => 'val1'), 'redirect' => 'node', 'redirect_options' => array('query' => array('key' => 'val', 'key1' => 'val1')))));
     $this->assertFieldByName('redirect_source[0][path]', 'non-existing?key=val&key1=val1');
     $this->assertFieldByName('redirect_redirect[0][uri]', '/node?key=val&key1=val1');
     // Test creating a new redirect via UI.
     $this->drupalPostForm('admin/config/search/redirect/add', array('redirect_source[0][path]' => 'non-existing', 'redirect_redirect[0][uri]' => '/node'), t('Save'));
     // Try to find the redirect we just created.
     $redirect = $this->repository->findMatchingRedirect('non-existing');
     $this->assertEqual($redirect->getSourceUrl(), Url::fromUri('base:non-existing')->toString());
     $this->assertEqual($redirect->getRedirectUrl()->toString(), Url::fromUri('base:node')->toString());
     // After adding the redirect we should end up in the list. Check if the
     // redirect is listed.
     $this->assertUrl('admin/config/search/redirect');
     $this->assertText('non-existing');
     $this->assertLink(Url::fromUri('base:node')->toString());
     $this->assertText(t('Not specified'));
     // Test the edit form and update action.
     $this->clickLink(t('Edit'));
     $this->assertFieldByName('redirect_source[0][path]', 'non-existing');
     $this->assertFieldByName('redirect_redirect[0][uri]', '/node');
     $this->assertFieldByName('status_code', $redirect->getStatusCode());
     // Append a query string to see if we handle query data properly.
     $this->drupalPostForm(NULL, array('redirect_source[0][path]' => 'non-existing?key=value'), t('Save'));
     // Check the location after update and check if the value has been updated
     // in the list.
     $this->assertUrl('admin/config/search/redirect');
     $this->assertText('non-existing?key=value');
     // The path field should not contain the query string and therefore we
     // should be able to load the redirect using only the url part without
     // query.
     $this->storage->resetCache();
     $redirects = $this->repository->findBySourcePath('non-existing');
     $redirect = array_shift($redirects);
     $this->assertEqual($redirect->getSourceUrl(), Url::fromUri('base:non-existing', ['query' => ['key' => 'value']])->toString());
     // Test the source url hints.
     // The hint about an existing base path.
     $this->drupalPostAjaxForm('admin/config/search/redirect/add', array('redirect_source[0][path]' => 'non-existing?key=value'), 'redirect_source[0][path]');
     $this->assertRaw(t('The base source path %source is already being redirected. Do you want to <a href="@edit-page">edit the existing redirect</a>?', array('%source' => 'non-existing?key=value', '@edit-page' => $redirect->url('edit-form'))));
     // The hint about a valid path.
     $this->drupalPostAjaxForm('admin/config/search/redirect/add', array('redirect_source[0][path]' => 'node'), 'redirect_source[0][path]');
     $this->assertRaw(t('The source path %path is likely a valid path. It is preferred to <a href="@url-alias">create URL aliases</a> for existing paths rather than redirects.', array('%path' => 'node', '@url-alias' => Url::fromRoute('path.admin_add')->toString())));
     // Test validation.
     // Duplicate redirect.
     $this->drupalPostForm('admin/config/search/redirect/add', array('redirect_source[0][path]' => 'non-existing?key=value', 'redirect_redirect[0][uri]' => '/node'), t('Save'));
     $this->assertRaw(t('The source path %source is already being redirected. Do you want to <a href="@edit-page">edit the existing redirect</a>?', array('%source' => 'non-existing?key=value', '@edit-page' => $redirect->url('edit-form'))));
     // Redirecting to itself.
     $this->drupalPostForm('admin/config/search/redirect/add', array('redirect_source[0][path]' => 'node', 'redirect_redirect[0][uri]' => '/node'), t('Save'));
     $this->assertRaw(t('You are attempting to redirect the page to itself. This will result in an infinite loop.'));
     // Redirecting the front page.
     $this->drupalPostForm('admin/config/search/redirect/add', array('redirect_source[0][path]' => '<front>', 'redirect_redirect[0][uri]' => '/node'), t('Save'));
     $this->assertRaw(t('It is not allowed to create a redirect from the front page.'));
     // Redirecting a url with fragment.
     $this->drupalPostForm('admin/config/search/redirect/add', array('redirect_source[0][path]' => 'page-to-redirect#content', 'redirect_redirect[0][uri]' => '/node'), t('Save'));
     $this->assertRaw(t('The anchor fragments are not allowed.'));
     // Test filters.
     // Add a new redirect.
     $this->drupalPostForm('admin/config/search/redirect/add', array('redirect_source[0][path]' => 'test27', 'redirect_redirect[0][uri]' => '/node'), t('Save'));
     // Filter  with non existing value.
     $this->drupalGet('admin/config/search/redirect', array('query' => array('status_code' => '3')));
     $rows = $this->xpath('//tbody/tr');
     // Check if the list has no rows.
     $this->assertTrue(count($rows) == 0);
     // Filter with existing values.
     $this->drupalGet('admin/config/search/redirect', array('query' => array('redirect_source__path' => 'test', 'status_code' => '2')));
     $rows = $this->xpath('//tbody/tr');
     // Check if the list has 1 row.
     $this->assertTrue(count($rows) == 1);
     $this->drupalGet('admin/config/search/redirect', array('query' => array('redirect_redirect__uri' => 'nod')));
     $rows = $this->xpath('//tbody/tr');
     // Check if the list has 2 rows.
     $this->assertTrue(count($rows) == 2);
     // Finally test the delete action.
     $this->drupalGet('admin/config/search/redirect');
     $this->clickLink(t('Delete'));
     $this->assertRaw(t('Are you sure you want to delete the URL redirect from %source to %redirect?', array('%source' => Url::fromUri('base:non-existing', ['query' => ['key' => 'value']])->toString(), '%redirect' => Url::fromUri('base:node')->toString())));
     $this->drupalPostForm(NULL, array(), t('Delete'));
     // Delete the other redirect.
     $this->clickLink(t('Delete'));
     $this->drupalPostForm(NULL, array(), t('Delete'));
     $this->assertUrl('admin/config/search/redirect');
     $this->assertText(t('There is no redirect yet.'));
 }