Version 1
[yaffs-website] / web / core / modules / system / tests / modules / js_webassert_test / src / Form / JsWebAssertTestForm.php
1 <?php
2
3 namespace Drupal\js_webassert_test\Form;
4
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\Core\Url;
8
9 /**
10  * Test form for JSWebAssert JavaScriptTestBase.
11  */
12 class JsWebAssertTestForm extends FormBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getFormId() {
18     return 'js_webassert_test_form';
19   }
20
21   /**
22    * Form for testing the addition of various types of elements via AJAX.
23    */
24   public function buildForm(array $form, FormStateInterface $form_state) {
25     $form['#prefix'] = '<div id="js_webassert_test_form_wrapper">';
26     $form['#suffix'] = '</div>';
27
28     // Button to test for the waitForButton() assertion.
29     $form['test_button'] = [
30       '#type' => 'submit',
31       '#value' => $this->t('Add button'),
32       '#button_type' => 'primary',
33       '#ajax' => [
34         'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addButton',
35         'progress' => [
36           'type' => 'throbber',
37           'message' => NULL,
38         ],
39         'wrapper' => 'js_webassert_test_form_wrapper',
40       ],
41     ];
42     // Button to test for the waitForLink() assertion.
43     $form['test_link'] = [
44       '#type' => 'submit',
45       '#value' => $this->t('Add link'),
46       '#button_type' => 'primary',
47       '#ajax' => [
48         'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addLink',
49         'progress' => [
50           'type' => 'throbber',
51           'message' => NULL,
52         ],
53         'wrapper' => 'js_webassert_test_form_wrapper',
54       ],
55     ];
56     // Button to test for the waitForField() assertion.
57     $form['test_field'] = [
58       '#type' => 'submit',
59       '#value' => $this->t('Add field'),
60       '#button_type' => 'primary',
61       '#ajax' => [
62         'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addField',
63         'progress' => [
64           'type' => 'throbber',
65           'message' => NULL,
66         ],
67         'wrapper' => 'js_webassert_test_form_wrapper',
68       ],
69     ];
70     // Button to test for the waitForId() assertion.
71     $form['test_id'] = [
72       '#type' => 'submit',
73       '#value' => $this->t('Add ID'),
74       '#button_type' => 'primary',
75       '#ajax' => [
76         'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addId',
77         'progress' => [
78           'type' => 'throbber',
79           'message' => NULL,
80         ],
81         'wrapper' => 'js_webassert_test_form_wrapper',
82       ],
83     ];
84
85     // Button to test the assertWaitOnAjaxRequest() assertion.
86     $form['test_wait_for_element_visible'] = [
87       '#type' => 'submit',
88       '#value' => $this->t('Test waitForElementVisible'),
89       '#button_type' => 'primary',
90       '#ajax' => [
91         'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addWaitForElementVisible',
92         'progress' => [
93           'type' => 'throbber',
94           'message' => NULL,
95         ],
96         'wrapper' => 'js_webassert_test_form_wrapper',
97       ],
98     ];
99
100     // Button to test the assertWaitOnAjaxRequest() assertion.
101     $form['test_assert_wait_on_ajax_request'] = [
102       '#type' => 'submit',
103       '#value' => $this->t('Test assertWaitOnAjaxRequest'),
104       '#button_type' => 'primary',
105       '#ajax' => [
106         'callback' => 'Drupal\js_webassert_test\Form\JsWebAssertTestForm::addAssertWaitOnAjaxRequest',
107         'progress' => [
108           'type' => 'throbber',
109           'message' => NULL,
110         ],
111         'wrapper' => 'js_webassert_test_form_wrapper',
112       ],
113     ];
114     return $form;
115   }
116
117   /**
118    * Ajax callback for the "Add button" button.
119    */
120   public static function addButton(array $form, FormStateInterface $form_state) {
121     $form['added_button'] = [
122       '#type' => 'submit',
123       '#value' => 'Added button',
124       '#button_type' => 'primary',
125     ];
126     return $form;
127   }
128
129   /**
130    * Ajax callback for the "Add link" button.
131    */
132   public static function addLink(array $form, FormStateInterface $form_state) {
133     $form['added_link'] = [
134       '#title' => 'Added link',
135       '#type' => 'link',
136       '#url' => Url::fromRoute('js_webassert_test.js_webassert_test_form')
137     ];
138     return $form;
139   }
140   /**
141    * Ajax callback for the "Add field" button.
142    */
143   public static function addField(array $form, FormStateInterface $form_state) {
144     $form['added_field'] = [
145       '#type' => 'textfield',
146       '#title' => 'Added textfield',
147       '#name' => 'added_field',
148     ];
149     return $form;
150   }
151
152   /**
153    * Ajax callback for the "Add ID" button.
154    */
155   public static function addId(array $form, FormStateInterface $form_state) {
156     $form['added_id'] = [
157       '#id' => 'js_webassert_test_field_id',
158       '#type' => 'submit',
159       '#value' => 'Added ID',
160       '#button_type' => 'primary',
161     ];
162     return $form;
163   }
164
165   /**
166    * Ajax callback for the "Test waitForAjax" button.
167    */
168   public static function addAssertWaitOnAjaxRequest(array $form, FormStateInterface $form_state) {
169     // Attach the library necessary for this test.
170     $form['#attached']['library'][] = 'js_webassert_test/wait_for_ajax_request';
171
172     $form['test_assert_wait_on_ajax_input'] = [
173       '#type' => 'textfield',
174       '#name' => 'test_assert_wait_on_ajax_input',
175     ];
176
177     return $form;
178   }
179
180
181   /**
182    * Ajax callback for the "Test waitForElementVisible" button.
183    */
184   public static function addWaitForElementVisible(array $form, FormStateInterface $form_state) {
185     // Attach the library necessary for this test.
186     $form['#attached']['library'][] = 'js_webassert_test/wait_for_element';
187
188     $form['element_invisible'] = [
189       '#id' => 'js_webassert_test_element_invisible',
190       '#type' => 'submit',
191       '#value' => 'Added WaitForElementVisible',
192       '#button_type' => 'primary',
193       '#attributes' => [
194         'style' => ['display: none;'],
195       ],
196     ];
197     return $form;
198   }
199
200   /**
201    * {@inheritdoc}
202    */
203   public function submitForm(array &$form, FormStateInterface $form_state) {
204
205   }
206
207 }