You are here

public function ViewUIObjectTest::testEntityDecoration in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php \Drupal\Tests\views_ui\Unit\ViewUIObjectTest::testEntityDecoration()
  2. 10 core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php \Drupal\Tests\views_ui\Unit\ViewUIObjectTest::testEntityDecoration()

Tests entity method decoration.

File

core/modules/views_ui/tests/src/Unit/ViewUIObjectTest.php, line 21

Class

ViewUIObjectTest
@coversDefaultClass \Drupal\views_ui\ViewUI @group views_ui

Namespace

Drupal\Tests\views_ui\Unit

Code

public function testEntityDecoration() {
  $method_args = [];
  $method_args['setOriginalId'] = [
    12,
  ];
  $method_args['setStatus'] = [
    TRUE,
  ];
  $method_args['enforceIsNew'] = [
    FALSE,
  ];
  $method_args['label'] = [
    LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ];
  $reflection = new \ReflectionClass('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface');
  $interface_methods = [];
  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.
    // EntityInterface::isSyncing() is only called during syncing process.
    // EntityInterface::isUninstalling() is only called during uninstallation
    // process. EntityInterface::getConfigDependencyName() and
    // ConfigEntityInterface::calculateDependencies() are only used for
    // dependency management.
    if (!in_array($reflection_method
      ->getName(), [
      'isNew',
      'isSyncing',
      'isUninstalling',
      'getConfigDependencyKey',
      'getConfigDependencyName',
      'calculateDependencies',
    ])) {
      if (count($reflection_method
        ->getParameters()) == 0) {
        $method_args[$reflection_method
          ->getName()] = [];
      }
    }
  }
  $storage = $this
    ->getMockBuilder('Drupal\\views\\Entity\\View')
    ->setMethods($interface_methods)
    ->setConstructorArgs([
    [],
    'view',
  ])
    ->getMock();
  $executable = $this
    ->getMockBuilder('Drupal\\views\\ViewExecutable')
    ->disableOriginalConstructor()
    ->setConstructorArgs([
    $storage,
  ])
    ->getMock();
  $storage
    ->set('executable', $executable);
  $view_ui = new ViewUI($storage);
  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([
      $view_ui,
      $method,
    ], $args);
  }
  $storage
    ->expects($this
    ->once())
    ->method('isNew');
  $view_ui
    ->isNew();
}