class AjaxExampleMenuTest

Same name in other branches
  1. 3.x modules/ajax_example/tests/src/Functional/AjaxExampleMenuTest.php \Drupal\Tests\ajax_example\Functional\AjaxExampleMenuTest
  2. 4.0.x modules/ajax_example/tests/src/Functional/AjaxExampleMenuTest.php \Drupal\Tests\ajax_example\Functional\AjaxExampleMenuTest

Verify tool block menu items and operability of all our routes.

@group ajax_example @group examples

Hierarchy

  • class \Drupal\Tests\ajax_example\Functional\AjaxExampleMenuTest extends \Drupal\Tests\BrowserTestBase

Expanded class hierarchy of AjaxExampleMenuTest

Related topics

File

ajax_example/tests/src/Functional/AjaxExampleMenuTest.php, line 16

Namespace

Drupal\Tests\ajax_example\Functional
View source
class AjaxExampleMenuTest extends BrowserTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * {@inheritdoc}
     */
    public static $modules = [
        'ajax_example',
    ];
    
    /**
     * The installation profile to use with this test.
     *
     * @var string
     */
    protected $profile = 'minimal';
    
    /**
     * Tests links.
     */
    public function testAjaxExampleLinks() {
        // Login a user that can access content.
        $this->drupalLogin($this->createUser([
            'access content',
            'access user profiles',
        ]));
        $assertion = $this->assertSession();
        // Routes with menu links, and their form buttons.
        $routes_with_menu_links = [
            'ajax_example.description' => [],
            'ajax_example.simplest' => [],
            'ajax_example.autotextfields' => [
                'Click Me',
            ],
            'ajax_example.submit_driven_ajax' => [
                'Submit',
            ],
            'ajax_example.dependent_dropdown' => [
                'Submit',
            ],
            'ajax_example.dynamic_form_sections' => [
                'Choose',
            ],
            'ajax_example.wizard' => [
                'Next step',
            ],
            'ajax_example.wizardnojs' => [
                'Next step',
            ],
            'ajax_example.ajax_link_render' => [],
            'ajax_example.autocomplete_user' => [
                'Submit',
            ],
        ];
        // Ensure the links appear in the tools menu sidebar.
        $this->drupalGet('');
        foreach (array_keys($routes_with_menu_links) as $route) {
            $assertion->linkByHrefExists(Url::fromRoute($route)->getInternalPath());
        }
        // All our routes with their form buttons.
        $routes = [
            'ajax_example.ajax_link_callback' => [],
        ];
        // Go to all the routes and click all the buttons.
        $routes = array_merge($routes_with_menu_links, $routes);
        foreach ($routes as $route => $buttons) {
            $url = Url::fromRoute($route);
            if ($route === 'ajax_example.ajax_link_callback') {
                $url = Url::fromRoute($route, [
                    'nojs' => 'nojs',
                ]);
            }
            $this->drupalGet($url);
            $assertion->statusCodeEquals(200);
            foreach ($buttons as $button) {
                $this->drupalPostForm($url, [], $button);
                $assertion->statusCodeEquals(200);
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
AjaxExampleMenuTest::$defaultTheme protected property
AjaxExampleMenuTest::$modules public static property
AjaxExampleMenuTest::$profile protected property The installation profile to use with this test.
AjaxExampleMenuTest::testAjaxExampleLinks public function Tests links.