Ejemplo n.º 1
0
 /**
  * Tests the integration of the {node_counter} table in views.
  */
 public function testNodeCounterIntegration()
 {
     $this->drupalLogin($this->webUser);
     $this->drupalGet('node/' . $this->node->id());
     // Manually calling statistics.php, simulating ajax behavior.
     // @see \Drupal\statistics\Tests\StatisticsLoggingTest::testLogging().
     global $base_url;
     $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
     $client = \Drupal::service('http_client_factory')->fromOptions(['config/curl', array(CURLOPT_TIMEOUT => 10)]);
     $client->post($stats_path, array('form_params' => array('nid' => $this->node->id())));
     $this->drupalGet('test_statistics_integration');
     $expected = statistics_get($this->node->id());
     // Convert the timestamp to year, to match the expected output of the date
     // handler.
     $expected['timestamp'] = date('Y', $expected['timestamp']);
     foreach ($expected as $field => $value) {
         $xpath = "//div[contains(@class, views-field-{$field})]/span[@class = 'field-content']";
         $this->assertFieldByXpath($xpath, $value, "The {$field} output matches the expected.");
     }
     $this->drupalLogout();
     $this->drupalLogin($this->deniedUser);
     $this->drupalGet('test_statistics_integration');
     $this->assertResponse(200);
     foreach ($expected as $field => $value) {
         $xpath = "//div[contains(@class, views-field-{$field})]/span[@class = 'field-content']";
         $this->assertNoFieldByXpath($xpath, $value, "The {$field} output is not displayed.");
     }
 }
Ejemplo n.º 2
0
 /**
  * Test that hook_entity_field_access() is called.
  */
 function testFieldAccess()
 {
     // Assert the text is visible.
     $this->drupalGet('node/' . $this->node->id());
     $this->assertText($this->testViewFieldValue);
     // Assert the text is not visible for anonymous users.
     // The field_test module implements hook_entity_field_access() which will
     // specifically target the 'test_view_field' field.
     $this->drupalLogout();
     $this->drupalGet('node/' . $this->node->id());
     $this->assertNoText($this->testViewFieldValue);
 }
Ejemplo n.º 3
0
  /**
   * Reset the flag and ensure the flaggings are deleted.
   */
  public function doFlagReset() {
    // Flag the node.
    $this->flagService->flag($this->flag, $this->node, $this->adminUser);

    $ids_before = $this->entityQueryManager->get('flagging')
      ->condition('flag_id', $this->flag->id())
      ->condition('entity_type', 'node')
      ->condition('entity_id', $this->node->id())
      ->execute();

    $this->assertEqual(count($ids_before), 1, "The flag has one flagging.");

    // Go to the reset form for the flag.
    $this->drupalGet('admin/structure/flags/manage/' . $this->flag->id() . '/reset');

    $this->assertText($this->t('Are you sure you want to reset the Flag'));

    $this->drupalPostForm(NULL, [], $this->t('Reset'));

    $ids_after = $this->entityQueryManager->get('flagging')
      ->condition('flag_id', $this->flag->id())
      ->condition('entity_type', 'node')
      ->condition('entity_id', $this->node->id())
      ->execute();

    $this->assertEqual(count($ids_after), 0, "The flag has no flaggings after being reset.");
  }
Ejemplo n.º 4
0
 public function mapAnalysisIssues(Node $entity, array $results)
 {
     $nid = $entity->id();
     foreach ($results as $issue_entity) {
         /** @var EntityInterface $issue_entity */
         $this->connection->insert('code_analyzer_project_issues')->fields(array('nid' => $nid, 'inid' => $issue_entity->id()))->execute();
     }
 }
 /**
  * Create the referrer entity.
  */
 protected function createReferrerEntity()
 {
     /** @var \Drupal\node\Entity\Node $node */
     $node = entity_create($this->testEntityTypeName, array('title' => $this->randomMachineName(), 'type' => $this->referrerType->id(), 'description' => array('value' => $this->randomMachineName(), 'format' => 'basic_html'), $this->referenceFieldName => array(array('target_id' => $this->referencedEntityWithTranslation->id()), array('target_id' => $this->referencedEntityWithoutTranslation->id())), 'langcode' => $this->baseLangcode));
     $node->save();
     $node->addTranslation($this->translateToLangcode, $node->toArray());
     $node->save();
     return $node;
 }
 /**
  * Tests if the translated taxonomy term is displayed.
  */
 public function testTranslatedTaxonomyTermReferenceDisplay()
 {
     $path = 'node/' . $this->node->id();
     $translation_path = $this->translateToLangcode . '/' . $path;
     $this->drupalGet($path);
     $this->assertNoText($this->translatedTagName);
     $this->assertText($this->baseTagName);
     $this->drupalGet($translation_path);
     $this->assertText($this->translatedTagName);
     $this->assertNoText($this->baseTagName);
 }
Ejemplo n.º 7
0
 /**
  * Test the access works for viewing the PDF's.
  */
 public function testEntityPrintAccess()
 {
     // User with entity print access but not content access.
     $account = $this->drupalCreateUser(['entity print access'], $this->randomMachineName());
     $this->drupalLogin($account);
     $this->drupalGet('entityprint/node/' . $this->node->id() . '/debug');
     $this->assertResponse(403, 'User with only the entity print access permission cannot view PDF.');
     // User with access content but not entity print access.
     $account = $this->drupalCreateUser(['access content'], $this->randomMachineName());
     $this->drupalLogin($account);
     $this->drupalGet('entityprint/node/' . $this->node->id() . '/debug');
     $this->assertResponse(403, 'User with access content but no entity print permission cannot view PDF.');
     // User with both entity print and entity view.
     $account = $this->drupalCreateUser(['entity print access', 'access content'], $this->randomMachineName());
     $this->drupalLogin($account);
     $this->drupalGet('entityprint/node/' . $this->node->id() . '/debug');
     $this->assertResponse(200, 'User with both permissions can view the PDF.');
     // User with neither permissions.
     $account = $this->drupalCreateUser([], $this->randomMachineName());
     $this->drupalLogin($account);
     $this->drupalGet('entityprint/node/' . $this->node->id() . '/debug');
     $this->assertResponse(403, 'User with neither permission cannot view the PDF.');
 }
Ejemplo n.º 8
0
 /**
  * Tests appearance of feedback options on node delete forms.
  */
 function testReportNode()
 {
     // Create a second node type, which is not protected.
     $this->drupalCreateContentType(array('type' => 'unprotected', 'name' => 'Unprotected'));
     user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['create unprotected content', 'delete own unprotected content', 'delete own article content']);
     // Protect the article node type.
     $this->drupalLogin($this->adminUser);
     $this->setProtectionUI('node_article_form');
     $this->drupalLogout();
     // Login and submit a protected article node.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('node/add/article');
     $edit = array('title[0][value]' => 'protected ham', 'body[0][value]' => 'ham');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $this->assertUrl('node/' . $this->node->id());
     $this->assertMollomData('node', $this->node->id());
     // Verify that no feedback options appear on the delete confirmation form
     // for the node author.
     $this->drupalGet('node/' . $this->node->id() . '/delete');
     $this->assertResponse(200);
     $this->assertNoText(t('Report as…'));
     // Verify that feedback options appear for the admin user.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('node/' . $this->node->id() . '/delete');
     $this->assertResponse(200);
     $this->assertText(t('Report as…'));
     // Login and submit an unprotected node.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('node/add/unprotected');
     $edit = array('title[0][value]' => 'unprotected spam', 'body[0][value]' => 'spam');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $this->assertUrl('node/' . $this->node->id());
     $this->assertNoMollomData('node', $this->node->id());
     // Verify that no feedback options appear on the delete confirmation form
     // for the node author.
     $this->drupalGet('node/' . $this->node->id() . '/delete');
     $this->assertResponse(200);
     $this->assertNoText(t('Report as…'));
     // Verify that no feedback options appear for the admin user.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('node/' . $this->node->id() . '/delete');
     $this->assertResponse(200);
     $this->assertNoText(t('Report as…'));
 }
Ejemplo n.º 9
0
 public function buildForm(array $form, FormStateInterface $form_state, Node $node = NULL)
 {
     $form['#node'] = $node;
     $config = $this->getConfiguration();
     $form['nid'] = array('#type' => 'value', '#value' => $node->id());
     $form['cid'] = array('#type' => 'value', '#value' => $config['cid']);
     $form['#component'] = $this;
     // Load basic component information from query string
     $form['type'] = array('#type' => 'value', '#value' => $config['type']);
     $form['pid'] = array('#type' => 'value', '#value' => $config['pid']);
     $form['weight'] = array('#type' => 'value', '#value' => $config['weight']);
     $form['name'] = ['#type' => 'textfield', '#title' => t('Name'), '#description' => t('This is used as a descriptive label when displaying this form element.'), '#size' => 60, '#maxlength' => NULL, '#required' => TRUE, '#default_value' => $config['name'], '#weight' => -20, '#attributes' => ['required' => TRUE, 'class' => ['webform-component-name']]];
     $form['form_key'] = ['#type' => 'machine_name', '#title' => t('Field key'), '#description' => t('Enter a machine readable key for this form element. May contain only alphanumeric characters and underscores. This key will be used as the name attribute of the form element. This value has no effect on the way data is saved, but may be helpful if doing custom form processing.'), '#size' => 60, '#machine_name' => ['exists' => array($this, 'componentKeyExists'), 'source' => array('name')], '#maxlength' => NULL, '#required' => TRUE, '#weight' => -19, '#attributes' => ['required' => TRUE, 'class' => ['webform-component-form-key']]];
     $form['validation'] = ['#type' => 'details', '#title' => t('Validation'), '#collapsible' => TRUE, '#open' => TRUE, '#attributes' => ['class' => ['webform-component-validation']]];
     $form['validation']['required'] = ['#type' => 'checkbox', '#title' => t('Required'), '#description' => t('Check this option if the user must enter a value.'), '#default_value' => $config['required'], '#attributes' => ['class' => ['webform-component-required']]];
     if ($this->supports_unique) {
         $form['validation']['unique'] = array('#type' => 'checkbox', '#title' => t('Unique'), '#return_value' => 1, '#description' => t('Check that all entered values for this field are unique. The same value is not allowed to be used twice.'), '#weight' => 1, '#default_value' => $config['extra']['unique'], '#parents' => array('extra', 'unique'));
     }
     $form['display'] = ['#type' => 'details', '#title' => t('Display'), '#collapsible' => TRUE, '#open' => TRUE, '#attributes' => ['class' => ['webform-component-display']]];
     $form['display']['wrapper_css'] = ['#type' => 'textfield', '#title' => t('Wrapper CSS classes'), '#description' => t('Apply a class to the wrapper around both the field and its label. Separate multiple classes by spaces.'), '#size' => 60, '#maxlength' => NULL, '#weight' => 20, '#parents' => array('extra', 'wrapper_css'), '#attributes' => ['class' => ['webform-component-wrapper-css']]];
     $form['display']['field_css'] = ['#type' => 'textfield', '#title' => t('Field CSS classes'), '#description' => t('Apply a class to the field. Separate multiple by spaces.'), '#size' => 60, '#maxlength' => NULL, '#weight' => 22, '#parents' => array('extra', 'field_css'), '#attributes' => ['class' => ['webform-component-field-css']]];
     if ($this->supports_disabled) {
         $form['display']['disabled'] = array('#type' => 'checkbox', '#title' => t('Disabled'), '#return_value' => 1, '#description' => t('Make this field non-editable. Useful for setting an unchangeable default value.'), '#weight' => 11, '#default_value' => $config['extra']['disabled'], '#parents' => array('extra', 'disabled'));
     }
     if ($this->supports_prefix_suffix) {
         $form['display']['field_prefix'] = array('#type' => 'textfield', '#title' => t('Prefix text placed to the left of the textfield'), '#default_value' => $config['extra']['field_prefix'], '#description' => t('Examples: $, #, -.'), '#size' => 20, '#maxlength' => 127, '#weight' => 2.1, '#parents' => array('extra', 'field_prefix'));
         $form['display']['field_suffix'] = array('#type' => 'textfield', '#title' => t('Postfix text placed to the right of the textfield'), '#default_value' => $config['extra']['field_suffix'], '#description' => t('Examples: lb, kg, %.'), '#size' => 20, '#maxlength' => 127, '#weight' => 2.2, '#parents' => array('extra', 'field_suffix'));
     }
     if ($this->supports_placeholder) {
         $form['display']['placeholder'] = array('#type' => 'textfield', '#title' => t('Placeholder'), '#default_value' => $config['extra']['placeholder'], '#description' => t('The placeholder will be shown in the field until the user starts entering a value.'), '#weight' => 1, '#parents' => array('extra', 'placeholder'));
     }
     if ($this->supports_width) {
         $form['display']['width'] = array('#type' => 'textfield', '#title' => t('Width'), '#default_value' => $config['extra']['width'], '#description' => t('Width of the textfield.') . ' ' . t('Leaving blank will use the default size.'), '#size' => 5, '#maxlength' => 10, '#weight' => 0, '#parents' => array('extra', 'width'));
     }
     $form['actions']['submit'] = ['#type' => 'submit', '#value' => t('Save component'), '#validate' => ['::validateComponentEditForm']];
     return $form;
 }
Ejemplo n.º 10
0
 /**
  * Helper function to return a sanitized node title.
  */
 private static function get_node_title(Node $node)
 {
     if (isset($node)) {
         $nid = $node->id();
         if ($node_title = $node->getTitle()) {
             return $node_title;
         } elseif ($nid) {
             return $nid;
         }
     }
     return '—';
 }
Ejemplo n.º 11
0
 public static function getCid(Node $benzinarie, Term $tip_carburant)
 {
     return 'benzinarie:' . $benzinarie->id() . ':carburant:' . $tip_carburant->id();
 }
Ejemplo n.º 12
0
 /**
  * Checks whether a route is the "Latest version" tab of a node.
  *
  * @param \Drupal\node\Entity\Node $node
  *   A node.
  *
  * @return bool
  *   True if the current route is the latest version tab of the given node.
  */
 public function isLatestVersionPage(Node $node)
 {
     return $this->routeMatch->getRouteName() == 'entity.node.latest_version' && ($pageNode = $this->routeMatch->getParameter('node')) && $pageNode->id() == $node->id();
 }
Ejemplo n.º 13
0
 /**
  * Checks that nested IEF entity references can be edit and saved.
  *
  * @param \Drupal\node\Entity\Node $node
  *  Top level node of type ief_test_nested1 to check.
  * @param bool $ajax_submit
  *  Whether IEF form widgets should be submitted via AJax or left open.
  *
  */
 protected function checkNestedEntityEditing(Node $node, $ajax_submit = TRUE)
 {
     $this->drupalGet("node/{$node->id()}/edit");
     /** @var \Drupal\node\Entity\Node $level_1_node */
     $level_1_node = $node->test_ref_nested1->entity;
     /** @var \Drupal\node\Entity\Node $level_2_node */
     $level_2_node = $node->test_ref_nested1->entity->test_ref_nested2->entity;
     $level_2_node_update_title = $level_2_node->getTitle() . ' - updated';
     //edit-test-ref-nested1-entities-0-actions-ief-entity-edit
     $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @data-drupal-selector="edit-test-ref-nested1-entities-0-actions-ief-entity-edit"]'));
     //edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-entities-0-actions-ief-entity-edit
     $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @data-drupal-selector="edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-entities-0-actions-ief-entity-edit"]'));
     $edit['test_ref_nested1[form][inline_entity_form][entities][0][form][test_ref_nested2][form][inline_entity_form][entities][0][form][title][0][value]'] = $level_2_node_update_title;
     if ($ajax_submit) {
         // Close IEF Forms with AJAX posts
         //edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-form-inline-entity-form-entities-0-form-actions-ief-edit-save
         $this->drupalPostAjaxForm(NULL, $edit, $this->getButtonName('//input[@type="submit" and @data-drupal-selector="edit-test-ref-nested1-form-inline-entity-form-entities-0-form-test-ref-nested2-form-inline-entity-form-entities-0-form-actions-ief-edit-save"]'));
         $this->drupalPostAjaxForm(NULL, [], $this->getButtonName('//input[@type="submit" and @data-drupal-selector="edit-test-ref-nested1-form-inline-entity-form-entities-0-form-actions-ief-edit-save"]'));
         $this->drupalPostForm(NULL, [], t('Save'));
     } else {
         $this->drupalPostForm(NULL, $edit, t('Save'));
     }
     $this->nodeStorage->resetCache([$level_2_node->id()]);
     $level_2_node = $this->nodeStorage->load($level_2_node->id());
     $this->assertEqual($level_2_node_update_title, $level_2_node->getTitle());
 }