function ViewsUIWizardJumpMenuTestCase::testJumpMenus

Tests the jump menu style plugin.

File

tests/views_ui.test, line 708

Class

ViewsUIWizardJumpMenuTestCase
Tests the ability of the wizard to create views with a jump menu style.

Code

public function testJumpMenus() {
    // We'll run this test for several different base tables that appear in the
    // wizard.
    $base_table_methods = array(
        'node' => 'createNodeAndGetPath',
        'users' => 'createUserAndGetPath',
        'comment' => 'createCommentAndGetPath',
        'taxonomy_term' => 'createTaxonomyTermAndGetPath',
        'file_managed' => 'createFileAndGetPath',
        'node_revision' => 'createNodeRevisionAndGetPath',
    );
    foreach ($base_table_methods as $base_table => $method) {
        // For each base table, find the path that we expect the jump menu to
        // redirect us to.
        $path_info = $this->{$method}();
        if (is_array($path_info)) {
            $path = $path_info['path'];
            $options = isset($path_info['options']) ? $path_info['options'] : array();
        }
        else {
            $path = $path_info;
            $options = array();
        }
        // Create a page view for the specified base table that uses the jump
        // menu style plugin.
        $view = array();
        $view['human_name'] = $this->randomName(16);
        $view['name'] = strtolower($this->randomName(16));
        $view['description'] = $this->randomName(16);
        $view['show[wizard_key]'] = $base_table;
        $view['page[create]'] = 1;
        $view['page[title]'] = $this->randomName(16);
        $view['page[path]'] = $this->randomName(16);
        $view['page[style][style_plugin]'] = 'jump_menu';
        $view['page[style][row_plugin]'] = 'fields';
        $this->drupalPost('admin/structure/views/add', $view, t('Save & exit'));
        // Submit the jump menu form, and check that we are redirected to the
        // expected URL.
        $edit = array();
        $edit['jump'] = url($path, $options);
        // The urls are built with :: to be able to have a unique path all the time,
        // so try to find out the real path of $edit.
        $view_object = views_get_view($view['name']);
        $view_object->preview('page');
        $form = $view_object->style_plugin
            ->render();
        $jump_options = $form['jump']['#options'];
        foreach ($jump_options as $key => $title) {
            if (strpos($key, $edit['jump']) !== FALSE) {
                $edit['jump'] = $key;
            }
        }
        $this->drupalPost($view['page[path]'], $edit, t('Go'));
        $this->assertResponse(200);
        $this->assertUrl($path, $options);
    }
}