/** * Test the basic settings. */ public function testBasicSettings() { $manage_display = '/admin/structure/types/manage/article/display'; $this->drupalGet($manage_display); $this->drupalPostAjaxForm(NULL, [], 'body_settings_edit'); $this->drupalPostAjaxForm(NULL, [ 'fields[body][label]' => 'above', 'fields[body][settings_edit_form][third_party_settings][fences][fences_field_tag]' => 'article', 'fields[body][settings_edit_form][third_party_settings][fences][fences_field_classes]' => 'my-field-class', 'fields[body][settings_edit_form][third_party_settings][fences][fences_field_item_tag]' => 'code', 'fields[body][settings_edit_form][third_party_settings][fences][fences_field_item_classes]' => 'my-field-item-class', 'fields[body][settings_edit_form][third_party_settings][fences][fences_label_tag]' => 'h2', 'fields[body][settings_edit_form][third_party_settings][fences][fences_label_classes]' => 'my-label-class', ], ['body_plugin_settings_update' => 'Update']); $this->drupalPostForm(NULL, [], 'Save'); $expected_field_markup = <<<EOD <article class="my-field-class clearfix text-formatted field field--name-body field--type-text-with-summary field--label-above field__items"> <h2 class="my-label-class field__label">Body</h2> <code class="my-field-item-class field__item"> <p>Body field value.</p> </code> </article> EOD; $page = $this->drupalGet('/node/' . $this->node->id()); $this->assertTrue(strpos($this->stripWhitespace($page), $this->stripWhitespace($expected_field_markup)) !== FALSE, 'Found the correct field markup on the page.'); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) { $this->attributeTable = 'uc_product_attributes'; $this->optionTable = 'uc_product_options'; $this->idField = 'nid'; $this->idValue = $node->id(); $attributes = uc_product_get_attributes($node->id()); return parent::buildForm($form, $form_state, $attributes); }
/** * Marks a node as read by the current user right now. * * @param \Symfony\Component\HttpFoundation\Request $request * The request of the page. * @param \Drupal\node\NodeInterface $node * The node whose "last read" timestamp should be updated. */ public function readNode(Request $request, NodeInterface $node) { if ($this->currentUser()->isAnonymous()) { throw new AccessDeniedHttpException(); } // Update the history table, stating that this user viewed this node. history_write($node->id()); return new JsonResponse((int) history_read($node->id())); }
/** * Simulates the scheduled (un)publication of a node. * * @param \Drupal\node\NodeInterface $node * The node to schedule. * @param string $action * The action to perform: either 'publish' or 'unpublish'. Defaults to * 'publish'. * * @return \Drupal\node\NodeInterface * The updated node, after scheduled (un)publication via a cron run. */ protected function schedule(NodeInterface $node, $action = 'publish') { $node_storage = $this->container->get('entity.manager')->getStorage('node'); // Simulate scheduling by setting the (un)publication date in the past and // running cron. $node->{$action . '_on'} = strtotime('-1 day'); $node->save(); scheduler_cron(); $node_storage->resetCache(array($node->id())); return $node_storage->load($node->id()); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) { $query = \Drupal::request()->query->all(); $form['#action'] = Url::fromRoute('<current>')->setOptions(['query' => $query])->toString(); $form['nid'] = array('#type' => 'value', '#value' => $node->id()); $form['qty'] = array('#type' => 'value', '#value' => 1); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Add to cart'), '#id' => 'edit-submit-' . $node->id()); uc_form_alter($form, $form_state, $this->getFormId()); return $form; }
/** * Displays the product features tab on a product node edit form. */ public function featuresOverview(NodeInterface $node) { $header = array($this->t('Type'), $this->t('Description'), $this->t('Operations')); $rows = []; $features = uc_product_feature_load_multiple($node->id()); foreach ($features as $feature) { $operations = array('edit' => array('title' => $this->t('Edit'), 'url' => Url::fromRoute('uc_product.feature_edit', ['node' => $node->id(), 'fid' => $feature->fid, 'pfid' => $feature->pfid])), 'delete' => array('title' => $this->t('Delete'), 'url' => Url::fromRoute('uc_product.feature_delete', ['node' => $node->id(), 'fid' => $feature->fid, 'pfid' => $feature->pfid]))); $rows[] = array(array('data' => uc_product_feature_data($feature->fid, 'title')), array('data' => array('#markup' => $feature->description)), array('data' => array('#type' => 'operations', '#links' => $operations))); } $build['features'] = array('#theme' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => array('class' => array('uc-product-features')), '#empty' => $this->t('No features found for this product.')); $build['add_form'] = $this->formBuilder()->getForm('Drupal\\uc_product\\Form\\ProductFeatureAddForm', $node); return $build; }
protected function setUp() { parent::setUp(); ViewTestData::createTestViews(get_class($this), array('tracker_test_views')); $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); // Add a comment field. $this->addDefaultCommentField('node', 'page'); $permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval'); $account = $this->drupalCreateUser($permissions); $this->drupalLogin($account); $this->node = $this->drupalCreateNode(array('title' => $this->randomMachineName(8), 'uid' => $account->id(), 'status' => 1)); $this->comment = Comment::create(array('entity_id' => $this->node->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'subject' => $this->randomMachineName(), 'comment_body[' . LanguageInterface::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this->randomMachineName(20))); }
/** * Helper function to setup the faq question. * * @param array &$data * Array reference to store display data in. * @param \Drupal\node\NodeInterface $node * The node object. * @param string $path * The path/url which the question should link to if links are disabled. * @param string $anchor * Link anchor to use in question links. */ public static function viewQuestion(&$data, \Drupal\node\NodeInterface $node, $path = NULL, $anchor = NULL) { $faq_settings = \Drupal::config('faq.settings'); $disable_node_links = $faq_settings->get('disable_node_links'); $question = ''; // Don't link to faq node, instead provide no link, or link to current page. if ($disable_node_links) { if (empty($path) && empty($anchor)) { $question = $node->getTitle(); } elseif (empty($path)) { // Can't seem to use l() function with empty string as screen-readers // don't like it, so create anchor name manually. $question = '<a id="' . $anchor . '"></a>' . $node->getTitle(); } else { $options = array(); if ($anchor) { $options['attributes'] = array('id' => $anchor); } $question = l($node->getTitle(), $path, $options); } } else { $node_id = $node->id(); if (empty($anchor)) { $question = l($node->getTitle(), "node/{$node_id})"); } else { $question = l($node->getTitle(), "node/{$node_id}", array("attributes" => array("id" => "{$anchor}"))); } } $question = '<span datatype="" property="dc:title">' . $question . '</span>'; $detailed_question = $node->get('field_detailed_question')->value; if ($faq_settings->get('display') != 'hide_answer' && !empty($detailed_question) && $faq_settings->get('question_length') == 'both') { $question .= '<div class="faq-detailed-question">' . $detailed_question . '</div>'; } $data['question'] = SafeMarkup::set($question); }
/** * Tests that cron clears day counts and expired access logs. */ function testExpiredLogs() { $this->config('statistics.settings')->set('count_content_views', 1)->save(); \Drupal::state()->set('statistics.day_timestamp', 8640000); $this->drupalGet('node/' . $this->testNode->id()); // Manually calling statistics.php, simulating ajax behavior. $nid = $this->testNode->id(); $post = array('nid' => $nid); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $this->client->post($stats_path, array('body' => $post)); $this->drupalGet('node/' . $this->testNode->id()); $this->client->post($stats_path, array('body' => $post)); $this->assertText('1 view', 'Node is viewed once.'); // statistics_cron() will subtract // statistics.settings:accesslog.max_lifetime config from REQUEST_TIME in // the delete query, so wait two secs here to make sure the access log will // be flushed for the node just hit. sleep(2); $this->cronRun(); $this->drupalGet('admin/reports/pages'); $this->assertNoText('node/' . $this->testNode->id(), 'No hit URL found.'); $result = db_select('node_counter', 'nc')->fields('nc', array('daycount'))->condition('nid', $this->testNode->id(), '=')->execute()->fetchField(); $this->assertFalse($result, 'Daycounter is zero.'); }
/** * Tests retaining of node form submissions containing profanity. */ function testRetain() { $this->drupalLogin($this->adminUser); $this->setProtectionUI('node_article_form', FormInterface::MOLLOM_MODE_ANALYSIS, NULL, ['checks[profanity]' => TRUE, 'discard' => 0]); $this->drupalLogout(); // Login and submit a node. $this->drupalLogin($this->webUser); $this->drupalGet('node/add/article'); $edit = ['title[0][value]' => 'profanity', 'body[0][value]' => 'ham profanity']; $this->drupalPostForm(NULL, $edit, t('Save')); $this->node = $this->drupalGetNodeByTitle($edit['title[0][value]']); debug($this->node, 'node'); $this->assertFalse($this->node->isPublished(), t('Node containing profanity was retained as unpublished.')); $this->assertUrl('node/' . $this->node->id()); $this->assertMollomData('node', $this->node->id()); }
protected function setUp() { parent::setUp(); ViewTestData::createTestViews(get_class($this), array('comment_test_views')); // Add two users, create a node with the user1 as author and another node // with user2 as author. For the second node add a comment from user1. $this->account = $this->drupalCreateUser(array('skip comment approval')); $this->account2 = $this->drupalCreateUser(); $this->drupalLogin($this->account); $this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page'))); $this->addDefaultCommentField('node', 'page'); $this->nodeUserPosted = $this->drupalCreateNode(); $this->nodeUserCommented = $this->drupalCreateNode(array('uid' => $this->account2->id())); $comment = array('uid' => $this->loggedInUser->id(), 'entity_id' => $this->nodeUserCommented->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'How much wood would a woodchuck chuck', 'cid' => '', 'pid' => '', 'mail' => '*****@*****.**'); $this->comment = Comment::create($comment); $this->comment->save(); }
/** * Tests if file fields in teasers have correct resources. * * Ensure that file fields have the correct resource as the object in RDFa * when displayed as a teaser. */ function testNodeTeaser() { // Render the teaser. $node_render_array = entity_view_multiple(array($this->node), 'teaser'); $html = drupal_render($node_render_array); // Parses front page where the node is displayed in its teaser form. $parser = new \EasyRdf_Parser_Rdfa(); $graph = new \EasyRdf_Graph(); $base_uri = url('<front>', array('absolute' => TRUE)); $parser->parse($graph, $html, 'rdfa', $base_uri); $node_uri = url('node/' . $this->node->id(), array('absolute' => TRUE)); $file_uri = file_create_url($this->file->getFileUri()); // Node relation to attached file. $expected_value = array('type' => 'uri', 'value' => $file_uri); $this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/2000/01/rdf-schema#seeAlso', $expected_value), 'Node to file relation found in RDF output (rdfs:seeAlso).'); $this->drupalGet('node'); }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { if ($this->bookManager->checkNodeIsRemovable($this->node)) { $this->bookManager->deleteFromBook($this->node->id()); drupal_set_message($this->t('The post has been removed from the book.')); } $form_state['redirect_route'] = $this->getCancelRoute(); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { if ($this->bookManager->checkNodeIsRemovable($this->node)) { $this->bookManager->deleteFromBook($this->node->id()); drupal_set_message($this->t('The post has been removed from the book.')); } $form_state->setRedirectUrl($this->getCancelUrl()); }
/** * Tests Quick Edit autocomplete term behavior. */ public function testAutocompleteQuickEdit() { $this->drupalLogin($this->editor_user); $quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->field_name . '/und/full'; $post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData(); $response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post); $ajax_commands = Json::decode($response); // Prepare form values for submission. drupalPostAJAX() is not suitable for // handling pages with JSON responses, so we need our own solution here. $form_tokens_found = preg_match('/\\sname="form_token" value="([^"]+)"/', $ajax_commands[0]['data'], $token_match) && preg_match('/\\sname="form_build_id" value="([^"]+)"/', $ajax_commands[0]['data'], $build_id_match); $this->assertTrue($form_tokens_found, 'Form tokens found in output.'); if ($form_tokens_found) { $post = array('form_id' => 'quickedit_field_form', 'form_token' => $token_match[1], 'form_build_id' => $build_id_match[1], $this->field_name => implode(', ', array($this->term1->getName(), 'new term', $this->term2->getName())), 'op' => t('Save')); // Submit field form and check response. Should render back all the terms. $response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post); $this->assertResponse(200); $ajax_commands = Json::decode($response); $this->drupalSetContent($ajax_commands[0]['data']); $this->assertLink($this->term1->getName()); $this->assertLink($this->term2->getName()); $this->assertText('new term'); $this->assertNoLink('new term'); // Load the form again, which should now get it back from TempStore. $quickedit_uri = 'quickedit/form/node/' . $this->node->id() . '/' . $this->field_name . '/und/full'; $post = array('nocssjs' => 'true') + $this->getAjaxPageStatePostData(); $response = $this->drupalPost($quickedit_uri, 'application/vnd.drupal-ajax', $post); $ajax_commands = Json::decode($response); // The AjaxResponse's first command is an InsertCommand which contains // the form to edit the taxonomy term field, it should contain all three // taxonomy terms, including the one that has just been newly created and // which is not yet stored. $this->drupalSetContent($ajax_commands[0]['data']); $this->assertFieldByName($this->field_name, implode(', ', array($this->term1->getName(), 'new term', $this->term2->label()))); // Save the entity. $post = array('nocssjs' => 'true'); $response = $this->drupalPost('quickedit/entity/node/' . $this->node->id(), 'application/json', $post); $this->assertResponse(200); // The full node display should now link to all entities, with the new // one created in the database as well. $this->drupalGet('node/' . $this->node->id()); $this->assertLink($this->term1->getName()); $this->assertLink($this->term2->getName()); $this->assertLink('new term'); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installSchema('node', 'node_access'); $this->installEntitySchema('node'); $this->installEntitySchema('user'); $this->installEntitySchema('content_moderation_state'); $this->installConfig('content_moderation'); $node_type = NodeType::create(['type' => 'example']); $node_type->setThirdPartySetting('content_moderation', 'enabled', TRUE); $node_type->setThirdPartySetting('content_moderation', 'allowed_moderation_states', ['draft']); $node_type->setThirdPartySetting('content_moderation', 'default_moderation_state', 'draft'); $node_type->save(); $this->testNode = Node::create(['type' => 'example', 'title' => 'Test title']); $this->testNode->save(); \Drupal::entityTypeManager()->getStorage('node')->resetCache(); $this->testNode = Node::load($this->testNode->id()); }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { $this->nodeStorage->deleteRevision($this->revision->getRevisionId()); watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId())); $node_type = $this->nodeTypeStorage->load($this->revision->bundle())->label(); drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($this->revision->getRevisionCreationTime()), '@type' => $node_type, '%title' => $this->revision->label()))); $form_state['redirect_route'] = array('route_name' => 'node.view', 'route_parameters' => array('node' => $this->revision->id())); if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {node_field_revision} WHERE nid = :nid', array(':nid' => $this->revision->id()))->fetchField() > 1) { $form_state['redirect_route']['route_name'] = 'node.revision_overview'; } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->nodeStorage->deleteRevision($this->revision->getRevisionId()); $this->logger('content')->notice('@type: deleted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId())); $node_type = $this->nodeTypeStorage->load($this->revision->bundle())->label(); drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($this->revision->getRevisionCreationTime()), '@type' => $node_type, '%title' => $this->revision->label()))); $form_state->setRedirect('entity.node.canonical', array('node' => $this->revision->id())); if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {node_field_revision} WHERE nid = :nid', array(':nid' => $this->revision->id()))->fetchField() > 1) { $form_state->setRedirect('entity.node.version_history', array('node' => $this->revision->id())); } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // The revision timestamp will be updated when the revision is saved. Keep // the original one for the confirmation message. $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision = $this->prepareRevertedRevision($this->revision, $form_state); $this->revision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]); $this->revision->save(); $this->logger('content')->notice('@type: reverted %title revision %revision.', ['@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]); drupal_set_message(t('@type %title has been reverted to the revision from %revision-date.', ['@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)])); $form_state->setRedirect('entity.node.version_history', array('node' => $this->revision->id())); }
/** * Text, if the user answered wrong. * * @param \Drupal\node\NodeInterface $node * The node the client form belongs to. * @return array */ public function sorry(NodeInterface $node) { $config = $this->config('field_quiz.settings'); $text = $config->get('field_quiz.test_answer_wrong'); $elements[] = array('#type' => 'html_tag', '#tag' => 'p', '#attributes' => array('style' => 'color: red'), '#value' => $this->t($text)); $url = Url::fromRoute('entity.node.canonical', array('node' => $node->id())); $project_link = Link::fromTextAndUrl(t('Please try again.'), $url); $project_link = $project_link->toRenderable(); // If you need some attributes. $project_link['#attributes'] = array('class' => array('button', 'button-action', 'button--primary', 'button--small')); $elements[] = array('#type' => 'html_tag', '#tag' => 'p', '#attributes' => array(), '#value' => render($project_link)); return $elements; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->revision->setNewRevision(); // Make this the new default revision for the node. $this->revision->isDefaultRevision(TRUE); // The revision timestamp will be updated when the revision is saved. Keep the // original one for the confirmation message. $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision->revision_log = t('Copy of the revision from %date.', array('%date' => format_date($original_revision_timestamp))); $this->revision->save(); $this->logger('content')->notice('@type: reverted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId())); drupal_set_message(t('@type %title has been reverted to the revision from %revision-date.', array('@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => format_date($original_revision_timestamp)))); $form_state->setRedirect('entity.node.version_history', array('node' => $this->revision->id())); }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { $this->revision->setNewRevision(); // Make this the new default revision for the node. $this->revision->isDefaultRevision(TRUE); // The revision timestamp will be updated when the revision is saved. Keep the // original one for the confirmation message. $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision->revision_log = t('Copy of the revision from %date.', array('%date' => format_date($original_revision_timestamp))); $this->revision->save(); watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId())); drupal_set_message(t('@type %title has been reverted back to the revision from %revision-date.', array('@type' => node_get_type_label($this->revision), '%title' => $this->revision->label(), '%revision-date' => format_date($original_revision_timestamp)))); $form_state['redirect_route'] = array('route_name' => 'node.revision_overview', 'route_parameters' => array('node' => $this->revision->id())); }
/** * Tests that image fields in teasers have correct resources. */ function testNodeTeaser() { // Set the display options for the teaser. $display_options = array('type' => 'image', 'settings' => array('image_style' => 'medium', 'image_link' => 'content')); $display = entity_get_display('node', 'article', 'teaser'); $display->setComponent($this->fieldName, $display_options)->save(); // Render the teaser. $node_render_array = node_view($this->node, 'teaser'); $html = drupal_render($node_render_array); // Parse the teaser. $parser = new \EasyRdf_Parser_Rdfa(); $graph = new \EasyRdf_Graph(); $base_uri = url('<front>', array('absolute' => TRUE)); $parser->parse($graph, $html, 'rdfa', $base_uri); // Construct the node and image URIs for testing. $node_uri = url('node/' . $this->node->id(), array('absolute' => TRUE)); $image_uri = entity_load('image_style', 'medium')->buildUrl($this->file->getFileUri()); // Test relations from node to image. $expected_value = array('type' => 'uri', 'value' => $image_uri); $this->assertTrue($graph->hasProperty($node_uri, 'http://ogp.me/ns#image', $expected_value), 'Node to file relation found in RDF output (og:image).'); // Test image type. $expected_value = array('type' => 'uri', 'value' => 'http://xmlns.com/foaf/0.1/Image'); $this->assertTrue($graph->hasProperty($image_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Image type found in RDF output (foaf:Image).'); }
/** * Tests the book navigation block when book is unpublished. * * There was a fatal error with "Show block only on book pages" block mode. */ public function testBookNavigationBlockOnUnpublishedBook() { // Create a new book. $this->createBook(); // Create administrator user. $administratorUser = $this->drupalCreateUser(['administer blocks', 'administer nodes', 'bypass node access']); $this->drupalLogin($administratorUser); // Enable the block with "Show block only on book pages" mode. $this->drupalPlaceBlock('book_navigation', ['block_mode' => 'book pages']); // Unpublish book node. $edit = []; $this->drupalPostForm('node/' . $this->book->id() . '/edit', $edit, t('Save and unpublish')); // Test node page. $this->drupalGet('node/' . $this->book->id()); $this->assertText($this->book->label(), 'Unpublished book with "Show block only on book pages" book navigation settings.'); }
/** * @cover replacePlaceHolders */ public function testBubbleableMetadata() { // Make sure the bubbleable metadata added by the fetcher is properly passed // though. $bubbleable_metadata = new BubbleableMetadata(); // Save the node, so it gets a cache tag. $this->node->save(); $this->placeholderResolver->replacePlaceHolders('test {{node.field_integer}}', ['node' => $this->node->getTypedData()], $bubbleable_metadata); $expected = ['node:' . $this->node->id()]; $this->assertEquals($expected, $bubbleable_metadata->getCacheTags()); // Ensure cache tags of filters are added in. $bubbleable_metadata = new BubbleableMetadata(); $this->placeholderResolver->replacePlaceHolders("test {{ node.created.value | format_date('medium') }}", ['node' => $this->node->getTypedData()], $bubbleable_metadata); $expected = Cache::mergeTags(['node:' . $this->node->id()], DateFormat::load('medium')->getCacheTags()); $this->assertEquals($expected, $bubbleable_metadata->getCacheTags()); }
/** * Update search index and search for comment. */ function assertCommentAccess($assume_access, $message) { // Invoke search index update. search_mark_for_reindex('node_search', $this->node->id()); $this->cronRun(); // Search for the comment subject. $edit = array('keys' => "'" . $this->commentSubject . "'"); $this->drupalPostForm('search/node', $edit, t('Search')); if ($assume_access) { $expected_node_result = $this->assertText($this->node->label()); $expected_comment_result = $this->assertText($this->commentSubject); } else { $expected_node_result = $this->assertText(t('Your search yielded no results.')); $expected_comment_result = $this->assertText(t('Your search yielded no results.')); } $this->assertTrue($expected_node_result && $expected_comment_result, $message); }
public function webform_paymethod_select_continue(\Drupal\node\NodeInterface $node, $submission, $page_num) { // We can't use a simple drupal_get_form() because we wan't to enter the form // at a specific $page_num. $form_state = []; $args = [$node, $submission, TRUE, TRUE]; $form_state['build_info']['args'] = $args; $form_state['storage']['component_tree'] = []; $form_state['storage']['page_count'] = 1; $form_state['storage']['preview'] = !empty($node->webform['preview']); _webform_components_tree_build($node->webform['components'], $form_state['storage']['component_tree'], 0, $form_state['storage']['page_count']); $form_state['storage']['page_num'] = $page_num; if (\Drupal::moduleHandler()->moduleExists('webform_steps')) { $form_state['steps_finished'] = $page_num - 1; } return \Drupal::formBuilder()->buildForm('webform_client_form_' . $node->id(), $form_state); }
protected function setUp() { parent::setUp(); // Use Classy theme for testing markup output. \Drupal::service('theme_handler')->install(['classy']); \Drupal::service('theme_handler')->setDefault('classy'); $this->baseUri = \Drupal::url('<front>', [], ['absolute' => TRUE]); // Create two test users. $this->adminUser = $this->drupalCreateUser(array('administer content types', 'administer comments', 'access comments', 'access content')); $this->webUser = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval', 'access content')); $this->drupalLogin($this->adminUser); // Create term. $this->term = Term::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => 'tags']); $this->term->save(); // Create image. file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = File::create(['uri' => 'public://example.jpg']); $this->image->save(); // Create article. $article_settings = array('type' => 'article', 'promote' => NODE_PROMOTED, 'field_image' => array(array('target_id' => $this->image->id())), 'field_tags' => array(array('target_id' => $this->term->id()))); $this->article = $this->drupalCreateNode($article_settings); // Create second article to test teaser list. $this->drupalCreateNode(array('type' => 'article', 'promote' => NODE_PROMOTED)); // Create article comment. $this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0); // Create page. $this->page = $this->drupalCreateNode(array('type' => 'page')); // Set URIs. // Image. $image_file = $this->article->get('field_image')->entity; $this->imageUri = ImageStyle::load('large')->buildUrl($image_file->getFileUri()); // Term. $this->termUri = $this->term->url('canonical', array('absolute' => TRUE)); // Article. $this->articleUri = $this->article->url('canonical', array('absolute' => TRUE)); // Page. $this->pageUri = $this->page->url('canonical', array('absolute' => TRUE)); // Author. $this->authorUri = $this->adminUser->url('canonical', array('absolute' => TRUE)); // Comment. $this->articleCommentUri = $this->articleComment->url('canonical', array('absolute' => TRUE)); // Commenter. $this->commenterUri = $this->webUser->url('canonical', array('absolute' => TRUE)); $this->drupalLogout(); }
/** * @cover fetchDataByPropertyPath */ public function testBubbleableMetadata() { $this->node->field_integer->setValue([]); // Save the node, so that it gets an ID and it has a cache tag. $this->node->save(); // Also add a user for testing cache tags of references. $user = $this->entityTypeManager->getStorage('user')->create(['name' => 'test', 'type' => 'user']); $user->save(); $this->node->uid->entity = $user; $bubbleable_metadata = new BubbleableMetadata(); $this->dataFetcher->fetchDataByPropertyPath($this->node->getTypedData(), 'title.value', $bubbleable_metadata)->getValue(); $expected = ['node:' . $this->node->id()]; $this->assertEquals($expected, $bubbleable_metadata->getCacheTags()); // Test cache tags of references are added correctly. $this->dataFetcher->fetchDataByPropertyPath($this->node->getTypedData(), 'uid.entity.name', $bubbleable_metadata)->getValue(); $expected = ['node:' . $this->node->id(), 'user:' . $user->id()]; $this->assertEquals($expected, $bubbleable_metadata->getCacheTags()); }
protected function setUp() { parent::setUp(); $this->base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]); // Create two test users. $this->adminUser = $this->drupalCreateUser(array('administer content types', 'administer comments', 'access comments', 'access content')); $this->webUser = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval', 'access content')); $this->drupalLogin($this->adminUser); // Create term. $this->term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => 'tags')); $this->term->save(); // Create image. file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = entity_create('file', array('uri' => 'public://example.jpg')); $this->image->save(); // Create article. $article_settings = array('type' => 'article', 'promote' => NODE_PROMOTED, 'field_image' => array(array('target_id' => $this->image->id())), 'field_tags' => array(array('target_id' => $this->term->id()))); $this->article = $this->drupalCreateNode($article_settings); // Create second article to test teaser list. $this->drupalCreateNode(array('type' => 'article', 'promote' => NODE_PROMOTED)); // Create article comment. $this->articleComment = $this->saveComment($this->article->id(), $this->webUser->id(), NULL, 0); // Create page. $this->page = $this->drupalCreateNode(array('type' => 'page')); // Set URIs. // Image. $image_file = $this->article->get('field_image')->entity; $this->imageUri = entity_load('image_style', 'large')->buildUrl($image_file->getFileUri()); // Term. $this->termUri = $this->term->url('canonical', array('absolute' => TRUE)); // Article. $this->articleUri = $this->article->url('canonical', array('absolute' => TRUE)); // Page. $this->pageUri = $this->page->url('canonical', array('absolute' => TRUE)); // Author. $this->authorUri = $this->adminUser->url('canonical', array('absolute' => TRUE)); // Comment. $this->articleCommentUri = $this->articleComment->url('canonical', array('absolute' => TRUE)); // Commenter. $this->commenterUri = $this->webUser->url('canonical', array('absolute' => TRUE)); $this->drupalLogout(); }