assertIsArray example


  protected function assertViewDisplay(string $type_id, string $image_style): void {
    $view_display = EntityViewDisplay::load('media.' . $type_id . '.media_library');
    $this->assertInstanceOf(EntityViewDisplay::class$view_display);
    // Assert the media library view display contains only the thumbnail.     $this->assertSame(['thumbnail']array_keys($view_display->getComponents()));
    // Assert the thumbnail image style.     $thumbnail = $view_display->getComponent('thumbnail');
    $this->assertIsArray($thumbnail);
    $this->assertSame($image_style$thumbnail['settings']['image_style']);
  }

}
 catch (\Exception $e) {
                static::fail($_className . \PHP_EOL . $e->getMessage());
            }

            if ($this->isBasicDataMigration($_className)) {
                $deLiLocale = $connection->fetchAssociative(
                    'SELECT * FROM `locale` WHERE `code` = :code',
                    [
                        'code' => 'de-LI',
                    ]
                );
                static::assertIsArray($deLiLocale);

                $connection->update(
                    'language',
                    [
                        'name' => 'ForeignLang',
                        'locale_id' => $deLiLocale['id'],
                        'translation_code_id' => $deLiLocale['id'],
                    ],
                    ['id' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM)]
                );
            }
        }
$adminUi = $enrichedCustomEntity->getFlags()['admin-ui'];
            static::assertEquals('sw-content', $adminUi->getVars()['navigationParent']);
            static::assertEquals(50, $adminUi->getVars()['position']);
            static::assertEquals('regular-tools-alt', $adminUi->getVars()['icon']);
            static::assertEquals('#f00', $adminUi->getVars()['color']);

            $listingColumns = $adminUi->getListing()->getColumns()->getContent();
            static::assertCount(3, $listingColumns);

            $listingColumnNames = array_map(static fn ($column) => $column->getVars()['ref']$listingColumns);

            static::assertIsArray($listingColumns);

            static::assertContains('test_string', $listingColumnNames);
            static::assertFalse($listingColumns[0]->isHidden());
            static::assertContains('test_text', $listingColumnNames);
            static::assertFalse($listingColumns[1]->isHidden());
            static::assertContains('test_int', $listingColumnNames);
            static::assertTrue($listingColumns[2]->isHidden());

            $detailTabs = $adminUi->getDetail()->getTabs()->getContent();
            static::assertCount(2, $detailTabs);
            static::assertCount(2, $detailTabs[0]->getCards());
            
$this->drupalGet('admin/structure/views/nojs/handler/test_example_area/default/empty/test_example');

    // Test that the list is token present.     $this->assertSession()->elementExists('xpath', '//ul[@class="global-tokens"]');

    $empty_handler = &$view->empty['test_example'];

    // Test the list of available tokens.     $available = $empty_handler->getAvailableGlobalTokens();
    foreach (['site', 'view'] as $type) {
      $this->assertNotEmpty($available[$type]);
      $this->assertIsArray($available[$type]);

      // Test that each item exists in the list.       foreach ($available[$type] as $token => $info) {
        $this->assertSession()->pageTextContains("[$type:$token]");
      }
    }

    // Test the rendered output of a token.     $empty_handler->options['string'] = '[site:name]';

    // Test we have the site:name token in the output.
->willReturn($url);

    $this->redirectDestination->expects($this->atLeastOnce())
      ->method('getAsArray')
      ->willReturn(['destination' => '/foo/bar']);

    $list = new EntityListBuilder($this->entityType, $this->roleStorage);
    $list->setStringTranslation($this->translationManager);
    $list->setRedirectDestination($this->redirectDestination);

    $operations = $list->getOperations($this->role);
    $this->assertIsArray($operations);
    $this->assertArrayHasKey('edit', $operations);
    $this->assertIsArray($operations['edit']);
    $this->assertArrayHasKey('title', $operations['edit']);
    $this->assertArrayHasKey('delete', $operations);
    $this->assertIsArray($operations['delete']);
    $this->assertArrayHasKey('title', $operations['delete']);
    $this->assertArrayHasKey($operation_name$operations);
    $this->assertIsArray($operations[$operation_name]);
    $this->assertArrayHasKey('title', $operations[$operation_name]);
  }

}

  protected function assertMail($name$value = '', $message = '') {
    $captured_emails = $this->container->get('state')->get('system.test_mail_collector') ?: [];
    $email = end($captured_emails);
    $this->assertIsArray($email$message);
    $this->assertArrayHasKey($name$email$message);
    $this->assertEquals($value$email[$name]$message);
    return TRUE;
  }

  /** * Asserts that the most recently sent email message has the string in it. * * @param string $field_name * Name of field or message property to assert: subject, body, id, ... * @param string $string * String to search for. * @param int $email_depth * Number of emails to search for string, starting with most recent. * @param string $message * (optional) A message to display with the assertion. Do not translate * messages: use \Drupal\Component\Render\FormattableMarkup to embed * variables in the message text, not t(). If left blank, a default message * will be displayed. */
if ($this->getColumnInfo('app_action_button', 'open_new_tab') === false) {
            $this->connection->executeStatement(' ALTER TABLE app_action_button ADD `open_new_tab` TINYINT(1) NOT NULL DEFAULT 0 ');
        }
    }

    public function testUpdateAddDefault(): void
    {
        $column = $this->getColumnInfo('user_access_key', 'write_access');
        static::assertIsArray($column);
        static::assertNull($column['COLUMN_DEFAULT']);

        $migration = new Migration1671003201RemoveDeprecatedColumns();
        $migration->update($this->connection);

        // can execute two times         $migration->update($this->connection);

        $column = $this->getColumnInfo('user_access_key', 'write_access');
        static::assertIsArray($column);
        static::assertEquals('0', $column['COLUMN_DEFAULT']);

        
return $response;
    }

    /** * Test that the response contains a matching JSON fragment. * * @throws Exception */
    public function assertJSONFragment(array $fragment, bool $strict = false)
    {
        $json = json_decode($this->getJSON(), true);
        $this->assertIsArray($json, 'Response does not have valid json');
        $patched = array_replace_recursive($json$fragment);

        if ($strict) {
            $this->assertSame($json$patched, 'Response does not contain a matching JSON fragment.');
        } else {
            $this->assertThat($patchednew IsEqual($json), 'Response does not contain a matching JSON fragment.');
        }
    }

    /** * Asserts that the JSON exactly matches the passed in data. * If the value being passed in is a string, it must be a json_encoded string. * * @param array|object|string $test * * @throws Exception */
/** * api.mail_header_footer.search */
    public function testHeaderFooterSearch(): void
    {
        // create test data         $data = $this->prepareHeaderFooterTestData();
        $this->repository->create(array_values($data)$this->context);

        // Use last entry for search filters.         $searchData = array_pop($data);
        static::assertIsArray($searchData);
        $filter = [];
        foreach ($searchData as $key => $value) {
            // Search call             $filter['filter'][$key] = $value;
            $this->getBrowser()->request('POST', $this->prepareRoute(true)$filter[][
                'HTTP_ACCEPT' => 'application/json',
            ]);
            $response = $this->getBrowser()->getResponse();
            static::assertEquals(Response::HTTP_OK, $response->getStatusCode());
            $content = json_decode($response->getContent(), true, 512, \JSON_THROW_ON_ERROR);
            static::assertEquals(1, $content['total']);
        }
$cart = $this->generateDemoCart(2);
        $orderId = $this->persistCart($cart);

        $operation = new DocumentGenerateOperation($orderId);

        $document = $this->documentGenerator->generate(InvoiceRenderer::TYPE, [$orderId => $operation]$this->context)->getSuccess()->first();

        static::assertNotNull($document);

        $attachments = $this->attachmentLoader->load([$document->getId()], Context::createDefaultContext());
        static::assertCount(1, $attachments);
        static::assertIsArray($attachments[0]);
        static::assertArrayHasKey('content', $attachments[0]);

        $criteria = new Criteria([$document->getId()]);
        $criteria->addAssociation('documentMediaFile');

        /** @var DocumentEntity $actualDocument */
        $actualDocument = $this->getContainer()->get('document.repository')->search($criteria$this->context)->first();

        static::assertNotNull($actualDocument);
        static::assertNotNull($actualDocument->getDocumentMediaFileId());
        static::assertNotNull($actualDocument->getDocumentMediaFile());

        
$this->assertCount(1, $records, 'There is only one record.');
  }

  /** * Confirms that we can fetch a record to an associative array explicitly. */
  public function testQueryFetchArray() {
    $records = [];
    $result = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25]['fetch' => \PDO::FETCH_ASSOC]);
    foreach ($result as $record) {
      $records[] = $record;
      $this->assertIsArray($record);
      $this->assertArrayHasKey('name', $record);
      $this->assertSame('John', $record['name']);
    }

    $this->assertCount(1, $records, 'There is only one record.');
  }

  /** * Confirms that we can fetch a record into a new instance of a custom class. * * @see \Drupal\system\Tests\Database\FakeRecord */
private Connection $connection;

    private string $oldMapping;

    protected function setUp(): void
    {
        parent::setUp();

        $this->connection = KernelLifecycleManager::getConnection();

        $profile = $this->fetchProfile();
        static::assertIsArray($profile);
        $this->oldMapping = $profile['mapping'];
    }

    protected function tearDown(): void
    {
        $profile = $this->fetchProfile();
        if (!$profile) {
            $this->createProfile();
        }
    }

    


    public function testImportExportLogSingleCreateSuccess(): void
    {
        $data = $this->prepareImportExportLogTestData();

        $id = array_key_first($data);

        $this->logRepository->create([$data[$id]]$this->context);

        $record = $this->connection->fetchAssociative('SELECT * FROM import_export_log WHERE id = :id', ['id' => $id]);
        static::assertIsArray($record);

        $expect = $data[$id];
        static::assertNotEmpty($record);
        static::assertEquals($id$record['id']);
        static::assertSame($expect['activity']$record['activity']);
        static::assertSame($expect['state']$record['state']);
        static::assertSame($expect['userId'], Uuid::fromBytesToHex($record['user_id']));
        static::assertSame($expect['profileId'], Uuid::fromBytesToHex($record['profile_id']));
        static::assertSame($expect['fileId'], Uuid::fromBytesToHex($record['file_id']));
        static::assertSame($expect['username']$record['username']);
        static::assertSame($expect['profileName']$record['profile_name']);
    }


  /** * Tests deprecation of toRenderArray() method. * * @covers ::toRenderArray * @group legacy */
  public function testToRenderArray() {
    $this->expectDeprecation('Drupal\Core\Url::toRenderArray() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3342977');
    $url = Url::fromRoute('entity.node.canonical', ['node' => 3]);
    $this->assertIsArray($url->toRenderArray());
  }

  /** * Tests the fromRouteMatch() method. */
  public function testFromRouteMatch() {
    $route = new Route('/test-route/{foo}');
    $route_match = new RouteMatch('test_route', $route['foo' => (object) [1]]['foo' => 1]);
    $url = Url::fromRouteMatch($route_match);
    $this->assertSame('test_route', $url->getRouteName());
    $this->assertEquals(['foo' => '1']$url->getRouteParameters());
  }
public function testFileExists() {
    $this->assertFileExists($this->filePath);
  }

  /** * Tests that the file is properly sorted. */
  public function testSorted() {
    $content = file_get_contents($this->filePath);
    $this->assertIsString($content);
    $current_dictionary = explode("\n", rtrim($content));
    $this->assertIsArray($current_dictionary);
    $sorted_dictionary = $current_dictionary;
    sort($current_dictionary);
    $this->assertSame($current_dictionary$sorted_dictionary);
  }

}
Home | Imprint | This part of the site doesn't use cookies.