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