• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Entity\Comment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Comment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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' => '[email protected]', '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


示例4: 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


示例5: testCommentNodeCommentStatistics

 /**
  * Tests the node comment statistics.
  */
 function testCommentNodeCommentStatistics()
 {
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     // Set comments to have subject and preview disabled.
     $this->drupalLogin($this->adminUser);
     $this->setCommentPreview(DRUPAL_DISABLED);
     $this->setCommentForm(TRUE);
     $this->setCommentSubject(FALSE);
     $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
     $this->drupalLogout();
     // Checks the initial values of node comment statistics with no comment.
     $node = $node_storage->load($this->node->id());
     $this->assertEqual($node->get('comment')->last_comment_timestamp, $this->node->getCreatedTime(), 'The initial value of node last_comment_timestamp is the node created date.');
     $this->assertEqual($node->get('comment')->last_comment_name, NULL, 'The initial value of node last_comment_name is NULL.');
     $this->assertEqual($node->get('comment')->last_comment_uid, $this->webUser->id(), 'The initial value of node last_comment_uid is the node uid.');
     $this->assertEqual($node->get('comment')->comment_count, 0, 'The initial value of node comment_count is zero.');
     // Post comment #1 as web_user2.
     $this->drupalLogin($this->webUser2);
     $comment_text = $this->randomMachineName();
     $this->postComment($this->node, $comment_text);
     // Checks the new values of node comment statistics with comment #1.
     // The node cache needs to be reset before reload.
     $node_storage->resetCache(array($this->node->id()));
     $node = $node_storage->load($this->node->id());
     $this->assertEqual($node->get('comment')->last_comment_name, NULL, 'The value of node last_comment_name is NULL.');
     $this->assertEqual($node->get('comment')->last_comment_uid, $this->webUser2->id(), 'The value of node last_comment_uid is the comment #1 uid.');
     $this->assertEqual($node->get('comment')->comment_count, 1, 'The value of node comment_count is 1.');
     // Prepare for anonymous comment submission (comment approval enabled).
     $this->drupalLogin($this->adminUser);
     user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array('access comments' => TRUE, 'post comments' => TRUE, 'skip comment approval' => FALSE));
     // Ensure that the poster can leave some contact info.
     $this->setCommentAnonymous('1');
     $this->drupalLogout();
     // Post comment #2 as anonymous (comment approval enabled).
     $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');
     $anonymous_comment = $this->postComment($this->node, $this->randomMachineName(), '', TRUE);
     // Checks the new values of node comment statistics with comment #2 and
     // ensure they haven't changed since the comment has not been moderated.
     // The node needs to be reloaded with the cache reset.
     $node_storage->resetCache(array($this->node->id()));
     $node = $node_storage->load($this->node->id());
     $this->assertEqual($node->get('comment')->last_comment_name, NULL, 'The value of node last_comment_name is still NULL.');
     $this->assertEqual($node->get('comment')->last_comment_uid, $this->webUser2->id(), 'The value of node last_comment_uid is still the comment #1 uid.');
     $this->assertEqual($node->get('comment')->comment_count, 1, 'The value of node comment_count is still 1.');
     // Prepare for anonymous comment submission (no approval required).
     $this->drupalLogin($this->adminUser);
     user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array('access comments' => TRUE, 'post comments' => TRUE, 'skip comment approval' => TRUE));
     $this->drupalLogout();
     // Post comment #3 as anonymous.
     $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');
     $anonymous_comment = $this->postComment($this->node, $this->randomMachineName(), '', array('name' => $this->randomMachineName()));
     $comment_loaded = Comment::load($anonymous_comment->id());
     // Checks the new values of node comment statistics with comment #3.
     // The node needs to be reloaded with the cache reset.
     $node_storage->resetCache(array($this->node->id()));
     $node = $node_storage->load($this->node->id());
     $this->assertEqual($node->get('comment')->last_comment_name, $comment_loaded->getAuthorName(), 'The value of node last_comment_name is the name of the anonymous user.');
     $this->assertEqual($node->get('comment')->last_comment_uid, 0, 'The value of node last_comment_uid is zero.');
     $this->assertEqual($node->get('comment')->comment_count, 2, 'The value of node comment_count is 2.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:63,代码来源:CommentStatisticsTest.php


示例6: 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


示例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

 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


示例9: 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


示例10: 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' => '[email protected]');
     $this->comment = Comment::create($comment);
     $this->comment->save();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:CommentTestBase.php


示例11: 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


示例12: 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' => '[email protected]', '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


示例13: 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


示例14: 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


示例15: testCommentUnpublishByKeyword

 /**
  * Tests the unpublish comment by keyword action.
  */
 function testCommentUnpublishByKeyword()
 {
     $this->drupalLogin($this->adminUser);
     $keyword_1 = $this->randomMachineName();
     $keyword_2 = $this->randomMachineName();
     $action = entity_create('action', array('id' => 'comment_unpublish_by_keyword_action', 'label' => $this->randomMachineName(), 'type' => 'comment', 'configuration' => array('keywords' => array($keyword_1, $keyword_2)), 'plugin' => 'comment_unpublish_by_keyword_action'));
     $action->save();
     $comment = $this->postComment($this->node, $keyword_2, $this->randomMachineName());
     // Load the full comment so that status is available.
     $comment = Comment::load($comment->id());
     $this->assertTrue($comment->isPublished() === TRUE, 'The comment status was set to published.');
     $action->execute(array($comment));
     $this->assertTrue($comment->isPublished() === FALSE, 'The comment status was set to not published.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:17,代码来源:CommentActionsTest.php


示例16: 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


示例17: 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


示例18: testNodeDeletion

 /**
  * Tests that comments are deleted with the node.
  */
 function testNodeDeletion()
 {
     $this->drupalLogin($this->webUser);
     $comment = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
     $this->assertTrue($comment->id(), 'The comment could be loaded.');
     $this->node->delete();
     $this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.');
     // Make sure the comment field storage and all its fields are deleted when
     // the node type is deleted.
     $this->assertNotNull(FieldStorageConfig::load('node.comment'), 'Comment field storage exists');
     $this->assertNotNull(FieldConfig::load('node.article.comment'), 'Comment field exists');
     // Delete the node type.
     entity_delete_multiple('node_type', array($this->node->bundle()));
     $this->assertNull(FieldStorageConfig::load('node.comment'), 'Comment field storage deleted');
     $this->assertNull(FieldConfig::load('node.article.comment'), 'Comment field deleted');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:19,代码来源:CommentNodeChangesTest.php


示例19: testNodeDeletion

 /**
  * Tests that comments are deleted with the node.
  */
 function testNodeDeletion()
 {
     $this->drupalLogin($this->web_user);
     $comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
     $this->assertTrue($comment->id(), 'The comment could be loaded.');
     $this->node->delete();
     $this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.');
     // Make sure the comment field and all its instances are deleted when node
     // type is deleted.
     $this->assertNotNull(entity_load('field_storage_config', 'node.comment'), 'Comment field exists');
     $this->assertNotNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance exists');
     // Delete the node type.
     entity_delete_multiple('node_type', array($this->node->bundle()));
     $this->assertNull(entity_load('field_storage_config', 'node.comment'), 'Comment field deleted');
     $this->assertNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance deleted');
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:19,代码来源:CommentNodeChangesTest.php


示例20: testCommentMigration

 /**
  * Tests migration of comments from Drupal 7.
  */
 public function testCommentMigration()
 {
     $comment = Comment::load(1);
     $this->assertTrue($comment instanceof CommentInterface);
     /** @var \Drupal\comment\CommentInterface $comment */
     $this->assertIdentical('A comment', $comment->getSubject());
     $this->assertIdentical('1421727536', $comment->getCreatedTime());
     $this->assertIdentical('1421727536', 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Entity\CommentType类代码示例发布时间:2022-05-23
下一篇:
PHP Entity\Block类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap