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

PHP views\Views类代码示例

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

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



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

示例1: testStyleUI

 /**
  * Tests changing the style plugin and changing some options of a style.
  */
 public function testStyleUI()
 {
     $view_name = 'test_view';
     $view_edit_url = "admin/structure/views/view/{$view_name}/edit";
     $style_plugin_url = "admin/structure/views/nojs/display/{$view_name}/default/style";
     $style_options_url = "admin/structure/views/nojs/display/{$view_name}/default/style_options";
     $this->drupalGet($style_plugin_url);
     $this->assertFieldByName('style[type]', 'default', 'The default style plugin selected in the UI should be unformatted list.');
     $edit = array('style[type]' => 'test_style');
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     $this->assertFieldByName('style_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.');
     $random_name = $this->randomMachineName();
     $edit = array('style_options[test_option]' => $random_name);
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     $this->drupalGet($style_options_url);
     $this->assertFieldByName('style_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.');
     $this->drupalPostForm($view_edit_url, array(), t('Save'));
     $this->assertLink(t('Test style plugin'), 0, 'Make sure the test style plugin is shown in the UI');
     $view = Views::getView($view_name);
     $view->initDisplay();
     $style = $view->display_handler->getOption('style');
     $this->assertEqual($style['type'], 'test_style', 'Make sure that the test_style got saved as used style plugin.');
     $this->assertEqual($style['options']['test_option'], $random_name, 'Make sure that the custom settings field got saved as expected.');
     // Test that fields are working correctly in the UI for style plugins when
     // a field row plguin is selected.
     $this->drupalPostForm("admin/structure/views/view/{$view_name}/edit", array(), 'Add Page');
     $this->drupalPostForm("admin/structure/views/nojs/display/{$view_name}/page_1/row", array('row[type]' => 'fields'), t('Apply'));
     // If fields are being used this text will not be shown.
     $this->assertNoText(t('The selected style or row format does not utilize fields.'));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:33,代码来源:StyleUITest.php


示例2: testCalculateDependencies

 /**
  * Tests the calculateDependencies method.
  */
 public function testCalculateDependencies()
 {
     $comment_type = entity_create('comment_type', array('id' => 'comment', 'label' => 'Comment settings', 'description' => 'Comment settings', 'target_entity_type_id' => 'node'));
     $comment_type->save();
     $content_type = entity_create('node_type', array('type' => $this->randomMachineName(), 'name' => $this->randomString()));
     $content_type->save();
     $field_storage = entity_create('field_storage_config', array('field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'node', 'type' => 'comment'));
     $field_storage->save();
     entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => $content_type->id(), 'label' => $this->randomMachineName() . '_label', 'description' => $this->randomMachineName() . '_description', 'settings' => array('comment_type' => $comment_type->id())))->save();
     entity_create('field_config', array('field_storage' => FieldStorageConfig::loadByName('node', 'body'), 'bundle' => $content_type->id(), 'label' => $this->randomMachineName() . '_body', 'settings' => array('display_summary' => TRUE)))->save();
     $expected = [];
     $expected['test_field_get_entity'] = ['module' => ['comment', 'node', 'user']];
     // Tests dependencies of relationships.
     $expected['test_relationship_dependency'] = ['module' => ['comment', 'node', 'user']];
     $expected['test_plugin_dependencies'] = ['module' => ['comment', 'views_test_data'], 'content' => ['RowTest', 'StaticTest', 'StyleTest']];
     $expected['test_argument_dependency'] = ['config' => ['core.entity_view_mode.node.teaser', 'field.storage.node.body'], 'content' => ['ArgumentDefaultTest', 'ArgumentValidatorTest'], 'module' => ['node', 'search', 'text', 'user']];
     foreach ($this::$testViews as $view_id) {
         $view = Views::getView($view_id);
         $dependencies = $view->calculateDependencies();
         $this->assertEqual($expected[$view_id], $dependencies);
         $config = $this->config('views.view.' . $view_id);
         \Drupal::service('config.storage.staging')->write($view_id, $config->get());
     }
     // Ensure that dependencies are calculated on the display level.
     $expected_display['default'] = ['config' => ['core.entity_view_mode.node.teaser'], 'content' => ['ArgumentDefaultTest', 'ArgumentValidatorTest'], 'module' => ['core', 'node', 'search', 'user', 'views']];
     $expected_display['page'] = ['config' => ['field.storage.node.body'], 'module' => ['core', 'text', 'views']];
     $view = Views::getView('test_argument_dependency');
     $view->initDisplay();
     foreach ($view->displayHandlers as $display) {
         // Calculate the dependencies each display has.
         $this->assertEqual($expected_display[$display->getPluginId()], $display->calculateDependencies());
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:36,代码来源:ViewEntityDependenciesTest.php


示例3: setUp

 function setUp()
 {
     parent::setUp();
     // Add two new languages.
     ConfigurableLanguage::createFromLangcode('fr')->save();
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Set up term names.
     $this->termNames = array('en' => 'Food in Paris', 'es' => 'Comida en Paris', 'fr' => 'Nouriture en Paris');
     // Create a vocabulary.
     $this->vocabulary = Vocabulary::create(['name' => 'Views testing tags', 'vid' => 'views_testing_tags']);
     $this->vocabulary->save();
     // Add a translatable field to the vocabulary.
     $field = FieldStorageConfig::create(array('field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'type' => 'text'));
     $field->save();
     FieldConfig::create(['field_name' => 'field_foo', 'entity_type' => 'taxonomy_term', 'label' => 'Foo', 'bundle' => 'views_testing_tags'])->save();
     // Create term with translations.
     $taxonomy = $this->createTermWithProperties(array('name' => $this->termNames['en'], 'langcode' => 'en', 'description' => $this->termNames['en'], 'field_foo' => $this->termNames['en']));
     foreach (array('es', 'fr') as $langcode) {
         $translation = $taxonomy->addTranslation($langcode, array('name' => $this->termNames[$langcode]));
         $translation->description->value = $this->termNames[$langcode];
         $translation->field_foo->value = $this->termNames[$langcode];
     }
     $taxonomy->save();
     Views::viewsData()->clear();
     ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
     $this->container->get('router.builder')->rebuild();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:27,代码来源:TaxonomyFieldFilterTest.php


示例4: testHooks

 /**
  * Tests the hooks.
  */
 public function testHooks()
 {
     $view = Views::getView('test_view');
     $view->setDisplay();
     // Test each hook is found in the implementations array and is invoked.
     foreach (static::$hooks as $hook => $type) {
         $this->assertTrue($this->moduleHandler->implementsHook('views_test_data', $hook), format_string('The hook @hook was registered.', array('@hook' => $hook)));
         if ($hook == 'views_post_render') {
             $this->moduleHandler->invoke('views_test_data', $hook, array($view, &$view->display_handler->output, $view->display_handler->getPlugin('cache')));
             continue;
         }
         switch ($type) {
             case 'view':
                 $this->moduleHandler->invoke('views_test_data', $hook, array($view));
                 break;
             case 'alter':
                 $data = array();
                 $this->moduleHandler->invoke('views_test_data', $hook, array($data));
                 break;
             default:
                 $this->moduleHandler->invoke('views_test_data', $hook);
         }
         $this->assertTrue($this->container->get('state')->get('views_hook_test_' . $hook), format_string('The %hook hook was invoked.', array('%hook' => $hook)));
         // Reset the module implementations cache, so we ensure that the
         // .views.inc file is loaded actively.
         $this->moduleHandler->resetImplementations();
     }
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:31,代码来源:ViewsHooksTest.php


示例5: testIntegration

 /**
  * Tests the integration.
  */
 public function testIntegration()
 {
     // Remove the watchdog entries added by the potential batch process.
     $this->container->get('database')->truncate('watchdog')->execute();
     $entries = array();
     // Setup a watchdog entry without tokens.
     $entries[] = array('message' => $this->randomMachineName(), 'variables' => array(), 'link' => l('Link', 'node/1'));
     // Setup a watchdog entry with one token.
     $entries[] = array('message' => '@token1', 'variables' => array('@token1' => $this->randomMachineName()), 'link' => l('Link', 'node/2'));
     // Setup a watchdog entry with two tokens.
     $entries[] = array('message' => '@token1 !token2', 'variables' => array('@token1' => $this->randomMachineName(), '!token2' => $this->randomMachineName()), 'link' => l('<object>Link</object>', 'node/2', array('html' => TRUE)));
     foreach ($entries as $entry) {
         $entry += array('type' => 'test-views', 'severity' => WATCHDOG_NOTICE);
         watchdog($entry['type'], $entry['message'], $entry['variables'], $entry['severity'], $entry['link']);
     }
     $view = Views::getView('test_dblog');
     $this->executeView($view);
     $view->initStyle();
     foreach ($entries as $index => $entry) {
         $this->assertEqual($view->style_plugin->getField($index, 'message'), String::format($entry['message'], $entry['variables']));
         $this->assertEqual($view->style_plugin->getField($index, 'link'), Xss::filterAdmin($entry['link']));
     }
     // Disable replacing variables and check that the tokens aren't replaced.
     $view->destroy();
     $view->initHandlers();
     $this->executeView($view);
     $view->initStyle();
     $view->field['message']->options['replace_variables'] = FALSE;
     foreach ($entries as $index => $entry) {
         $this->assertEqual($view->style_plugin->getField($index, 'message'), $entry['message']);
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:35,代码来源:ViewsIntegrationTest.php


示例6: testSimple

 function testSimple()
 {
     $view = Views::getView('test_view');
     $view->setDisplay();
     $view->displayHandlers->get('default')->overrideOption('fields', array('counter' => array('id' => 'counter', 'table' => 'views', 'field' => 'counter', 'relationship' => 'none'), 'name' => array('id' => 'name', 'table' => 'views_test_data', 'field' => 'name', 'relationship' => 'none')));
     $view->preview();
     $counter = $view->style_plugin->getField(0, 'counter');
     $this->assertEqual($counter, '1', format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', array('@expected' => 1, '@counter' => $counter)));
     $counter = $view->style_plugin->getField(1, 'counter');
     $this->assertEqual($counter, '2', format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', array('@expected' => 2, '@counter' => $counter)));
     $counter = $view->style_plugin->getField(2, 'counter');
     $this->assertEqual($counter, '3', format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', array('@expected' => 3, '@counter' => $counter)));
     $view->destroy();
     $view->storage->invalidateCaches();
     $view->setDisplay();
     $rand_start = rand(5, 10);
     $view->displayHandlers->get('default')->overrideOption('fields', array('counter' => array('id' => 'counter', 'table' => 'views', 'field' => 'counter', 'relationship' => 'none', 'counter_start' => $rand_start), 'name' => array('id' => 'name', 'table' => 'views_test_data', 'field' => 'name', 'relationship' => 'none')));
     $view->preview();
     $counter = $view->style_plugin->getField(0, 'counter');
     $expected_number = 0 + $rand_start;
     $this->assertEqual($counter, (string) $expected_number, format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', array('@expected' => $expected_number, '@counter' => $counter)));
     $counter = $view->style_plugin->getField(1, 'counter');
     $expected_number = 1 + $rand_start;
     $this->assertEqual($counter, (string) $expected_number, format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', array('@expected' => $expected_number, '@counter' => $counter)));
     $counter = $view->style_plugin->getField(2, 'counter');
     $expected_number = 2 + $rand_start;
     $this->assertEqual($counter, (string) $expected_number, format_string('Make sure the expected number (@expected) patches with the rendered number (@counter)', array('@expected' => $expected_number, '@counter' => $counter)));
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:28,代码来源:FieldCounterTest.php


示例7: testUsername

 /**
  * Test the username formatter.
  */
 public function testUsername()
 {
     $view_id = $this->randomMachineName();
     $view = View::create(['id' => $view_id, 'base_table' => 'comment_field_data', 'display' => ['default' => ['display_plugin' => 'default', 'id' => 'default', 'display_options' => ['fields' => ['name' => ['table' => 'comment_field_data', 'field' => 'name', 'id' => 'name', 'plugin_id' => 'field', 'type' => 'comment_username'], 'subject' => ['table' => 'comment_field_data', 'field' => 'subject', 'id' => 'subject', 'plugin_id' => 'field', 'type' => 'string', 'settings' => ['link_to_entity' => TRUE]]]]]]]);
     $view->save();
     /* @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
     $account_switcher = \Drupal::service('account_switcher');
     /* @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $account_switcher->switchTo($this->adminUser);
     $executable = Views::getView($view_id);
     $build = $executable->preview();
     $this->setRawContent($renderer->renderRoot($build));
     $this->verbose($this->getRawContent());
     $this->assertLink('My comment title');
     $this->assertLink('Anonymous comment title');
     $this->assertLink($this->adminUser->label());
     $this->assertLink('barry (not verified)');
     $account_switcher->switchTo(new AnonymousUserSession());
     $executable = Views::getView($view_id);
     $executable->storage->invalidateCaches();
     $build = $executable->preview();
     $this->setRawContent($renderer->renderRoot($build));
     // No access to user-profiles, so shouldn't be able to see links.
     $this->assertNoLink($this->adminUser->label());
     // Note: External users aren't pointing to drupal user profiles.
     $this->assertLink('barry (not verified)');
     $this->verbose($this->getRawContent());
     $this->assertLink('My comment title');
     $this->assertLink('Anonymous comment title');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:34,代码来源:CommentUserNameTest.php


示例8: testCustomOption

 /**
  * Tests the setting and output of custom labels for boolean values.
  */
 public function testCustomOption()
 {
     // Add the boolean field handler to the test view.
     $view = Views::getView('test_view');
     $view->setDisplay();
     $view->displayHandlers->get('default')->overrideOption('fields', array('age' => array('id' => 'age', 'table' => 'views_test_data', 'field' => 'age', 'relationship' => 'none')));
     $this->executeView($view);
     $custom_true = 'Yay';
     $custom_false = 'Nay';
     // Set up some custom value mappings for different types.
     $custom_values = array('plain' => array('true' => $custom_true, 'false' => $custom_false, 'test' => 'assertTrue'), 'allowed tag' => array('true' => '<p>' . $custom_true . '</p>', 'false' => '<p>' . $custom_false . '</p>', 'test' => 'assertTrue'), 'disallowed tag' => array('true' => '<script>' . $custom_true . '</script>', 'false' => '<script>' . $custom_false . '</script>', 'test' => 'assertFalse'));
     // Run the same tests on each type.
     foreach ($custom_values as $type => $values) {
         $options = array('options[type]' => 'custom', 'options[type_custom_true]' => $values['true'], 'options[type_custom_false]' => $values['false']);
         $this->drupalPostForm('admin/structure/views/nojs/handler/test_view/default/field/age', $options, 'Apply');
         // Save the view.
         $this->drupalPostForm('admin/structure/views/view/test_view', array(), 'Save');
         $view = Views::getView('test_view');
         $output = $view->preview();
         $output = drupal_render($output);
         $replacements = array('%type' => $type);
         $this->{$values['test']}(strpos($output, $values['true']), format_string('Expected custom boolean TRUE value in output for %type.', $replacements));
         $this->{$values['test']}(strpos($output, $values['false']), format_string('Expected custom boolean FALSE value in output for %type', $replacements));
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:28,代码来源:CustomBooleanTest.php


示例9: testFilterEntity

 /**
  * Tests the generic bundle filter.
  */
 public function testFilterEntity()
 {
     $view = Views::getView('test_entity_type_filter');
     // Tests \Drupal\views\Plugin\views\filter\Bundle::calculateDependencies().
     $expected = ['config' => ['node.type.test_bundle', 'node.type.test_bundle_2'], 'module' => ['node']];
     $this->assertIdentical($expected, $view->getDependencies());
     $this->executeView($view);
     // Test we have all the results, with all types selected.
     $this->assertEqual(count($view->result), $this->entities['count']);
     // Test the valueOptions of the filter handler.
     $expected = array();
     foreach ($this->entityBundles as $key => $info) {
         $expected[$key] = $info['label'];
     }
     $this->assertIdentical($view->filter['type']->getValueOptions(), $expected);
     $view->destroy();
     // Test each bundle type.
     foreach ($this->entityBundles as $key => $info) {
         // Test each bundle type.
         $view->initDisplay();
         $filters = $view->display_handler->getOption('filters');
         $filters['type']['value'] = array($key => $key);
         $view->display_handler->setOption('filters', $filters);
         $this->executeView($view);
         $this->assertEqual(count($view->result), count($this->entities[$key]));
         $view->destroy();
     }
     // Test an invalid bundle type to make sure we have no results.
     $view->initDisplay();
     $filters = $view->display_handler->getOption('filters');
     $filters['type']['value'] = array('type_3' => 'type_3');
     $view->display_handler->setOption('filters', $filters);
     $this->executeView($view);
     $this->assertEqual(count($view->result), 0);
 }
开发者ID:318io,项目名称:318-io,代码行数:38,代码来源:FilterEntityBundleTest.php


示例10: testHandlers

 /**
  * Tests the handlers.
  */
 public function testHandlers()
 {
     $nodes = array();
     $nodes[] = $this->drupalCreateNode();
     $nodes[] = $this->drupalCreateNode();
     $account = $this->drupalCreateUser();
     $this->drupalLogin($account);
     \Drupal::currentUser()->setAccount($account);
     db_insert('history')->fields(array('uid' => $account->id(), 'nid' => $nodes[0]->id(), 'timestamp' => REQUEST_TIME - 100))->execute();
     db_insert('history')->fields(array('uid' => $account->id(), 'nid' => $nodes[1]->id(), 'timestamp' => REQUEST_TIME + 100))->execute();
     $column_map = array('nid' => 'nid');
     // Test the history field.
     $view = Views::getView('test_history');
     $view->setDisplay('page_1');
     $this->executeView($view);
     $this->assertEqual(count($view->result), 2);
     $output = $view->preview();
     $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
     $result = $this->xpath('//span[@class=:class]', array(':class' => 'marker'));
     $this->assertEqual(count($result), 1, 'Just one node is marked as new');
     // Test the history filter.
     $view = Views::getView('test_history');
     $view->setDisplay('page_2');
     $this->executeView($view);
     $this->assertEqual(count($view->result), 1);
     $this->assertIdenticalResultset($view, array(array('nid' => $nodes[0]->id())), $column_map);
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:30,代码来源:HistoryTimestampTest.php


示例11: testGlossary

 /**
  * Tests the glossary feature.
  */
 function testGlossary()
 {
     // Setup some nodes, one with a, two with b and three with c.
     $counter = 1;
     foreach (array('a', 'b', 'c') as $char) {
         for ($i = 0; $i < $counter; $i++) {
             $edit = array('title' => $char . $this->randomMachineName());
             $this->drupalCreateNode($edit);
         }
     }
     $view = Views::getView('test_glossary');
     $this->executeView($view);
     $count_field = 'nid';
     foreach ($view->result as &$row) {
         if (strpos($view->field['title']->getValue($row), 'a') === 0) {
             $this->assertEqual(1, $row->{$count_field});
         }
         if (strpos($view->field['title']->getValue($row), 'b') === 0) {
             $this->assertEqual(2, $row->{$count_field});
         }
         if (strpos($view->field['title']->getValue($row), 'c') === 0) {
             $this->assertEqual(3, $row->{$count_field});
         }
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:28,代码来源:ArgumentStringTest.php


示例12: testCommentFieldName

 /**
  * Test comment field name.
  */
 public function testCommentFieldName()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $view = Views::getView('test_comment_field_name');
     $this->executeView($view);
     $expected_result = [['cid' => $this->comment->id(), 'field_name' => $this->comment->getFieldName()], ['cid' => $this->customComment->id(), 'field_name' => $this->customComment->getFieldName()]];
     $column_map = ['cid' => 'cid', 'comment_field_data_field_name' => 'field_name'];
     $this->assertIdenticalResultset($view, $expected_result, $column_map);
     // Test that no data can be rendered.
     $this->assertIdentical(FALSE, isset($view->field['field_name']));
     // Grant permission to properly check view access on render.
     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']);
     $this->container->get('account_switcher')->switchTo(new AnonymousUserSession());
     $view = Views::getView('test_comment_field_name');
     $this->executeView($view);
     // Test that data rendered.
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($view) {
         return $view->field['field_name']->advancedRender($view->result[0]);
     });
     $this->assertIdentical($this->comment->getFieldName(), $output);
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($view) {
         return $view->field['field_name']->advancedRender($view->result[1]);
     });
     $this->assertIdentical($this->customComment->getFieldName(), $output);
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:29,代码来源:CommentFieldNameTest.php


示例13: testUserName

 public function testUserName()
 {
     $this->drupalLogin($this->drupalCreateUser(array('access user profiles')));
     $view = Views::getView('test_views_handler_field_user_name');
     $this->executeView($view);
     $view->field['name']->options['link_to_user'] = TRUE;
     $username = $view->result[0]->users_field_data_name = $this->randomMachineName();
     $view->result[0]->users_field_data_uid = 1;
     $render = $view->field['name']->advancedRender($view->result[0]);
     $this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
     $this->assertTrue(strpos($render, 'user/1') !== FALSE, 'If link to user is checked the link to the user should appear as well.');
     $view->field['name']->options['link_to_user'] = FALSE;
     $username = $view->result[0]->users_field_data_name = $this->randomMachineName();
     $view->result[0]->users_field_data_uid = 1;
     $render = $view->field['name']->advancedRender($view->result[0]);
     $this->assertIdentical($render, $username, 'If the user is not linked the username should be printed out for a normal user.');
     $view->result[0]->users_field_data_uid = 0;
     $anon_name = \Drupal::config('user.settings')->get('anonymous');
     $view->result[0]->users_field_data_name = '';
     $render = $view->field['name']->advancedRender($view->result[0]);
     $this->assertIdentical($render, $anon_name, 'For user0 it should use the default anonymous name by default.');
     $view->field['name']->options['overwrite_anonymous'] = TRUE;
     $anon_name = $view->field['name']->options['anonymous_text'] = $this->randomMachineName();
     $render = $view->field['name']->advancedRender($view->result[0]);
     $this->assertIdentical($render, $anon_name, 'For user0 it should use the configured anonymous text if overwrite_anonymous is checked.');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:26,代码来源:HandlerFieldUserNameTest.php


示例14: testCalculateDependencies

 /**
  * Tests the calculateDependencies method.
  */
 public function testCalculateDependencies()
 {
     $expected = [];
     $expected['test_field_get_entity'] = ['module' => ['comment', 'node', 'user']];
     // Tests dependencies of relationships.
     $expected['test_relationship_dependency'] = ['module' => ['comment', 'node', 'user']];
     $expected['test_plugin_dependencies'] = ['module' => ['comment', 'views_test_data'], 'content' => ['RowTest', 'StaticTest', 'StyleTest']];
     $expected['test_argument_dependency'] = ['config' => ['core.entity_view_mode.node.teaser', 'field.storage.node.body'], 'content' => ['ArgumentDefaultTest', 'ArgumentValidatorTest'], 'module' => ['node', 'search', 'text', 'user']];
     foreach ($this::$testViews as $view_id) {
         $view = Views::getView($view_id);
         $dependencies = $view->calculateDependencies();
         $this->assertEqual($expected[$view_id], $dependencies);
         $config = $this->config('views.view.' . $view_id);
         \Drupal::service('config.storage.staging')->write($view_id, $config->get());
     }
     // Ensure that dependencies are calculated on the display level.
     $expected_display['default'] = ['config' => ['core.entity_view_mode.node.teaser'], 'content' => ['ArgumentDefaultTest', 'ArgumentValidatorTest'], 'module' => ['core', 'node', 'search', 'user', 'views']];
     $expected_display['page'] = ['config' => ['field.storage.node.body'], 'module' => ['core', 'text', 'views']];
     $view = Views::getView('test_argument_dependency');
     $view->initDisplay();
     foreach ($view->displayHandlers as $display) {
         // Calculate the dependencies each display has.
         $this->assertEqual($expected_display[$display->getPluginId()], $display->calculateDependencies());
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:28,代码来源:ViewEntityDependenciesTest.php


示例15: testFileExtensionTarOption

 /**
  * Tests file extension views field handler extension_detect_tar option.
  */
 public function testFileExtensionTarOption()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $view = Views::getView('file_extension_view');
     $view->setDisplay();
     $this->executeView($view);
     // Test without the tar option.
     $renderer->executeInRenderContext(new RenderContext(), function () use($view) {
         $this->assertEqual($view->field['extension']->advancedRender($view->result[0]), 'png');
         $this->assertEqual($view->field['extension']->advancedRender($view->result[1]), 'tar');
         $this->assertEqual($view->field['extension']->advancedRender($view->result[2]), 'gz');
         $this->assertEqual($view->field['extension']->advancedRender($view->result[3]), '');
     });
     // Test with the tar option.
     $view = Views::getView('file_extension_view');
     $view->setDisplay();
     $view->initHandlers();
     $view->field['extension']->options['settings']['extension_detect_tar'] = TRUE;
     $this->executeView($view);
     $renderer->executeInRenderContext(new RenderContext(), function () use($view) {
         $this->assertEqual($view->field['extension']->advancedRender($view->result[0]), 'png');
         $this->assertEqual($view->field['extension']->advancedRender($view->result[1]), 'tar');
         $this->assertEqual($view->field['extension']->advancedRender($view->result[2]), 'tar.gz');
         $this->assertEqual($view->field['extension']->advancedRender($view->result[3]), '');
     });
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:30,代码来源:ExtensionViewsFieldTest.php


示例16: testForumIntegration

 /**
  * Tests the integration.
  */
 public function testForumIntegration()
 {
     // Create a forum.
     $entity_manager = $this->container->get('entity.manager');
     $term = $entity_manager->getStorage('taxonomy_term')->create(array('vid' => 'forums', 'name' => $this->randomName()));
     $term->save();
     $comment_storage = $entity_manager->getStorage('comment');
     // Create some nodes which are part of this forum with some comments.
     $nodes = array();
     for ($i = 0; $i < 3; $i++) {
         $node = $this->drupalCreateNode(array('type' => 'forum', 'taxonomy_forums' => array($term->id()), 'sticky' => $i == 0 ? NODE_STICKY : NODE_NOT_STICKY));
         $nodes[] = $node;
     }
     $account = $this->drupalCreateUser(array('skip comment approval'));
     $this->drupalLogin($account);
     $comments = array();
     foreach ($nodes as $index => $node) {
         for ($i = 0; $i <= $index; $i++) {
             $comment = $comment_storage->create(array('entity_type' => 'node', 'entity_id' => $node->id(), 'field_name' => 'comment_forum'));
             $comment->save();
             $comments[$comment->get('entity_id')->target_id][$comment->id()] = $comment;
         }
     }
     $view = Views::getView('test_forum_index');
     $this->executeView($view);
     $expected_result = array();
     $expected_result[] = array('nid' => $nodes[0]->id(), 'sticky' => NODE_STICKY, 'comment_count' => 1.0);
     $expected_result[] = array('nid' => $nodes[1]->id(), 'sticky' => NODE_NOT_STICKY, 'comment_count' => 2.0);
     $expected_result[] = array('nid' => $nodes[2]->id(), 'sticky' => NODE_NOT_STICKY, 'comment_count' => 3.0);
     $column_map = array('nid' => 'nid', 'forum_index_sticky' => 'sticky', 'forum_index_comment_count' => 'comment_count');
     $this->assertIdenticalResultset($view, $expected_result, $column_map);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:35,代码来源:ForumIntegrationTest.php


示例17: testIntegration

 /**
  * Tests the integration.
  */
 public function testIntegration()
 {
     // Remove the watchdog entries added by the potential batch process.
     $this->container->get('database')->truncate('watchdog')->execute();
     $entries = array();
     // Setup a watchdog entry without tokens.
     $entries[] = array('message' => $this->randomMachineName(), 'variables' => array('link' => \Drupal::l('Link', new Url('<front>'))));
     // Setup a watchdog entry with one token.
     $entries[] = array('message' => '@token1', 'variables' => array('@token1' => $this->randomMachineName(), 'link' => \Drupal::l('Link', new Url('<front>'))));
     // Setup a watchdog entry with two tokens.
     $entries[] = array('message' => '@token1 !token2', 'variables' => array('@token1' => $this->randomMachineName(), '!token2' => $this->randomMachineName(), 'link' => \Drupal::l(SafeMarkup::set('<object>Link</object>'), new Url('<front>'))));
     $logger_factory = $this->container->get('logger.factory');
     foreach ($entries as $entry) {
         $entry += array('type' => 'test-views', 'severity' => RfcLogLevel::NOTICE);
         $logger_factory->get($entry['type'])->log($entry['severity'], $entry['message'], $entry['variables']);
     }
     $view = Views::getView('test_dblog');
     $this->executeView($view);
     $view->initStyle();
     foreach ($entries as $index => $entry) {
         $this->assertEqual($view->style_plugin->getField($index, 'message'), SafeMarkup::format($entry['message'], $entry['variables']));
         $this->assertEqual($view->style_plugin->getField($index, 'link'), Xss::filterAdmin($entry['variables']['link']));
     }
     // Disable replacing variables and check that the tokens aren't replaced.
     $view->destroy();
     $view->storage->invalidateCaches();
     $view->initHandlers();
     $this->executeView($view);
     $view->initStyle();
     $view->field['message']->options['replace_variables'] = FALSE;
     foreach ($entries as $index => $entry) {
         $this->assertEqual($view->style_plugin->getField($index, 'message'), $entry['message']);
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:37,代码来源:ViewsIntegrationTest.php


示例18: testMediaRevisionWizard

 /**
  * Tests adding a view of media revisions.
  */
 public function testMediaRevisionWizard()
 {
     $view = [];
     $view['label'] = $this->randomMachineName(16);
     $view['id'] = strtolower($this->randomMachineName(16));
     $view['show[wizard_key]'] = 'media_revision';
     $view['page[create]'] = TRUE;
     $view['page[path]'] = $this->randomMachineName(16);
     // Just triggering the saving should automatically choose a proper row
     // plugin.
     $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
     $this->assertUrl('admin/structure/views/view/' . $view['id'], [], 'Make sure the view saving was successful and the browser got redirected to the edit page.');
     $user = $this->drupalCreateUser(['view all revisions']);
     $this->drupalLogin($user);
     $view = Views::getView($view['id']);
     $view->initHandlers();
     $row = $view->display_handler->getOption('row');
     $this->assertEqual($row['type'], 'fields');
     // Check for the default filters.
     $this->assertEqual($view->filter['status']->table, 'media_field_revision');
     $this->assertEqual($view->filter['status']->field, 'status');
     $this->assertTrue($view->filter['status']->value);
     // Check for the default fields.
     $this->assertEqual($view->field['name']->table, 'media_field_revision');
     $this->assertEqual($view->field['name']->field, 'name');
     $this->assertEqual($view->field['changed']->table, 'media_field_revision');
     $this->assertEqual($view->field['changed']->field, 'changed');
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:31,代码来源:WizardTest.php


示例19: testHandlers

 /**
  * Tests the handlers.
  */
 public function testHandlers()
 {
     $nodes = array();
     $nodes[] = $this->drupalCreateNode();
     $nodes[] = $this->drupalCreateNode();
     $account = $this->drupalCreateUser();
     $this->drupalLogin($account);
     \Drupal::currentUser()->setAccount($account);
     db_insert('history')->fields(array('uid' => $account->id(), 'nid' => $nodes[0]->id(), 'timestamp' => REQUEST_TIME - 100))->execute();
     db_insert('history')->fields(array('uid' => $account->id(), 'nid' => $nodes[1]->id(), 'timestamp' => REQUEST_TIME + 100))->execute();
     $column_map = array('nid' => 'nid');
     // Test the history field.
     $view = Views::getView('test_history');
     $view->setDisplay('page_1');
     $this->executeView($view);
     $this->assertEqual(count($view->result), 2);
     $output = $view->preview();
     $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
     $result = $this->xpath('//span[@class=:class]', array(':class' => 'marker'));
     $this->assertEqual(count($result), 1, 'Just one node is marked as new');
     // Test the history filter.
     $view = Views::getView('test_history');
     $view->setDisplay('page_2');
     $this->executeView($view);
     $this->assertEqual(count($view->result), 1);
     $this->assertIdenticalResultset($view, array(array('nid' => $nodes[0]->id())), $column_map);
     // Install Comment module and make sure that content types without comment
     // field will not break the view.
     // See \Drupal\history\Plugin\views\filter\HistoryUserTimestamp::query()
     \Drupal::service('module_installer')->install(['comment']);
     $view = Views::getView('test_history');
     $view->setDisplay('page_2');
     $this->executeView($view);
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:37,代码来源:HistoryTimestampTest.php


示例20: testAreaText


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP Entity\View类代码示例发布时间:2022-05-23
下一篇:
PHP views\ViewExecutable类代码示例发布时间: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