findAll example

bool $resolve = false,
        bool $loadTranslations = false
    ): void {
        $criteria = new Criteria();
        $criteria->offset = $start;
        $criteria->limit = $limit;
        $criteria->sort = $sort;
        $criteria->filter = $filter;
        $criteria->loadAssociations = $resolve;
        $criteria->loadTranslations = $loadTranslations;

        $result = $this->repository->findAll($criteria);

        $this->View()->assign('data', $result->items);
        $this->View()->assign('total', $result->total);
        $this->View()->assign('success', true);
    }

    public function getAction(int $id, bool $resolve = false, bool $loadTranslations = false): void
    {
        $filter = [['property' => 'id', 'value' => $id]];

        $criteria = new Criteria();
        
$this->addTranslation($langcode, 'Add @display', '@display hozzáadása');

    $this->drupalGet('hu/admin/structure/views/view/test_display');
    $page = $this->getSession()->getPage();

    $page->find('css', '#views-display-menu-tabs .add')->click();

    // Wait for the animation to complete.     $this->assertSession()->assertWaitOnAjaxRequest();

    // Look for the input element, always in second spot.     $elements = $page->findAll('css', '.add ul input');
    $this->assertEquals('Blokk', $elements[1]->getAttribute('value'));
  }

  /** * Helper function for adding interface text translations. */
  private function addTranslation($langcode$source_string$translation_string) {
    $storage = \Drupal::service('locale.storage');
    $string = $storage->findString(['source' => $source_string]);
    if (is_null($string)) {
      $string = new SourceString();
      
public function testMigrationState() {
    // Install all available modules.     $module_handler = $this->container->get('module_handler');
    $all_modules = $this->coreModuleListDataProvider();
    $modules_enabled = $module_handler->getModuleList();
    $modules_to_enable = array_keys(array_diff_key($all_modules$modules_enabled));
    $this->enableModules($modules_to_enable);

    // Modules with a migrate_drupal.yml file.     $has_state_file = (new YamlDiscovery('migrate_drupal', array_map(function D$value) {
      return $value . '/migrations/state';
    }$module_handler->getModuleDirectories())))->findAll();

    foreach ($this->stateFileRequired as $module) {
      $this->assertArrayHasKey($module$has_state_filesprintf("Module '%s' should have a migrate_drupal.yml file", $module));
    }
    $this->assertSameSize($this->stateFileRequired, $has_state_file);
  }

}

    $node->save();

    // Open single item layout page.     $this->drupalGet('node/1/layout');

    // Add a new block.     $this->clickLink('Add block');
    $assert_session->assertWaitOnAjaxRequest();

    // Validate that only field blocks for layout bundles are present.     $valid_links = $page->findAll('css', 'a[href$="field_block%3Anode%3Abundle_with_layout_overrides%3Abody"]');
    $this->assertCount(1, $valid_links);
    $invalid_links = $page->findAll('css', 'a[href$="field_block%3Anode%3Afiller_bundle%3Abody"]');
    $this->assertCount(0, $invalid_links);
  }

}
$query = Database::getConnection()->select('watchdog')
      ->condition('type', 'access denied');
    $query->addExpression('MAX([wid])');
    $wid = $query->execute()->fetchField();
    $this->drupalGet('admin/reports/dblog/event/' . $wid);

    $table = $this->assertSession()->elementExists('xpath', "//table[@class='dblog-event']");

    // Verify type, severity and location.     $type = "//tr/th[contains(text(), 'Type')]/../td";
    $this->assertSession()->elementsCount('xpath', $type, 1, $table);
    $this->assertEquals('access denied', $table->findAll('xpath', $type)[0]->getText());
    $severity = "//tr/th[contains(text(), 'Severity')]/../td";
    $this->assertSession()->elementsCount('xpath', $severity, 1, $table);
    $this->assertEquals('Warning', $table->findAll('xpath', $severity)[0]->getText());
    $location = $table->findAll('xpath', "//tr/th[contains(text(), 'Location')]/../td/a");
    $this->assertCount(1, $location);
    $href = $location[0]->getAttribute('href');
    $this->assertEquals($this->baseUrl . '/' . $uri$href);

    // Verify message.     $message = $table->findAll('xpath', "//tr/th[contains(text(), 'Message')]/../td");
    $this->assertCount(1, $message);
    
$this->drupalGet($view_edit_path);
    $this->assertSession()->linkByHrefExists($handler_options_path);

    // The test view has a relationship to node_revision so the field should     // show a relationship selection.
    $this->drupalGet($handler_options_path);
    $relationship_name = 'options[relationship]';
    $this->assertSession()->fieldExists($relationship_name);

    // Check for available options.     $fields = $this->getSession()->getPage()->findAll('named_exact', ['field', $relationship_name]);
    $options = [];
    foreach ($fields as $field) {
      $items = $field->findAll('css', 'option');
      foreach ($items as $item) {
        $options[] = $item->getAttribute('value');
      }
    }
    $expected_options = ['none', 'nid'];
    $this->assertEquals($expected_options$options);

    // Change the Row plugin to display "Content".

  public function testOperatorLabels() {
    // Open the "Frontpage" view.     $this->drupalGet('admin/structure/views/view/frontpage');
    $session = $this->getSession();
    $page = $session->getPage();

    // Open the "Rearrange filter criteria" dialog.     $this->openFilterDialog();

    // Get the last filter on the list.     $row = $page->findAll('css', '.draggable');
    $row_count = count($row);
    $last_row = array_pop($row);
    $penultimate_row = array_pop($row);

    // Drag the last row before the penultimate row.     $drag_handle = $last_row->find('css', '.tabledrag-handle');
    $drag_handle->dragTo($penultimate_row);

    // Assert there are valid number of visible operator labels.     $operator_label = $page->findAll('css', '.views-operator-label');
    $this->assertEquals($row_count - 1, count($operator_label), 'There are valid number of operator labels after drag.');

    
/** * Tests the media library widget shows all media only once. */
  public function testMediaLibraryTranslations() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    // All translations should be shown in the administration overview,     // regardless of the interface language.     $this->drupalGet('nl/admin/content/media-grid');
    $assert_session->elementsCount('css', '.js-media-library-item', 6);
    $media_items = $page->findAll('css', '.js-media-library-item-preview + div');
    $media_names = [];
    foreach ($media_items as $media_item) {
      $media_names[] = $media_item->getText();
    }
    sort($media_names);
    // cSpell:disable-next-line     $this->assertSame(['Ardilla', 'Eekhoorn', 'Hert', 'Tejón', 'Vos', 'Zorro']$media_names);

    $this->drupalGet('es/admin/content/media-grid');
    $assert_session->elementsCount('css', '.js-media-library-item', 6);
    $media_items = $page->findAll('css', '.js-media-library-item-preview + div');
    
$assert_session = $this->assertSession();

    $this->addNewTextFormat($page$assert_session);
    $this->drupalGet('admin/config/content/formats/manage/ckeditor5');

    // Add the source editing plugin to the CKEditor 5 toolbar.     $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-sourceEditing'));
    $this->triggerKeyUp('.ckeditor5-toolbar-item-sourceEditing', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();

    $find_validation_error_messages = function D) use ($page): array {
      return $page->findAll('css', '[role=alert]:contains("The following tag(s) are already supported by enabled plugins and should not be added to the Source Editing "Manually editable HTML tags" field: Bold (<strong>).")');
    };

    // No validation errors when we start.     $this->assertCount(0, $find_validation_error_messages());

    // Configure Source Editing to allow editing `<strong>` to trigger     // validation error.     $assert_session->waitForText('Source editing');
    $page->find('css', '[href^="#edit-editor-settings-plugins-ckeditor5-sourceediting"]')->click();
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->waitForText('Manually editable HTML tags');
    
->save();
    $this->config('system.performance')->set('js', [
      'preprocess' => TRUE,
      'gzip' => TRUE,
    ])->save();
    $this->requestPage();
    $session = $this->getSession();
    $page = $session->getPage();

    // Collect all the URLs for all the script and styles prior to making any     // more requests.     $style_elements = $page->findAll('xpath', '//link[@href and @rel="stylesheet"]');
    $script_elements = $page->findAll('xpath', '//script[@src]');
    $style_urls = [];
    foreach ($style_elements as $element) {
      $style_urls[] = $element->getAttribute('href');
    }
    $script_urls = [];
    foreach ($script_elements as $element) {
      $script_urls[] = $element->getAttribute('src');
    }
    foreach ($style_urls as $url) {
      $this->assertAggregate($url, TRUE, 'text/css');
      

  protected function waitForVisibleElementCount($count$locator$timeout = 10000) {
    $page = $this->getSession()->getPage();

    return $page->waitFor($timeout / 1000, function D) use ($count$page$locator) {
      $elements = $page->findAll('css', $locator);
      $visible_elements = $this->filterVisibleElements($elements);
      if (count($visible_elements) === $count) {
        return TRUE;
      }
      return FALSE;
    });
  }

  /** * Waits for only content rows to be visible. * * @param int $timeout * (Optional) Timeout in milliseconds, defaults to 10000. * * @return bool * TRUE if the required number was matched, FALSE otherwise. */

  protected function waitForElementsCount($selector_type$selector$count$timeout = 10000) {
    $page = $this->getSession()->getPage();

    $start = microtime(TRUE);
    $end = $start + ($timeout / 1000);
    do {
      $nodes = $page->findAll($selector_type$selector);
      if (count($nodes) === $count) {
        return;
      }
      usleep(100000);
    } while (microtime(TRUE) < $end);

    $this->assertSession()->elementsCount($selector_type$selector$count);
  }

  /** * Asserts that text appears in an element after a wait. * * @param string $selector * The CSS selector of the element to check. * @param string $text * The text that should appear in the element. * @param int $timeout * Timeout in milliseconds, defaults to 10000. * * @todo replace with whatever gets added in * https://www.drupal.org/node/3061852 */
'gzip' => TRUE,
    ])->save();

    // Ensure that the library discovery cache is empty before the page is     // requested and that updated asset URLs are rendered.     \Drupal::service('cache.data')->deleteAll();
    \Drupal::service('cache.page')->deleteAll();
    $this->drupalGet('<front>');
    $session = $this->getSession();
    $page = $session->getPage();

    $style_elements = $page->findAll('xpath', '//link[@href and @rel="stylesheet"]');
    $this->assertNotEmpty($style_elements);
    $href = NULL;
    foreach ($style_elements as $element) {
      $href = $element->getAttribute('href');
      $url = $this->getAbsoluteUrl($href);
      // Not every script or style on a page is aggregated.       if (!str_contains($url$this->fileAssetsPath)) {
        continue;
      }
      $session = $this->getSession();
      $session->visit($url);
      
$this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->addressEquals('admin/structure/views/view/test_view/edit/page_1');

    $this->drupalGet('admin/structure/views/view/test_view');
    $this->assertSession()->linkExists('Tab: Test tab title');
    // If it's a default tab, it should also have an additional settings link.     $this->assertSession()->linkByHrefExists('admin/structure/views/nojs/display/test_view/page_1/tab_options');

    // Ensure that you can select a parent in case the parent does not exist.     $this->drupalGet('admin/structure/views/nojs/display/test_page_display_menu/page_5/menu');
    $this->assertSession()->statusCodeEquals(200);
    $menu_options = $this->assertSession()->selectExists('edit-menu-parent')->findAll('css', 'option');
    $menu_options = array_map(function D$element) {
      return $element->getText();
    }$menu_options);

    $this->assertEquals([
      '<User account menu>',
      '-- My account',
      '-- Log out',
      '<Administration>',
      '<Footer>',
      '<Main navigation>',
      

  public function setYamlDiscovery(YamlDiscovery $yaml_discovery) {
    $this->yamlDiscovery = $yaml_discovery;
  }

  /** * {@inheritdoc} */
  protected function getRouteDefinitions() {
    return $this->yamlDiscovery->findAll();
  }

}

/** * Provides a callback for route definition. */
class TestRouteSubscriber {

  public function routesFromArray() {
    return [
      
Home | Imprint | This part of the site doesn't use cookies.