Thanks to visit codestin.com
Credit goes to git.drupalcode.org

Commit 08586066 authored by Peter Wolanin's avatar Peter Wolanin
Browse files

Start on kernel test, add plugin config schema, and fix notices

parent b0e5b186
Loading
Loading
Loading
Loading
+58 −0
Original line number Diff line number Diff line
views.area.linkarea:
  type: views_area
  label: 'Link Area'
  mapping:
    tokenize:
      type: boolean
      label: 'Should replacement tokens be used from the first row'
    link_text:
      type: string
      label: 'The link text'
    path:
      type: string
      label: 'Link path'
    output_as_action:
      type: boolean
      label: 'Output as action'
    destination:
      type: boolean
      label: 'Include destination'
    external:
      type: boolean
      label: 'External'
    replace_spaces:
      type: boolean
      label: 'Replace spaces'
    absolute:
      type: boolean
      label: 'Use absolute path'
    path_case:
      type: string
      label: 'Transform the case'
    alt:
      type: label
      label: 'Title text'
    rel:
      type: string
      label: 'Rel Text'
    link_class:
      type: string
      label: 'Link class'
    prefix:
      type: label
      label: 'Prefix text'
    suffix:
      type: label
      label: 'Suffix text'
    target:
      type: string
      label: 'Target'
    rewrite_output:
      type: string
      label: 'Target'
    access_denied_text:
      type: string
      label: 'Target'
    language:
      type: string
      label: 'Target'
+7 −8
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ class Link extends TokenizeAreaPluginBase {
      '#type' => 'textarea',
      '#title' => $this->t('Rewrite output'),
      '#default_value' => $this->options['rewrite_output'],
      '#description' => $this->t('Use this to output whatever HTML you want with the link created usable via the token {{views_area_link}}. Global tokens available as well.'),
      '#description' => $this->t('Use this to output whatever HTML you want with the link created usable via the token {{views_linkarea}}. Global tokens available as well.'),
    ];
    $form['access_denied_text'] = [
      '#fieldset' => 'advanced_opts',
@@ -263,7 +263,6 @@ class Link extends TokenizeAreaPluginBase {
      return [];
    }

    $text = $this->options['base_info']['link_text'];
    $options = array(
      'absolute' => !empty($this->options['absolute']) ? TRUE : FALSE,
      'alias' => FALSE,
@@ -336,13 +335,13 @@ class Link extends TokenizeAreaPluginBase {

    // Seriously malformed URLs may return FALSE or empty arrays.
    if (empty($url_parts)) {
      return $text;
      return $this->options['link_text'];
    }

    // If the path is empty do not build a link around the given text and return
    // it as is.
    if (empty($url_parts['path']) && empty($url_parts['fragment']) && empty($url_parts['url'])) {
      return $text;
      return $this->options['link_text'];
    }

    // If we get to here we have a path from the url parsing. So assign that to
@@ -376,13 +375,13 @@ class Link extends TokenizeAreaPluginBase {
      $options['fragment'] = $url_parts['fragment'];
    }

    $alt = $this->tokenizeValue($url_info['alt']);
    $alt = $this->tokenizeValue($this->options['alt']);
    // Set the title attribute of the link only if it improves accessibility.
    if ($alt && $alt != $text) {
    if ($alt && $alt != $this->options['link_text']) {
      $options['attributes']['title'] = Html::decodeEntities($alt);
    }

    $class = $this->tokenizeValue($url_info['link_class']);
    $class = $this->tokenizeValue($this->options['link_class']);
    if ($class) {
      $options['attributes']['class'] = [$class];
    }
@@ -450,7 +449,7 @@ class Link extends TokenizeAreaPluginBase {
    if ($this->options['rewrite_output'] !== '') {
      $rewritten_output = $this->viewsTokenReplace(
        $this->options['rewrite_output'],
        ['views_area_link' => $link]
        ['views_linkarea' => $link]
      );
      return [
        '#markup' => $this->sanitizeValue($this->tokenizeValue($rewritten_output), 'xss_admin'),
+63 −0
Original line number Diff line number Diff line
langcode: en
status: true
dependencies: {}
id: test_entity_linkarea
label: 'Test Entity LinkArea'
module: views
description: ''
tag: ''
base_table: views_test_data
base_field: id
core: '8'
display:
  default:
    display_options:
      defaults:
        fields: false
        pager: false
        sorts: false
      header:
        linkarea:
          id: linkarea
          table: views
          field: linkarea
          relationship: none
          group_type: group
          admin_label: ''
          empty: false
          tokenize: 0
          link_text: 'Test link text'
          path: '<front>'
          output_as_action: 0
          destination: 1
          prefix: ''
          suffix: ''
          external: 0
          replace_spaces: 0
          path_case: none
          alt: ''
          rel: ''
          link_class: ''
          target: ''
          absolute: 0
          rewrite_output: ''
          access_denied_text: ''
          language: '**auto**'
          plugin_id: linkarea
      footer: {}
      fields:
        id:
          field: id
          id: id
          relationship: none
          table: views_test_data
          plugin_id: numeric
      arguments: {}
      pager:
        options:
          offset: 0
        type: none
    display_plugin: default
    display_title: Master
    id: default
    position: 0
+8 −0
Original line number Diff line number Diff line
name: 'Views Test Link Area'
type: module
description: 'Provides default views for tests.'
package: Testing
version: 8.x-1.x
core: 8.x
dependencies:
  - views
+73 −0
Original line number Diff line number Diff line
<?php


namespace Drupal\Tests\views_linkarea\Kernel\Plugin;

use Drupal\views\Entity\View;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Symfony\Component\HttpFoundation\Request;

/**
 * Tests the page display plugin.
 *
 * @group views
 * @see \Drupal\views_linkarea\Plugin\views\area\Link
 */
class LinkAreaTest extends ViewsKernelTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = ['entity_test', 'user', 'views_linkarea', 'views_test_linkarea'];

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = array('test_entity_linkarea');

  /**
   * {@inheritdoc}
   */
  protected function setUp($import_test_views = TRUE) {
    parent::setUp();
    if ($import_test_views) {
      ViewTestData::createTestViews(get_class($this), ['views_test_linkarea']);
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function setUpFixtures() {
    $this->installEntitySchema('user');
    $this->installEntitySchema('entity_test');
    $this->installConfig(['entity_test']);

    parent::setUpFixtures();
  }

  /**
   * Tests the area handler.
   */
  public function testLinkArea() {
    $view = Views::getView('test_entity_linkarea');
    $display =  $view->getDisplay();
    $plugin = Views::pluginManager('area')->createInstance('linkarea');

    $options = [
      'path' => '<front>',
      'link_text' => 'SSSSSS',
    ];
    // Initialize the plugin.
    $plugin->init($view, $display, $options);
    $build = $plugin->render();
    $this->assertEquals($options['link_text'], $build['#title']);
  }

}