Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Render / Element / TableSelectTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Render\Element;
4
5 use Drupal\Core\Form\FormState;
6 use Drupal\Core\Link;
7 use Drupal\Core\Render\Element\Tableselect;
8 use Drupal\Core\StringTranslation\TranslatableMarkup;
9 use Drupal\Core\Url;
10 use Drupal\Tests\UnitTestCase;
11
12 /**
13  * @coversDefaultClass \Drupal\Core\Render\Element\Tableselect
14  * @group Render
15  */
16 class TableSelectTest extends UnitTestCase {
17
18   /**
19    * @covers ::processTableselect
20    */
21   public function testProcessTableselectWithLinkTitle() {
22     $element = [];
23     $form_state = new FormState();
24     $complete_form = [];
25
26     $element_object = new Tableselect([], 'table_select', []);
27     $info = $element_object->getInfo();
28     $element += $info;
29
30     $element['#value'] = 0;
31
32     $element['#options'][] = [
33       'title' => new Link('my-text', Url::fromRoute('<front>')),
34     ];
35
36     $element['#attributes'] = [];
37
38     Tableselect::processTableselect($element, $form_state, $complete_form);
39
40     $this->assertEquals('', $element[0]['#title']);
41   }
42
43   /**
44    * @covers ::processTableselect
45    */
46   public function testProcessTableselectWithStringTitle() {
47     $element = [];
48     $form_state = new FormState();
49     $complete_form = [];
50
51     $element_object = new Tableselect([], 'table_select', []);
52     $info = $element_object->getInfo();
53     $element += $info;
54
55     $element['#value'] = 0;
56
57     $element['#options'][] = [
58       'title' => ['data' => ['#title' => 'Static title']],
59     ];
60
61     $element['#attributes'] = [];
62
63     Tableselect::processTableselect($element, $form_state, $complete_form);
64
65     $this->assertEquals(new TranslatableMarkup('Update @title', ['@title' => 'Static title']), $element[0]['#title']);
66   }
67
68 }