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

Commit 54000cb1 authored by Peter Wolanin's avatar Peter Wolanin
Browse files

Start adding a data provider to test case

parent 08586066
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -297,7 +297,7 @@ class Link extends TokenizeAreaPluginBase {
      // If we have no $path and no $url_info['url'], we have nothing to work
      // with, so we just return the text.
      if (empty($path)) {
        return $text;
        return $this->options['link_text'];
      }

      // If no scheme is provided in the $path, assign the default 'http://'.
@@ -476,7 +476,10 @@ class Link extends TokenizeAreaPluginBase {
  }

  /**
   * Takes the generated link ant transforms it into a 'local action' link.
   * Takes the generated link and transforms it into a 'local action' link.
   *
   * Wrapping with hard-coded HTML is ugly but basically copied from
   * \Drupal\block\Controller\BlockLibraryController::buildLocalActions()
   *
   * @param array $link
   *   The link to transform.
+56 −9
Original line number Diff line number Diff line
@@ -3,11 +3,9 @@

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.
@@ -17,6 +15,8 @@ use Symfony\Component\HttpFoundation\Request;
 */
class LinkAreaTest extends ViewsKernelTestBase {

  protected $entityId;

  /**
   * Modules to enable.
   *
@@ -39,6 +39,15 @@ class LinkAreaTest extends ViewsKernelTestBase {
    if ($import_test_views) {
      ViewTestData::createTestViews(get_class($this), ['views_test_linkarea']);
    }
    $random_label = $this->randomMachineName();
    $data = array('bundle' => 'entity_test', 'name' => $random_label);
    $entity_test = $this->container->get('entity.manager')
      ->getStorage('entity_test')
      ->create($data);
    $entity_test->save();
    $this->entityId = $entity_test->id();
    \Drupal::state()
      ->set('entity_test_entity_access.view.' . $entity_test->id(), TRUE);
  }

  /**
@@ -54,20 +63,58 @@ class LinkAreaTest extends ViewsKernelTestBase {

  /**
   * Tests the area handler.
   *
   *  @param $options
   * @param $expected_text
   * @param $expected_link
   * @param bool $no_dest
   *
   * @dataProvider providerTestLinkArea
   */
  public function testLinkArea() {
  public function testLinkArea($options, $expected_text, $expected_link, $no_dest = TRUE) {
    if ($no_dest) {
      // Set destination query string to off.
      $options['destination'] = 0;
    }
    $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']);
    $this->assertEquals($expected_text, $build['#title']);
    $this->assertEquals($expected_link, $build['#url']->toString());
  }

  /**
   * @return array
   */
  public function providerTestLinkArea() {
    $data = [];
    $data[] = [
      [
        'path' => '<front>',
        'link_text' => 'SSSSSS',
      ],
      'SSSSSS',
      '/'
    ];
    $data[] = [
      [
        'path' => 'route:user.pass',
        'link_text' => '<b>Pass</b>',
      ],
      'Pass',
      '/user/password'
    ];
    $data[] = [
      [
        'path' => 'entity:entity_test/1',
        'link_text' => '<b>Pass</b>',
      ],
      'Pass',
      '/entity_test/1'
    ];
    return $data;
  }
}