annotate core/modules/link/src/Tests/Views/LinkViewsTokensTest.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents 4c8ae668cc8c
children 1fec387a4317
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\link\Tests\Views;
Chris@0 4
Chris@0 5 use Drupal\field\Entity\FieldConfig;
Chris@0 6 use Drupal\field\Entity\FieldStorageConfig;
Chris@0 7 use Drupal\views\Tests\ViewTestBase;
Chris@0 8 use Drupal\views\Tests\ViewTestData;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Tests the views integration for link tokens.
Chris@0 12 *
Chris@0 13 * @group link
Chris@0 14 */
Chris@0 15 class LinkViewsTokensTest extends ViewTestBase {
Chris@0 16
Chris@0 17 /**
Chris@0 18 * Modules to enable.
Chris@0 19 *
Chris@0 20 * @var array
Chris@0 21 */
Chris@0 22 public static $modules = ['link_test_views'];
Chris@0 23
Chris@0 24 /**
Chris@0 25 * Views used by this test.
Chris@0 26 *
Chris@0 27 * @var array
Chris@0 28 */
Chris@0 29 public static $testViews = ['test_link_tokens'];
Chris@0 30
Chris@0 31 /**
Chris@0 32 * The field name used for the link field.
Chris@0 33 *
Chris@0 34 * @var string
Chris@0 35 */
Chris@0 36 protected $fieldName = 'field_link';
Chris@0 37
Chris@0 38 /**
Chris@0 39 * {@inheritdoc}
Chris@0 40 */
Chris@0 41 protected function setUp() {
Chris@0 42 parent::setUp();
Chris@0 43 ViewTestData::createTestViews(get_class($this), ['link_test_views']);
Chris@0 44
Chris@0 45 // Create Basic page node type.
Chris@0 46 $this->drupalCreateContentType([
Chris@0 47 'type' => 'page',
Chris@0 48 'name' => 'Basic page'
Chris@0 49 ]);
Chris@0 50
Chris@0 51 // Create a field.
Chris@0 52 FieldStorageConfig::create([
Chris@0 53 'field_name' => $this->fieldName,
Chris@0 54 'type' => 'link',
Chris@0 55 'entity_type' => 'node',
Chris@0 56 'cardinality' => 1,
Chris@0 57 ])->save();
Chris@0 58 FieldConfig::create([
Chris@0 59 'field_name' => $this->fieldName,
Chris@0 60 'entity_type' => 'node',
Chris@0 61 'bundle' => 'page',
Chris@0 62 'label' => 'link field',
Chris@0 63 ])->save();
Chris@0 64
Chris@0 65 }
Chris@0 66
Chris@0 67 public function testLinkViewsTokens() {
Chris@0 68 // Array of URI's to test.
Chris@0 69 $uris = [
Chris@0 70 'http://www.drupal.org' => 'Drupal.org',
Chris@0 71 ];
Chris@0 72
Chris@0 73 // Add nodes with the URI's and titles.
Chris@0 74 foreach ($uris as $uri => $title) {
Chris@0 75 $values = ['type' => 'page'];
Chris@0 76 $values[$this->fieldName][] = ['uri' => $uri, 'title' => $title, 'options' => ['attributes' => ['class' => 'test-link-class']]];
Chris@0 77 $this->drupalCreateNode($values);
Chris@0 78 }
Chris@0 79
Chris@0 80 $this->drupalGet('test_link_tokens');
Chris@0 81
Chris@0 82 foreach ($uris as $uri => $title) {
Chris@0 83 // Formatted link: {{ field_link }}<br />
Chris@0 84 $this->assertRaw("Formated: <a href=\"$uri\" class=\"test-link-class\">$title</a>");
Chris@0 85
Chris@0 86 // Raw uri: {{ field_link__uri }}<br />
Chris@0 87 $this->assertRaw("Raw uri: $uri");
Chris@0 88
Chris@0 89 // Raw title: {{ field_link__title }}<br />
Chris@0 90 $this->assertRaw("Raw title: $title");
Chris@0 91
Chris@0 92 // Raw options: {{ field_link__options }}<br />
Chris@0 93 // Options is an array and should return empty after token replace.
Chris@0 94 $this->assertRaw("Raw options: .");
Chris@0 95 }
Chris@0 96 }
Chris@0 97
Chris@0 98 }