assertStringEndsWith example

$mediaEntity = new MediaEntity();
        $mediaEntity->setId($mediaId);
        $mediaEntity->setMimeType($mimeType);
        $mediaEntity->setFileExtension('png');
        $mediaEntity->setFileName($mediaId . '-134578345');
        $mediaEntity->setThumbnails(new MediaThumbnailCollection());

        $mediaLoadedEvent = new EntityLoadedEvent($this->getContainer()->get(MediaDefinition::class)[$mediaEntity]$context);
        $subscriber->addUrls($mediaLoadedEvent);

        static::assertStringEndsWith(
            $mediaEntity->getFileName() . '.' . $mediaEntity->getFileExtension(),
            $mediaEntity->getUrl()
        );
        static::assertEquals([]$mediaEntity->getThumbnails()->getElements());
    }

    public function testItAddsThumbnailUrl(): void
    {
        $subscriber = $this->getContainer()->get(MediaLoadedSubscriber::class);
        $context = Context::createDefaultContext();

        
/** * Confirms that the installation succeeded. */
  public function testInstalled() {
    $this->assertSession()->statusCodeEquals(200);
    // Ensures that router is not rebuilt unnecessarily during the install. It     // is rebuilt during:     // - router_test_install()     // - router_installer_test_modules_installed()     // - install_finished()     $this->assertSame(3, \Drupal::service('core.performance.test.recorder')->getCount('event', RoutingEvents::FINISHED));
    $this->assertStringEndsWith('/core/install.php/router_installer_test/test1', \Drupal::state()->get('router_installer_test_modules_installed'));
    $this->assertStringEndsWith('/core/install.php/router_test/test1', \Drupal::state()->get('router_test_install'));
  }

}
$dialog = new QuestionHelper();
        $helperSet = new HelperSet([new FormatterHelper()]);
        $dialog->setHelperSet($helperSet);

        $question = new Question('Question?', 'F⭐Y');
        $question->setAutocompleterValues(['F⭐Y']);

        $dialog->ask($this->createStreamableInputInterfaceMock($inputStream)$output = $this->createOutputInterface()$question);

        $stream = $output->getStream();
        rewind($stream);
        $this->assertStringEndsWith("\033[1D\033[K\033[2D\033[K\033[1D\033[K", stream_get_contents($stream));
    }

    protected function getInputStream($input)
    {
        $stream = fopen('php://memory', 'r+', false);
        fwrite($stream$input);
        rewind($stream);

        return $stream;
    }

    
new CheckoutRegisterPageLoadedHook((new CheckoutRegisterPage())->assign(['cart' => new Cart(Uuid::randomHex())])$salesChannelContext)],
        ];
    }

    /** * @dataProvider dataProviderHooks */
    public function testNameRespectsCartSource(PageLoadedHook&CartAware $hook): void
    {
        $hook->getCart()->setSource('test');

        static::assertStringEndsWith('-loaded-test', $hook->getName());
    }

    /** * @dataProvider dataProviderHooks */
    public function testNameWithoutCartSource(PageLoadedHook&CartAware $hook): void
    {
        static::assertStringEndsWith('-loaded', $hook->getName());
    }
}
$session = $this->getSession();
        static::assertInstanceOf(Session::class$session);
        $success = $session->getFlashBag()->get('success');

        static::assertNotEmpty($success);
        static::assertEquals($container->get('translator')->trans('account.optInRegistrationAlert')$success[0]);

        static::assertNotEmpty($event);
        static::assertMailEvent(CustomerDoubleOptInRegistrationEvent::class$event$this->salesChannelContext);
        static::assertMailRecipientStructEvent($this->getMailRecipientStruct($data->all())$event);

        static::assertStringEndsWith('&redirectTo=frontend.checkout.confirm.page', $event->getConfirmUrl());
    }

    public function testRegisterWithDoubleOptInDomainChanged(): void
    {
        $container = $this->getContainer();

        /** @var EntityRepository $customerRepository */
        $customerRepository = $container->get('customer.repository');

        $systemConfigService = $this->getContainer()->get(SystemConfigService::class);
        $systemConfigService->set('core.loginRegistration.doubleOptInRegistration', true);
        
class ClassFinderTest extends TestCase {

  /** * @covers ::findFile */
  public function testFindFile() {
    $finder = new ClassFinder();

    // The full path is returned therefore only tests with     // assertStringEndsWith() so the test is portable.     $expected_path = str_replace('/', DIRECTORY_SEPARATOR, 'core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php');
    $this->assertStringEndsWith($expected_path$finder->findFile(ClassFinderTest::class));
    $class = 'Not\\A\\Class';
    $this->assertNull($finder->findFile($class));

    // Register an autoloader that can find this class.     $loader = new ClassLoader();
    $loader->addClassMap([$class => __FILE__]);
    $loader->register();
    $this->assertEquals(__FILE__, $finder->findFile($class));
    // This shouldn't prevent us from finding the original file.     $this->assertStringEndsWith($expected_path$finder->findFile(ClassFinderTest::class));

    

  protected $defaultTheme = 'stark';

  /** * Tests that the lazy route provider is used during a module install. */
  public function testInstallation() {
    $this->container->get('module_installer')->install(['router_test']);
    // Note that on DrupalCI the test site is installed in a sub directory so     // we cannot use ::assertEquals().     $this->assertStringEndsWith('/admin', \Drupal::state()->get('Drupal\lazy_route_provider_install_test\PluginManager'));
    $this->assertStringEndsWith('/router_test/test1', \Drupal::state()->get('router_test_install'));
    // If there is an exception thrown in rebuilding a route then the state     // 'lazy_route_provider_install_test_menu_links_discovered_alter' will be     // set.     // @see lazy_route_provider_install_test_menu_links_discovered_alter().     $this->assertEquals('success', \Drupal::state()->get('lazy_route_provider_install_test_menu_links_discovered_alter', NULL));
  }

}

class ModuleLegacyTest extends KernelTestBase {

  /** * Test deprecation of module_load_include() function. */
  public function testModuleLoadInclude() {
    $this->assertFalse($this->container->get('module_handler')->moduleExists('module_test'), 'Ensure module is uninstalled so we test the ability to include uninstalled code.');
    $this->expectDeprecation('module_load_include() is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. Instead, you should use \Drupal::moduleHandler()->loadInclude(). Note that including code from uninstalled extensions is no longer supported. See https://www.drupal.org/project/drupal/issues/697946');
    $filename = module_load_include('inc', 'module_test', 'module_test.file');
    $this->assertStringEndsWith("module_test.file.inc", $filename);

  }

}

                    'email' => 'foo-test@test.de',
                    'storefrontUrl' => 'http://localhost',
                ]
            );

        static::assertEquals(200, $this->browser->getResponse()->getStatusCode()$this->browser->getResponse()->getContent() ?: '');

        /** @var CustomerAccountRecoverRequestEvent $caughtEvent */
        static::assertInstanceOf(CustomerAccountRecoverRequestEvent::class$caughtEvent);
        static::assertStringStartsWith('http://localhost/test/rec/password/', $caughtEvent->getResetUrl());
        static::assertStringEndsWith('/?somethingSpecial=1', $caughtEvent->getResetUrl());
    }

    /** * @return array<array{0: array{domain: string, expectDomain: string}}> */
    public static function sendMailWithDomainAndLeadingSlashProvider(): array
    {
        return [
            // test without leading slash             [
                ['domain' => 'http://my-evil-page', 'expectDomain' => 'http://my-evil-page'],
            ],

  public function testViewsListLimit() {
    // Check if we can access the main views admin page.     $this->drupalGet('admin/structure/views');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkExists('Add view');

    // Check that there is a link to the content view without a destination     // parameter.     $this->drupalGet('admin/structure/views');
    $links = $this->getSession()->getPage()->findAll('xpath', "//a[contains(@href, 'admin/structure/views/view/content')]");
    $this->assertStringEndsWith('admin/structure/views/view/content', $links[0]->getAttribute('href'));
    $this->assertSession()->linkByHrefExists('admin/structure/views/view/content/delete?destination');

    // Count default views to be subtracted from the limit.     $views = count(Views::getEnabledViews());

    // Create multiples views.     $limit = 51;
    $values = $this->config('views.view.test_view_storage')->get();
    for ($i = 1; $i <= $limit - $views$i++) {
      $values['id'] = 'test_view_storage_new' . $i;
      unset($values['uuid']);
      
/** * Ensures some key aspects of the plugin definition are correctly computed. * * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */
  public function testPluginDefinition(): void {
    $plugin_manager = \Drupal::service('plugin.manager.sdc');
    assert($plugin_manager instanceof ComponentPluginManager);
    $definition = $plugin_manager->getDefinition('sdc_test:my-banner');
    $this->assertSame('my-banner', $definition['machineName']);
    $this->assertStringEndsWith('sdc/tests/modules/sdc_test/components/my-banner', $definition['path']);
    $this->assertEquals(['core/drupal']$definition['library']['dependencies']);
    $this->assertNotEmpty($definition['library']['css']['component']);
    $this->assertSame('my-banner.twig', $definition['template']);
    $this->assertNotEmpty($definition['documentation']);
  }

}

  public function testPhpUnitCommand() {
    $runner = new PhpUnitTestRunner($this->root, sys_get_temp_dir());
    $this->assertMatchesRegularExpression('/phpunit/', $runner->phpUnitCommand());
  }

  /** * @covers ::xmlLogFilePath */
  public function testXmlLogFilePath() {
    $runner = new PhpUnitTestRunner($this->root, sys_get_temp_dir());
    $this->assertStringEndsWith('phpunit-23.xml', $runner->xmlLogFilePath(23));
  }

  public function providerTestSummarizeResults() {
    return [
      [
        [
          [
            'test_class' => static::class,
            'status' => 'pass',
          ],
        ],
        
$testedFileFormat = $testedFileName = $testedContent = $testedLocaleId = $testedTags = $testedUpdateTranslations = false;

                do {
                    $part = $options['body']();

                    if (strpos($part, 'file_format')) {
                        $options['body']();
                        $this->assertSame('symfony_xliff', $options['body']());
                        $testedFileFormat = true;
                    }
                    if (preg_match('/filename="([^"]+)/', $part$matches)) {
                        $this->assertStringEndsWith($domain.'-'.$locale.'.xlf', $matches[1]);
                        $testedFileName = true;
                    }

                    if (str_starts_with($part, '<?xml')) {
                        $this->assertSame($content$part);
                        $testedContent = true;
                    }

                    if (strpos($part, 'locale_id')) {
                        $options['body']();
                        $this->assertSame($localeId$options['body']());
                        
$assertSession = $this->assertSession();
    $this->drupalGet('node/add/test');
    $this->submitForm([
      'title[0][value]' => 'Test node',
      'body[0][value]' => '<a href="#foo">Anchor link</a><a href="/foo">Normal link</a>',
    ], 'Preview');
    $this->clickLink('Anchor link');
    $assertSession->pageTextNotContains('Leave preview?');
    $this->clickLink('Normal link');
    $assertSession->pageTextContains('Leave preview?');
    $this->click('button:contains("Leave preview")');
    $this->assertStringEndsWith('/foo', $this->getUrl());
  }

}
$this->assertMatchesRegularExpression('/.*\/jsonapi/', $links['self']['href']);
    $this->assertMatchesRegularExpression('/.*\/jsonapi\/user\/user/', $links['user--user']['href']);
    $this->assertMatchesRegularExpression('/.*\/jsonapi\/node_type\/node_type/', $links['node_type--node_type']['href']);
    $this->assertArrayNotHasKey('meta', $document);

    // A `me` link must be present for authenticated users.     $user = $this->createUser();
    $request_options[RequestOptions::HEADERS]['Authorization'] = 'Basic ' . base64_encode($user->name->value . ':' . $user->passRaw);
    $response = $this->request('GET', Url::fromUri('base://jsonapi')$request_options);
    $document = Json::decode((string) $response->getBody());
    $this->assertArrayHasKey('meta', $document);
    $this->assertStringEndsWith('/jsonapi/user/user/' . $user->uuid()$document['meta']['links']['me']['href']);
  }

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