class ViewUIObjectTest

Tests the ViewUI class.

Hierarchy

Expanded class hierarchy of ViewUIObjectTest

See also

\Drupal\views_ui\ViewUI

File

drupal/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewUIObjectTest.php, line 25
Contains \Drupal\views_ui\Tests\ViewUIObjectTest.

Namespace

Drupal\views_ui\Tests
View source
class ViewUIObjectTest extends UnitTestCase {
  public static function getInfo() {
    return array(
      'name' => 'View UI Object',
      'description' => 'Test the ViewUI class.',
      'group' => 'Views UI',
    );
  }

  /**
   * Tests entity method decoration.
   */
  public function testEntityDecoration() {
    $method_args = array();
    $method_args['setOriginalID'] = array(
      12,
    );
    $method_args['setStatus'] = array(
      TRUE,
    );
    $method_args['setNewRevision'] = array(
      FALSE,
    );
    $method_args['enforceIsNew'] = array(
      FALSE,
    );
    $method_args['label'] = array(
      Language::LANGCODE_NOT_SPECIFIED,
    );
    $method_args['isDefaultRevision'] = array(
      TRUE,
    );
    $reflection = new \ReflectionClass('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
    $interface_methods = array();
    foreach ($reflection
      ->getMethods() as $reflection_method) {
      $interface_methods[] = $reflection_method
        ->getName();

      // EntityInterface::isNew() is missing from the list of methods, because it
      // calls id(), which breaks the ->expect($this->once()) call. Call it later.
      if ($reflection_method
        ->getName() != 'isNew') {
        if (count($reflection_method
          ->getParameters()) == 0) {
          $method_args[$reflection_method
            ->getName()] = array();
        }
      }
    }
    $storage = $this
      ->getMock('Drupal\\views\\Plugin\\Core\\Entity\\View', $interface_methods, array(
      array(),
      'view',
    ));
    $executable = $this
      ->getMockBuilder('Drupal\\views\\ViewExecutable')
      ->disableOriginalConstructor()
      ->setConstructorArgs(array(
      $storage,
    ))
      ->getMock();
    $view_ui = new ViewUI($storage, $executable);
    foreach ($method_args as $method => $args) {
      $method_mock = $storage
        ->expects($this
        ->once())
        ->method($method);
      foreach ($args as $arg) {
        $method_mock
          ->with($this
          ->equalTo($arg));
      }
      call_user_func_array(array(
        $view_ui,
        $method,
      ), $args);
    }
    $storage
      ->expects($this
      ->once())
      ->method('isNew');
    $view_ui
      ->isNew();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::randomName public static function Generates a random string containing letters and numbers.
ViewUIObjectTest::getInfo public static function This method exists to support the simpletest UI runner. Overrides UnitTestCase::getInfo
ViewUIObjectTest::testEntityDecoration public function Tests entity method decoration.