/**
  * Test if aliases are (not) generated with enabled/disabled patterns.
  */
 function testPatternStatus()
 {
     // Create a node to get an alias for.
     $title = 'Pattern enabled';
     $alias = '/content/pattern-enabled';
     $node1 = $this->drupalCreateNode(['title' => $title, 'type' => 'page']);
     $this->assertEntityAlias($node1, $alias);
     // Disable the pattern, save the node again and make sure the alias is still
     // working.
     $this->nodePattern->setStatus(FALSE)->save();
     $node1->save();
     $this->assertEntityAlias($node1, $alias);
     // Create a new node with disabled pattern and make sure there is no new
     // alias created.
     $title = 'Pattern disabled';
     $node2 = $this->drupalCreateNode(['title' => $title, 'type' => 'page']);
     $this->assertNoEntityAlias($node2);
 }
Exemplo n.º 2
0
 function testNoExistingPathAliases()
 {
     $this->config('pathauto.settings')->set('punctuation.period', PathautoGeneratorInterface::PUNCTUATION_DO_NOTHING)->save();
     $this->nodePattern->setPattern('[node:title]')->save();
     // Check that Pathauto does not create an alias of '/admin'.
     $node = $this->drupalCreateNode(array('title' => 'Admin', 'type' => 'page'));
     $this->assertEntityAlias($node, '/admin-0');
     // Check that Pathauto does not create an alias of '/modules'.
     $node->setTitle('Modules');
     $node->save();
     $this->assertEntityAlias($node, '/modules-0');
     // Check that Pathauto does not create an alias of '/index.php'.
     $node->setTitle('index.php');
     $node->save();
     $this->assertEntityAlias($node, '/index.php-0');
     // Check that a safe value gets an automatic alias. This is also a control
     // to ensure the above tests work properly.
     $node->setTitle('Safe value');
     $node->save();
     $this->assertEntityAlias($node, '/safe-value');
 }
Exemplo n.º 3
0
 /**
  * Add a bundle condition to a pathauto pattern.
  *
  * @param \Drupal\pathauto\PathautoPatternInterface $pattern
  *   The pattern.
  * @param string $entity_type
  *   The entity type ID.
  * @param string $bundle
  *   The bundle
  */
 protected function addBundleCondition(PathautoPatternInterface $pattern, $entity_type, $bundle)
 {
     $pattern->addSelectionCondition(['id' => 'entity_bundle:' . $entity_type, 'bundles' => [$bundle => $bundle], 'negate' => FALSE, 'context_mapping' => [$entity_type => $entity_type]]);
 }
Exemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     parent::save($form, $form_state);
     drupal_set_message($this->t('Pattern @label saved.', ['@label' => $this->entity->label()]));
     $form_state->setRedirectUrl($this->entity->toUrl('collection'));
 }