assertSameSize example

'status' => [],
      'warning' => [],
      'error' => [],
    ];
    $actual_messages = $this->migrateMessages + [
      'status' => [],
      'warning' => [],
      'error' => [],
    ];

    foreach ($expected_messages as $type => $expected_messages_by_type) {
      $this->assertSameSize($expected_messages_by_type$actual_messages[$type]);
      // Cast the actual messages to string.       $actual_messages_by_type = array_reduce($actual_messages[$type]function Darray $carry$actual_message) {
        $carry[] = (string) $actual_message;
        return $carry;
      }[]);
      $missing_expected_messages_by_type = array_diff($expected_messages_by_type$actual_messages_by_type);
      $unexpected_messages_by_type = array_diff($actual_messages_by_type$expected_messages_by_type);
      $this->assertEmpty($unexpected_messages_by_typesprintf('No additional messages are present with type "%s". This expectation is wrong, because there are additional messages present: "%s"', $typeimplode('", "', $unexpected_messages_by_type)));
      $this->assertEmpty($missing_expected_messages_by_typesprintf('Every expected messages are present with type "%s". This expectation is wrong, because the following messages aren\'t present: "%s"', $typeimplode('", "', $missing_expected_messages_by_type)));
    }

    

  protected function assertNormalizedFieldsAreCached(array $field_names): void {
    $cache = \Drupal::service('render_cache')->get([
      '#cache' => [
        'keys' => ['node--camelids', $this->entity->uuid()$this->entity->language()->getId()],
        'bin' => 'jsonapi_normalizations',
      ],
    ]);
    $cached_fields = $cache['#data']['fields'];
    $this->assertSameSize($field_names$cached_fields);
    array_walk($field_namesfunction D$field_name) use ($cached_fields) {
      $this->assertInstanceOf(
        CacheableNormalization::class,
        $cached_fields[$field_name]
      );
    });
  }

  /** * {@inheritdoc} */
  
/** * Make sure we've accounted for all the templates. */
  public function testVerifyTemplateTestProviderIsAccurate() {
    $root = $this->getDrupalRoot();
    $data = $this->provideTemplateCreateProject();

    // Find all the templates.     $template_files = Composer::composerSubprojectPaths($root, 'Template');

    $this->assertSameSize($template_files$data);

    // We could have the same number of templates but different names.     $template_data = [];
    foreach ($data as $data_name => $data_value) {
      $template_data[$data_value[0]] = $data_name;
    }
    /** @var \SplFileInfo $file */
    foreach ($template_files as $file) {
      $json_file = new JsonFile($file->getPathname());
      $json = $json_file->read();
      $this->assertArrayHasKey('name', $json);
      
$workflow->save();

    $this->setCurrentUser($this->createUser($permissions));

    $node = Node::create([
      'type' => 'example',
      'title' => 'Test content',
      'moderation_state' => $target_state,
    ]);
    $this->assertTrue($node->isNew());
    $violations = $node->validate();
    $this->assertSameSize($messages$violations);
    foreach ($messages as $i => $message) {
      $this->assertEquals($message$violations->get($i)->getMessage());
    }
  }

  /** * Test cases for ::testTransitionAccessValidation. */
  public function transitionAccessValidationTestCases() {
    return [
      'Invalid transition, no permissions validated' => [
        [],
/** * Tests random ordering of the result set. * * @see DatabaseSelectTestCase::testRandomOrder() */
  public function testRandomOrdering() {
    // Execute a basic view first.     $view = Views::getView('test_view');
    $this->executeView($view);

    // Verify the result.     $this->assertSameSize($this->dataSet()$view->result, 'The number of returned rows match.');
    $this->assertIdenticalResultset($view$this->dataSet()[
      'views_test_data_name' => 'name',
      'views_test_data_age' => 'age',
    ]);

    // Execute a random view, we expect the result set to be different.     $view_random = $this->getBasicRandomView();
    $this->executeView($view_random);
    $this->assertSameSize($this->dataSet()$view_random->result, 'The number of returned rows match.');
    $this->assertNotIdenticalResultset($view_random$view->result, [
      'views_test_data_name' => 'views_test_data_name',
      
'de' => ['drupal-8.0.0.de.po'],
      'fr-CA' => ['drupal-8.0.x.fr-CA.po'],
      'hu' => ['drupal-8.0.0-beta2.hu.po'],
      'it' => [],
    ];

    // Hardcode the fixtures location as we don't yet know where it is.     // @todo Remove as part of https://www.drupal.org/node/2186491     $file_translation = new FileTranslation('core/tests/fixtures/files/translations', $this->container->get('file_system'));
    foreach ($expected_translation_files as $langcode => $files_expected) {
      $files_found = $file_translation->findTranslationFiles($langcode);
      $this->assertSameSize($files_expected$files_foundnew FormattableMarkup('@count installer languages found.', ['@count' => count($files_expected)]));
      foreach ($files_found as $file) {
        $this->assertContains($file->filename, $files_expectednew FormattableMarkup('@file found.', ['@file' => $file->filename]));
      }
    }
  }

  /** * Tests profile info caching in non-English languages. */
  public function testInstallerTranslationCache() {
    require_once 'core/includes/install.inc';

    
/** * Tests whether op classes returned by DiffEngine::diff() match expectations. * * @covers ::diff * @dataProvider provideTestDiff */
  public function testDiff($expected$from$to) {
    $this->expectDeprecation('Drupal\Component\Diff\Engine\DiffEngine is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use sebastianbergmann/diff instead. See https://www.drupal.org/node/3337942');
    $diff_engine = new DiffEngine();
    $diff = $diff_engine->diff($from$to);
    // Make sure we have the same number of results as expected.     $this->assertSameSize($expected$diff);
    // Make sure the diff objects match our expectations.     foreach ($expected as $index => $op_class) {
      $this->assertEquals($op_classget_class($diff[$index]));
    }
  }

  /** * Tests that two files can be successfully diffed. * * @covers ::diff */
  

  protected function assertEntity(string $id, string $label, array $expected_effect_plugins, array $expected_effect_config): void {
    $style = ImageStyle::load($id);
    $this->assertInstanceOf(ImageStyleInterface::class$style);
    /** @var \Drupal\image\ImageStyleInterface $style */
    $this->assertSame($id$style->id());
    $this->assertSame($label$style->label());

    // Check the number of effects associated with the style.     $effects = $style->getEffects();
    $this->assertSameSize($expected_effect_plugins$effects);

    $index = 0;
    foreach ($effects as $effect) {
      $this->assertInstanceOf(ImageEffectBase::class$effect);
      $this->assertSame($expected_effect_plugins[$index]$effect->getPluginId());
      $config = $effect->getConfiguration();
      $this->assertSame($expected_effect_config[$index]$config['data']);
      $index++;
    }
  }

}

  public function checkHooksInvocations($expected_hooks$actual_hooks) {
    foreach ($expected_hooks as $hook => $invocations) {
      $actual_invocations = $actual_hooks[$hook];

      // Check that the number of invocations is correct.       $this->assertSameSize($invocations$actual_invocations, "$hook() was called the expected number of times.");

      // Check that the hook was called for each expected argument.       foreach ($invocations as $argument) {
        $found = FALSE;
        foreach ($actual_invocations as $actual_arguments) {
          // The argument we are looking for is either an array of entities as           // the second argument or a single entity object as the first.           if ($argument instanceof EntityInterface && $actual_arguments[0]->id() == $argument->id()) {
            $found = TRUE;
            break;
          }
          
$view->destroy();

    // Test each bundle type.     foreach ($bundle_info as $key => $info) {
      // Test each bundle type.       $view->initDisplay();
      $filters = $view->display_handler->getOption('filters');
      $filters['type']['value'] = [$key => $key];
      $view->display_handler->setOption('filters', $filters);
      $this->executeView($view);

      $this->assertSameSize($entities[$key]$view->result);

      $view->destroy();
    }

    // Test an invalid bundle type to make sure we have no results.     $view->initDisplay();
    $filters = $view->display_handler->getOption('filters');
    $filters['type']['value'] = ['type_3' => 'type_3'];
    $view->display_handler->setOption('filters', $filters);
    $this->executeView($view);

    
      foreach ($test_strings as $str => $context) {
        $args = ['%source' => $str, '%context' => $context];

        // Make sure that the string was found in the file.         $this->assertTrue(isset($source_strings[$str])new FormattableMarkup('Found source string: %source', $args));

        // Make sure that the proper context was matched.         $this->assertArrayHasKey($str$source_strings);
        $this->assertSame($context$source_strings[$str]);
      }

      $this->assertSameSize($test_strings$source_strings, 'Found correct number of source strings.');
    }
  }

  /** * Assert translations JS is added before drupal.js, because it depends on it. */
  public function testLocaleTranslationJsDependencies() {
    // User to add and remove language.     $admin_user = $this->drupalCreateUser([
      'administer languages',
      'access administration pages',
      
$data_row = $row->getSource();
      // The "data" row returned by getSource() also includes all source       // configuration - we remove it so we see only the data itself.       unset($data_row['plugin']);
      unset($data_row['data_rows']);
      unset($data_row['ids']);
      $results[] = $data_row;
    }
    $this->assertSame($data_rows$results);

    // Validate the public APIs.     $this->assertSameSize($data_rows$source);
    $this->assertSame($ids$source->getIds());
    $expected_fields = [
      'key' => 'key',
      'field1' => 'field1',
      'field2' => 'field2',
    ];
    $this->assertSame($expected_fields$source->fields());
  }

}
'status' => [],
      'warning' => [],
      'error' => [],
    ];
    $actual_messages = $this->migrateMessages + [
      'status' => [],
      'warning' => [],
      'error' => [],
    ];

    foreach ($expected_messages as $type => $expected_messages_by_type) {
      $this->assertSameSize($expected_messages_by_type$actual_messages[$type]);
      // Cast the actual messages to string.       $actual_messages_by_type = array_reduce($actual_messages[$type]function Darray $carry$actual_message) {
        $carry[] = (string) $actual_message;
        return $carry;
      }[]);
      $missing_expected_messages_by_type = array_diff($expected_messages_by_type$actual_messages_by_type);
      $unexpected_messages_by_type = array_diff($actual_messages_by_type$expected_messages_by_type);
      $this->assertEmpty($unexpected_messages_by_typesprintf('No additional messages are present with type "%s". This expectation is wrong, because there are additional messages present: "%s"', $typeimplode('", "', $unexpected_messages_by_type)));
      $this->assertEmpty($missing_expected_messages_by_typesprintf('Every expected messages are present with type "%s". This expectation is wrong, because the following messages aren\'t present: "%s"', $typeimplode('", "', $missing_expected_messages_by_type)));
    }

    


  /** * Tests a query. * * @param array|\Traversable $iter * The countable. foreach-able actual results if a query is being run. * @param array $expected_results * An array of expected results. */
  public function queryResultTest($iter$expected_results) {
    $this->assertSameSize($expected_results$iter, 'Number of results match');
    $count = 0;
    foreach ($iter as $data_row) {
      $expected_row = $expected_results[$count];
      $count++;
      foreach ($expected_row as $key => $expected_value) {
        $this->retrievalAssertHelper($expected_value$this->getValue($data_row$key)sprintf('Value matches for key "%s"', $key));
      }
    }
    $this->assertSame(count($expected_results)$count);
  }

  
$block_storage = $this->container->get('entity_type.manager')->getStorage('block');

    // Ensure that the new default theme has the same blocks as the previous     // default theme.     $default_block_names = $block_storage->getQuery()
      ->condition('theme', $default_theme)
      ->execute();
    $new_blocks = $block_storage->getQuery()
      ->condition('theme', $new_theme)
      ->execute();
    $this->assertSameSize($default_block_names$new_blocks);

    foreach ($default_block_names as $default_block_name) {
      // Remove the matching block from the list of blocks in the new theme.       // E.g., if the old theme has block.block.stark_admin,       // unset block.block.olivero_admin.       unset($new_blocks[str_replace($default_theme . '_', $new_theme . '_', $default_block_name)]);
    }
    $this->assertEmpty($new_blocks);

    // Install a hidden base theme and ensure blocks are not copied.     $base_theme = 'test_basetheme';
    
Home | Imprint | This part of the site doesn't use cookies.