ViewListControllerTest.php 3.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
<?php

/**
 * @file
 * Contains \Drupal\views_ui\Tests\ViewListControllerTest
 */

namespace Drupal\views_ui\Tests {


use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\Core\Entity\View;
use Drupal\views_ui\ViewListController;

class ViewListControllerTest extends UnitTestCase {

  public static function getInfo() {
    return array(
      'name' => 'Views List Controller Unit Test',
      'description' => 'Unit tests the views list controller',
      'group' => 'Views UI',
    );
  }

  /**
   * Tests the listing of displays on a views list.
   *
   * @see \Drupal\views_ui\ViewListController::getDisplaysList().
   */
  public function testBuildRowEntityList() {
    $storage_controller = $this->getMockBuilder('Drupal\views\ViewStorageController')
      ->disableOriginalConstructor()
      ->getMock();
    $entity_info = array();
    $display_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
      ->disableOriginalConstructor()
      ->getMock();
    $display_manager->expects($this->any())
      ->method('getDefinition')
      ->will($this->returnValueMap(array(
        array(
          'default',
          array(
            'id' => 'default',
            'title' => 'Master',
            'theme' => 'views_view',
            'no_ui' => TRUE,
          )
        ),
        array(
          'page',
          array(
            'id' => 'page',
            'title' => 'Page',
            'uses_hook_menu' => TRUE,
            'uses_route' => TRUE,
            'contextual_links_locations' => array('page'),
            'theme' => 'views_view',
            'admin' => 'Page admin label',
          )
        ),
        array(
          'embed',
          array(
            'id' => 'embed',
            'title' => 'embed',
            'theme' => 'views_view',
            'admin' => 'Embed admin label',
          )
        ),
      )));
72 73 74
    $module_handler = $this->getMockBuilder('Drupal\Core\Extension\ModuleHandler')
      ->disableOriginalConstructor()
      ->getMock();
75 76 77

    // Setup a view list controller with a mocked buildOperations method,
    // because t() is called on there.
78
    $view_list_controller = $this->getMock('Drupal\views_ui\ViewListController', array('buildOperations'), array('view', $storage_controller, $entity_info, $display_manager, $module_handler));
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    $view_list_controller->expects($this->any())
      ->method('buildOperations')
      ->will($this->returnValue(array()));

    $values = array();
    $values['display']['default']['id'] = 'default';
    $values['display']['default']['display_title'] = 'Display';
    $values['display']['default']['display_plugin'] = 'default';

    $values['display']['page_1']['id'] = 'page_1';
    $values['display']['page_1']['display_title'] = 'Page 1';
    $values['display']['page_1']['display_plugin'] = 'page';

    $values['display']['embed']['id'] = 'embed';
    $values['display']['embed']['display_title'] = 'Embedded';
    $values['display']['embed']['display_plugin'] = 'embed';

    $view = new View($values, 'view');

    $row = $view_list_controller->buildRow($view);

    $this->assertEquals(array('Embed admin label', 'Page admin label'), $row['data']['view_name']['data']['#displays'], 'Wrong displays got added to view list');
  }
}

}

// @todo Remove this once t() is converted to a service.
namespace {
  if (!function_exists('t')) {
    function t($string) {
      return $string;
    }
  }
}