当前位置: 首页>>代码示例>>PHP>>正文


PHP Comment::create方法代码示例

本文整理汇总了PHP中Drupal\comment\Entity\Comment::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::create方法的具体用法?PHP Comment::create怎么用?PHP Comment::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\comment\Entity\Comment的用法示例。


在下文中一共展示了Comment::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('page_title_block');
     // Create Basic page node type.
     $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
     $vocabulary = Vocabulary::create(['name' => $this->randomMachineName(), 'description' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('page' => 'page'), 'weight' => mt_rand(0, 10)]);
     $vocabulary->save();
     // Create a field.
     $field_name = Unicode::strtolower($this->randomMachineName());
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('node', 'page', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     // Create a time in the past for the archive.
     $time = REQUEST_TIME - 3600;
     $this->addDefaultCommentField('node', 'page');
     for ($i = 0; $i <= 10; $i++) {
         $user = $this->drupalCreateUser();
         $term = $this->createTerm($vocabulary);
         $values = array('created' => $time, 'type' => 'page');
         $values[$field_name][]['target_id'] = $term->id();
         // Make every other node promoted.
         if ($i % 2) {
             $values['promote'] = TRUE;
         }
         $values['body'][]['value'] = \Drupal::l('Node ' . 1, new Url('entity.node.canonical', ['node' => 1]));
         $node = $this->drupalCreateNode($values);
         $comment = array('uid' => $user->id(), 'status' => CommentInterface::PUBLISHED, 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment');
         Comment::create($comment)->save();
     }
     // Some views, such as the "Who's Online" view, only return results if at
     // least one user is logged in.
     $account = $this->drupalCreateUser(array());
     $this->drupalLogin($account);
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:34,代码来源:DefaultViewsTest.php

示例2: setUp

 protected function setUp()
 {
     parent::setUp();
     // Create a new content type
     $content_type = $this->drupalCreateContentType();
     // Add a node of the new content type.
     $node_data = array('type' => $content_type->id());
     $this->addDefaultCommentField('node', $content_type->id());
     $this->node = $this->drupalCreateNode($node_data);
     // Force a flush of the in-memory storage.
     $this->container->get('views.views_data')->clear();
     // Create some comments and attach them to the created node.
     for ($i = 0; $i < $this->masterDisplayResults; $i++) {
         /** @var \Drupal\comment\CommentInterface $comment */
         $comment = Comment::create(array('status' => CommentInterface::PUBLISHED, 'field_name' => 'comment', 'entity_type' => 'node', 'entity_id' => $this->node->id()));
         $comment->setOwnerId(0);
         $comment->setSubject('Test comment ' . $i);
         $comment->comment_body->value = 'Test body ' . $i;
         $comment->comment_body->format = 'full_html';
         // Ensure comments are sorted in ascending order.
         $time = REQUEST_TIME + ($this->masterDisplayResults - $i);
         $comment->setCreatedTime($time);
         $comment->changed->value = $time;
         $comment->save();
     }
     // Store all the nodes just created to access their properties on the tests.
     $this->commentsCreated = Comment::loadMultiple();
     // Sort created comments in descending order.
     ksort($this->commentsCreated, SORT_NUMERIC);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:30,代码来源:DefaultViewRecentCommentsTest.php

示例3: testCommentForm_2698811

    /**
     * Ensure comment form works with history and big_pipe modules.
     *
     * @see https://www.drupal.org/node/2698811
     */
    public function testCommentForm_2698811()
    {
        $this->assertTrue($this->container->get('module_installer')->install(['comment', 'history', 'ckeditor'], TRUE), 'Installed modules.');
        // Ensure an `article` node type exists.
        $this->createContentType(['type' => 'article']);
        $this->addDefaultCommentField('node', 'article');
        // Enable CKEditor.
        $format = $this->randomMachineName();
        FilterFormat::create(['format' => $format, 'name' => $this->randomString(), 'weight' => 1, 'filters' => []])->save();
        $settings['toolbar']['rows'] = [[['name' => 'Links', 'items' => ['DrupalLink', 'DrupalUnlink']]]];
        $editor = Editor::create(['format' => $format, 'editor' => 'ckeditor']);
        $editor->setSettings($settings);
        $editor->save();
        $admin_user = $this->drupalCreateUser(['access comments', 'post comments', 'use text format ' . $format]);
        $this->drupalLogin($admin_user);
        $node = $this->createNode(['type' => 'article', 'comment' => CommentItemInterface::OPEN]);
        // Create some comments.
        foreach (range(1, 5) as $i) {
            $comment = Comment::create(['status' => CommentInterface::PUBLISHED, 'field_name' => 'comment', 'entity_type' => 'node', 'entity_id' => $node->id()]);
            $comment->save();
        }
        $this->drupalGet($node->toUrl()->toString());
        // Confirm that CKEditor loaded.
        $javascript = <<<JS
    (function(){
      return Object.keys(CKEDITOR.instances).length > 0;
    }());
JS;
        $this->assertJsCondition($javascript);
    }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:35,代码来源:BigPipeRegressionTest.php

示例4: setUp

 function setUp()
 {
     parent::setUp();
     $this->drupalLogin($this->drupalCreateUser(['access comments']));
     // Add two new languages.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Set up comment titles.
     $this->commentTitles = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
     // Create a new comment. Using the one created earlier will not work,
     // as it predates the language set-up.
     $comment = array('uid' => $this->loggedInUser->id(), 'entity_id' => $this->nodeUserCommented->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'cid' => '', 'pid' => '', 'node_type' => '');
     $this->comment = Comment::create($comment);
     // Add field values and translate the comment.
     $this->comment->subject->value = $this->commentTitles['en'];
     $this->comment->comment_body->value = $this->commentTitles['en'];
     $this->comment->langcode = 'en';
     $this->comment->save();
     foreach (array('es', 'fr') as $langcode) {
         $translation = $this->comment->addTranslation($langcode, array());
         $translation->comment_body->value = $this->commentTitles[$langcode];
         $translation->subject->value = $this->commentTitles[$langcode];
     }
     $this->comment->save();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:25,代码来源:CommentFieldFilterTest.php

示例5: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp($import_test_views = TRUE)
 {
     parent::setUp($import_test_views);
     $this->installEntitySchema('user');
     $this->installEntitySchema('comment');
     // Create the anonymous role.
     $this->installConfig(['user']);
     // Create an anonymous user.
     $storage = \Drupal::entityManager()->getStorage('user');
     // Insert a row for the anonymous user.
     $storage->create(array('uid' => 0, 'name' => '', 'status' => 0))->save();
     $admin_role = Role::create(['id' => 'admin', 'permissions' => ['administer comments', 'access user profiles']]);
     $admin_role->save();
     /* @var \Drupal\user\RoleInterface $anonymous_role */
     $anonymous_role = Role::load(Role::ANONYMOUS_ID);
     $anonymous_role->grantPermission('access comments');
     $anonymous_role->save();
     $this->adminUser = User::create(['name' => $this->randomMachineName(), 'roles' => [$admin_role->id()]]);
     $this->adminUser->save();
     // Create some comments.
     $comment = Comment::create(['subject' => 'My comment title', 'uid' => $this->adminUser->id(), 'name' => $this->adminUser->label(), 'entity_type' => 'entity_test', 'comment_type' => 'entity_test', 'status' => 1]);
     $comment->save();
     $comment_anonymous = Comment::create(['subject' => 'Anonymous comment title', 'uid' => 0, 'name' => 'barry', 'mail' => 'test@example.com', 'homepage' => 'https://example.com', 'entity_type' => 'entity_test', 'comment_type' => 'entity_test', 'created' => 123456, 'status' => 1]);
     $comment_anonymous->save();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:CommentUserNameTest.php

示例6: setUp

 /**
  * Performs setup tasks before each individual test method is run.
  */
 public function setUp()
 {
     parent::setUp('content_access');
     // The parent method already installs most needed node and comment schemas,
     // but here we also need the comment statistics.
     $this->installSchema('comment', array('comment_entity_statistics'));
     // Create a node type for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     // Create anonymous user role.
     $role = Role::create(array('id' => 'anonymous', 'label' => 'anonymous'));
     $role->save();
     // Insert the anonymous user into the database, as the user table is inner
     // joined by \Drupal\comment\CommentStorage.
     User::create(array('uid' => 0, 'name' => ''))->save();
     // Create a node with attached comment.
     $this->nodes[0] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'test title'));
     $this->nodes[0]->save();
     $comment_type = CommentType::create(array('id' => 'comment', 'target_entity_type_id' => 'node'));
     $comment_type->save();
     $this->installConfig(array('comment'));
     $this->addDefaultCommentField('node', 'page');
     $comment = Comment::create(array('entity_type' => 'node', 'entity_id' => $this->nodes[0]->id(), 'field_name' => 'comment', 'body' => 'test body', 'comment_type' => $comment_type->id()));
     $comment->save();
     $this->comments[] = $comment;
     $this->nodes[1] = Node::create(array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => 'some title'));
     $this->nodes[1]->save();
     $this->nodes[2] = Node::create(array('status' => NODE_NOT_PUBLISHED, 'type' => 'page', 'title' => 'other title'));
     $this->nodes[2]->save();
     // Also index users, to verify that they are unaffected by the processor.
     $this->index->set('datasources', array('entity:comment', 'entity:node', 'entity:user'));
     $this->index->save();
     $this->index = entity_load('search_api_index', $this->index->id(), TRUE);
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:37,代码来源:ContentAccessTest.php

示例7: testGetEntity

 /**
  * Tests the getEntity method.
  */
 public function testGetEntity()
 {
     // The view is a view of comments, their nodes and their authors, so there
     // are three layers of entities.
     $account = User::create(['name' => $this->randomMachineName(), 'bundle' => 'user']);
     $account->save();
     $node = Node::create(['uid' => $account->id(), 'type' => 'page', 'title' => $this->randomString()]);
     $node->save();
     $comment = Comment::create(array('uid' => $account->id(), 'entity_id' => $node->id(), 'entity_type' => 'node', 'field_name' => 'comment'));
     $comment->save();
     $user = $this->drupalCreateUser(['access comments']);
     $this->drupalLogin($user);
     $view = Views::getView('test_field_get_entity');
     $this->executeView($view);
     $row = $view->result[0];
     // Tests entities on the base level.
     $entity = $view->field['cid']->getEntity($row);
     $this->assertEqual($entity->id(), $comment->id(), 'Make sure the right comment entity got loaded.');
     // Tests entities as relationship on first level.
     $entity = $view->field['nid']->getEntity($row);
     $this->assertEqual($entity->id(), $node->id(), 'Make sure the right node entity got loaded.');
     // Tests entities as relationships on second level.
     $entity = $view->field['uid']->getEntity($row);
     $this->assertEqual($entity->id(), $account->id(), 'Make sure the right user entity got loaded.');
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:28,代码来源:FieldEntityTest.php

示例8: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->addDefaultCommentField('node', 'page', $this->fieldName);
     $this->customComment = Comment::create(['entity_id' => $this->nodeUserCommented->id(), 'entity_type' => 'node', 'field_name' => $this->fieldName]);
     $this->customComment->save();
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:10,代码来源:CommentFieldNameTest.php

示例9: testForumUninstallWithField

 /**
  * Tests if forum module uninstallation properly deletes the field.
  */
 public function testForumUninstallWithField()
 {
     $this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'administer nodes', 'administer modules', 'delete any forum content', 'administer content types']));
     // Ensure that the field exists before uninstallation.
     $field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums');
     $this->assertNotNull($field_storage, 'The taxonomy_forums field storage exists.');
     // Create a taxonomy term.
     $term = Term::create(['name' => t('A term'), 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), 'description' => '', 'parent' => array(0), 'vid' => 'forums', 'forum_container' => 0]);
     $term->save();
     // Create a forum node.
     $node = $this->drupalCreateNode(array('title' => 'A forum post', 'type' => 'forum', 'taxonomy_forums' => array(array('target_id' => $term->id()))));
     // Create at least one comment against the forum node.
     $comment = Comment::create(array('entity_id' => $node->nid->value, 'entity_type' => 'node', 'field_name' => 'comment_forum', 'pid' => 0, 'uid' => 0, 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomMachineName(), 'hostname' => '127.0.0.1'));
     $comment->save();
     // Attempt to uninstall forum.
     $this->drupalGet('admin/modules/uninstall');
     // Assert forum is required.
     $this->assertNoFieldByName('uninstall[forum]');
     $this->assertText('To uninstall Forum, first delete all Forum content');
     // Delete the node.
     $this->drupalPostForm('node/' . $node->id() . '/delete', array(), t('Delete'));
     // Attempt to uninstall forum.
     $this->drupalGet('admin/modules/uninstall');
     // Assert forum is still required.
     $this->assertNoFieldByName('uninstall[forum]');
     $this->assertText('To uninstall Forum, first delete all Forums terms');
     // Delete any forum terms.
     $vid = $this->config('forum.settings')->get('vocabulary');
     $terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vid]);
     foreach ($terms as $term) {
         $term->delete();
     }
     // Ensure that the forum node type can not be deleted.
     $this->drupalGet('admin/structure/types/manage/forum');
     $this->assertNoLink(t('Delete'));
     // Now attempt to uninstall forum.
     $this->drupalGet('admin/modules/uninstall');
     // Assert forum is no longer required.
     $this->assertFieldByName('uninstall[forum]');
     $this->drupalPostForm('admin/modules/uninstall', array('uninstall[forum]' => 1), t('Uninstall'));
     $this->drupalPostForm(NULL, [], t('Uninstall'));
     // Check that the field is now deleted.
     $field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums');
     $this->assertNull($field_storage, 'The taxonomy_forums field storage has been deleted.');
     // Check that a node type with a machine name of forum can be created after
     // uninstalling the forum module and the node type is not locked.
     $edit = array('name' => 'Forum', 'title_label' => 'title for forum', 'type' => 'forum');
     $this->drupalPostForm('admin/structure/types/add', $edit, t('Save content type'));
     $this->assertTrue((bool) NodeType::load('forum'), 'Node type with machine forum created.');
     $this->drupalGet('admin/structure/types/manage/forum');
     $this->clickLink(t('Delete'));
     $this->drupalPostForm(NULL, array(), t('Delete'));
     $this->assertResponse(200);
     $this->assertFalse((bool) NodeType::load('forum'), 'Node type with machine forum deleted.');
     // Double check everything by reinstalling the forum module again.
     $this->drupalPostForm('admin/modules', ['modules[Core][forum][enable]' => 1], 'Install');
     $this->assertText('Module Forum has been enabled.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:61,代码来源:ForumUninstallTest.php

示例10: setUp

 protected function setUp()
 {
     parent::setUp();
     // Add another anonymous comment.
     $comment = array('uid' => 0, 'entity_id' => $this->nodeUserCommented->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'A lot, apparently', 'cid' => '', 'pid' => $this->comment->id(), 'mail' => 'someone@example.com', 'name' => 'bobby tables', 'hostname' => 'public.example.com');
     $this->comment = Comment::create($comment);
     $this->comment->save();
     $user = $this->drupalCreateUser(['access comments']);
     $this->drupalLogin($user);
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:10,代码来源:CommentRestExportTest.php

示例11: testCommentUserUIDTest

 function testCommentUserUIDTest()
 {
     // Add an additional comment which is not created by the user.
     $new_user = User::create(['name' => 'new user']);
     $new_user->save();
     $comment = Comment::create(['uid' => $new_user->uid->value, 'entity_id' => $this->nodeUserCommented->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'subject' => 'if a woodchuck could chuck wood.']);
     $comment->save();
     $view = Views::getView('test_comment_user_uid');
     $this->executeView($view, array($this->account->id()));
     $result_set = array(array('nid' => $this->nodeUserPosted->id()), array('nid' => $this->nodeUserCommented->id()));
     $column_map = array('nid' => 'nid');
     $this->assertIdenticalResultset($view, $result_set, $column_map);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:13,代码来源:ArgumentUserUIDTest.php

示例12: setUp

 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)));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:13,代码来源:TrackerTestBase.php

示例13: testCommentNewCommentsIndicator

 /**
  * Tests new comment marker.
  */
 public function testCommentNewCommentsIndicator()
 {
     // Test if the right links are displayed when no comment is present for the
     // node.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('node');
     $this->assertNoLink(t('@count comments', array('@count' => 0)));
     $this->assertLink(t('Read more'));
     // Verify the data-history-node-last-comment-timestamp attribute, which is
     // used by the drupal.node-new-comments-link library to determine whether
     // a "x new comments" link might be necessary or not. We do this in
     // JavaScript to prevent breaking the render cache.
     $this->assertIdentical(0, count($this->xpath('//*[@data-history-node-last-comment-timestamp]')), 'data-history-node-last-comment-timestamp attribute is not set.');
     // Create a new comment. This helper function may be run with different
     // comment settings so use $comment->save() to avoid complex setup.
     /** @var \Drupal\comment\CommentInterface $comment */
     $comment = Comment::create(array('cid' => NULL, 'entity_id' => $this->node->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'pid' => 0, 'uid' => $this->loggedInUser->id(), 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomMachineName(), 'hostname' => '127.0.0.1', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'comment_body' => array(LanguageInterface::LANGCODE_NOT_SPECIFIED => array($this->randomMachineName()))));
     $comment->save();
     $this->drupalLogout();
     // Log in with 'web user' and check comment links.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('node');
     // Verify the data-history-node-last-comment-timestamp attribute. Given its
     // value, the drupal.node-new-comments-link library would determine that the
     // node received a comment after the user last viewed it, and hence it would
     // perform an HTTP request to render the "new comments" node link.
     $this->assertIdentical(1, count($this->xpath('//*[@data-history-node-last-comment-timestamp="' . $comment->getChangedTime() . '"]')), 'data-history-node-last-comment-timestamp attribute is set to the correct value.');
     $this->assertIdentical(1, count($this->xpath('//*[@data-history-node-field-name="comment"]')), 'data-history-node-field-name attribute is set to the correct value.');
     // The data will be pre-seeded on this particular page in drupalSettings, to
     // avoid the need for the client to make a separate request to the server.
     $settings = $this->getDrupalSettings();
     $this->assertEqual($settings['history'], ['lastReadTimestamps' => [1 => 0]]);
     $this->assertEqual($settings['comment'], ['newCommentsLinks' => ['node' => ['comment' => [1 => ['new_comment_count' => 1, 'first_new_comment_link' => Url::fromRoute('entity.node.canonical', ['node' => 1])->setOptions(['fragment' => 'new'])->toString()]]]]]);
     // Pretend the data was not present in drupalSettings, i.e. test the
     // separate request to the server.
     $response = $this->renderNewCommentsNodeLinks(array($this->node->id()));
     $this->assertResponse(200);
     $json = Json::decode($response);
     $expected = array($this->node->id() => array('new_comment_count' => 1, 'first_new_comment_link' => $this->node->url('canonical', array('fragment' => 'new'))));
     $this->assertIdentical($expected, $json);
     // Failing to specify node IDs for the endpoint should return a 404.
     $this->renderNewCommentsNodeLinks(array());
     $this->assertResponse(404);
     // Accessing the endpoint as the anonymous user should return a 403.
     $this->drupalLogout();
     $this->renderNewCommentsNodeLinks(array($this->node->id()));
     $this->assertResponse(403);
     $this->renderNewCommentsNodeLinks(array());
     $this->assertResponse(403);
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:53,代码来源:CommentNewIndicatorTest.php

示例14: testCommentLinks

 /**
  * Tests that comment links are output and can be hidden.
  */
 public function testCommentLinks()
 {
     // Bartik theme alters comment links, so use a different theme.
     \Drupal::service('theme_handler')->install(array('stark'));
     $this->config('system.theme')->set('default', 'stark')->save();
     // Remove additional user permissions from $this->webUser added by setUp(),
     // since this test is limited to anonymous and authenticated roles only.
     $roles = $this->webUser->getRoles();
     entity_delete_multiple('user_role', array(reset($roles)));
     // Create a comment via CRUD API functionality, since
     // $this->postComment() relies on actual user permissions.
     $comment = Comment::create(array('cid' => NULL, 'entity_id' => $this->node->id(), 'entity_type' => 'node', 'field_name' => 'comment', 'pid' => 0, 'uid' => 0, 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomMachineName(), 'hostname' => '127.0.0.1', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'comment_body' => array(LanguageInterface::LANGCODE_NOT_SPECIFIED => array($this->randomMachineName()))));
     $comment->save();
     $this->comment = $comment;
     // Change comment settings.
     $this->setCommentSettings('form_location', CommentItemInterface::FORM_BELOW, 'Set comment form location');
     $this->setCommentAnonymous(TRUE);
     $this->node->comment = CommentItemInterface::OPEN;
     $this->node->save();
     // Change user permissions.
     $perms = array('access comments' => 1, 'post comments' => 1, 'skip comment approval' => 1, 'edit own comments' => 1);
     user_role_change_permissions(RoleInterface::ANONYMOUS_ID, $perms);
     $nid = $this->node->id();
     // Assert basic link is output, actual functionality is unit-tested in
     // \Drupal\comment\Tests\CommentLinkBuilderTest.
     foreach (array('node', "node/{$nid}") as $path) {
         $this->drupalGet($path);
         // In teaser view, a link containing the comment count is always
         // expected.
         if ($path == 'node') {
             $this->assertLink(t('1 comment'));
         }
         $this->assertLink('Add new comment');
     }
     // Make sure we can hide node links.
     entity_get_display('node', $this->node->bundle(), 'default')->removeComponent('links')->save();
     $this->drupalGet($this->node->urlInfo());
     $this->assertNoLink('1 comment');
     $this->assertNoLink('Add new comment');
     // Visit the full node, make sure there are links for the comment.
     $this->drupalGet('node/' . $this->node->id());
     $this->assertText($comment->getSubject());
     $this->assertLink('Reply');
     // Make sure we can hide comment links.
     entity_get_display('comment', 'comment', 'default')->removeComponent('links')->save();
     $this->drupalGet('node/' . $this->node->id());
     $this->assertText($comment->getSubject());
     $this->assertNoLink('Reply');
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:52,代码来源:CommentLinksTest.php

示例15: setUp

 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' => 'someone@example.com');
     $this->comment = Comment::create($comment);
     $this->comment->save();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:CommentTestBase.php


注:本文中的Drupal\comment\Entity\Comment::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。