assertStringContainsString example

private ?CommandTester $passwordHasherCommandTester = null;
    private string|false $colSize;

    public function testEncodePasswordEmptySalt()
    {
        $this->passwordHasherCommandTester->execute([
            'password' => 'password',
            'user-class' => 'Symfony\Component\Security\Core\User\InMemoryUser',
            '--empty-salt' => true,
        ]['decorated' => false]);

        $this->assertStringContainsString(' Password hash password', $this->passwordHasherCommandTester->getDisplay());
    }

    public function testEncodeNoPasswordNoInteraction()
    {
        $statusCode = $this->passwordHasherCommandTester->execute([
        ]['interactive' => false]);

        $this->assertStringContainsString('[ERROR] The password must not be empty.', $this->passwordHasherCommandTester->getDisplay());
        $this->assertEquals(1, $statusCode);
    }

    
$processedCart = $this->cartProcessor->process($cart$contextnew CartBehavior());

        $exception = null;

        try {
            $this->orderPersister->persist($processedCart$context);
        } catch (CartException $exception) {
        }

        static::assertInstanceOf(CartException::class$exception);
        static::assertStringContainsString('Line item "test" incomplete. Property "label" missing.', $exception->getMessage());
    }

    private function getCustomer(): CustomerEntity
    {
        $faker = Factory::create();

        $billingAddress = new CustomerAddressEntity();
        $billingAddress->setId('SWAG-ADDRESS-ID-1');
        $billingAddress->setSalutationId($this->getValidSalutationId());
        $billingAddress->setFirstName($faker->firstName);
        $billingAddress->setLastName($faker->lastName);
        
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;

class HelpCommandTest extends TestCase
{
    public function testExecuteForCommandAlias()
    {
        $command = new HelpCommand();
        $command->setApplication(new Application());
        $commandTester = new CommandTester($command);
        $commandTester->execute(['command_name' => 'li']['decorated' => false]);
        $this->assertStringContainsString('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
        $this->assertStringContainsString('format=FORMAT', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
        $this->assertStringContainsString('raw', $commandTester->getDisplay(), '->execute() returns a text help for the given command alias');
    }

    public function testExecuteForCommand()
    {
        $command = new HelpCommand();
        $commandTester = new CommandTester($command);
        $command->setCommand(new ListCommand());
        $commandTester->execute([]['decorated' => false]);
        $this->assertStringContainsString('list [options] [--] [<namespace>]', $commandTester->getDisplay(), '->execute() returns a text help for the given command');
        
public function testMigrateEnv(): void
    {
        $tmpDir = sys_get_temp_dir() . '/flex-migrator-test';
        $fs = new Filesystem();
        $fs->mkdir($tmpDir);

        $flexMigrator = new FlexMigrator();

        $flexMigrator->migrateEnvFile($tmpDir);

        static::assertFileExists($tmpDir . '/.env');
        static::assertStringContainsString('###> symfony/lock ###', (string) file_get_contents($tmpDir . '/.env'));

        $fs->remove($tmpDir);
    }

    public function testMigrateEnvExistingEnv(): void
    {
        $tmpDir = sys_get_temp_dir() . '/flex-migrator-test';
        $fs = new Filesystem();
        $fs->mkdir($tmpDir);
        $fs->dumpFile($tmpDir . '/.env', 'old');

        

    public function testDumpString($var$needle)
    {
        $dumper = new HtmlDumper();
        $cloner = new VarCloner();

        ob_start();
        $dumper->dump($cloner->cloneVar($var));
        $out = ob_get_clean();

        $this->assertStringContainsString($needle$out);
    }

    public static function varToDumpProvider()
    {
        return [
            [['dummy' => new ImgStub('dummy', 'img/png', '100em')], '<img src="data:img/png;base64,ZHVtbXk=" />'],
            ['foo', '<span class=sf-dump-str title="3 characters">foo</span>'],
        ];
    }
}
/** * Tests libraryOverrides. */
  public function testLibraryOverrides(): void {
    $build = [
      '#type' => 'inline_template',
      '#template' => "{{ include('sdc_theme_test:lib-overrides') }}",
    ];
    \Drupal::state()->set('sdc_test_component', $build);
    $output = $this->drupalGet('sdc-test-component');
    $this->assertStringContainsString('another-stylesheet.css', $output);
    // Since libraryOverrides is taking control of CSS, and it's not listing     // lib-overrides.css, then it should not be there. Even if it's the CSS     // that usually gets auto-attached.     $this->assertStringNotContainsString('lib-overrides.css', $output);
    // Ensure that libraryDependencies adds the expected assets.     $this->assertStringContainsString('dialog.position.js', $output);
    // Ensure that libraryOverrides processes attributes properly.     $this->assertMatchesRegularExpression('@<script.*src="[^"]*lib-overrides\.js\?v=1[^"]*".*defer.*bar="foo"></script>@', $output);
    // Ensure that libraryOverrides processes external CSS properly.     $this->assertMatchesRegularExpression('@<link.*href="https://drupal\.org/fake-dependency/styles\.css" />@', $output);
    // Ensure that libraryOverrides processes external JS properly.


    // Ensure that the tests still pass when the file is generated by accessing     // a poorly constructed (but still valid) file URL that has an extra slash     // in it.     if ($extra_slash) {
      $modified_uri = str_replace('://', ':///', $original_uri);
      $this->assertNotEquals($original_uri$modified_uri, 'An extra slash was added to the generated file URI.');
      $generate_url = $this->style->buildUrl($modified_uri$clean_url);
    }
    if (!$clean_url) {
      $this->assertStringContainsString('index.php/', $generate_url, 'When using non-clean URLS, the system path contains the script name.');
    }
    // Add some extra chars to the token.     $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', IMAGE_DERIVATIVE_TOKEN . '=Zo', $generate_url));
    $this->assertSession()->statusCodeEquals(404);
    // Change the parameter name so the token is missing.     $this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', 'wrongparam=', $generate_url));
    $this->assertSession()->statusCodeEquals(404);

    // Check that the generated URL is the same when we pass in a relative path     // rather than a URI. We need to temporarily switch the default scheme to     // match the desired scheme before testing this, then switch it back to the
protected function tearDown(): void
    {
        $this->removeApp();
    }

    public function testSuccessfulCreateCommand(): void
    {
        $commandTester = $this->getCommandTester();

        $commandTester->execute(['name' => self::APP_NAME]);

        static::assertStringContainsString(
            'Creating app structure under TestApp',
            (string) preg_replace('/\s+/', ' ', trim($commandTester->getDisplay(true)))
        );

        static::assertFileExists($this->appDir . '/TestApp/manifest.xml');
        static::assertEquals(
            <<<EOL <?xml version="1.0" encoding="UTF-8"?> <manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/trunk/src/Core/Framework/App/Manifest/Schema/manifest-2.0.xsd"> <meta> <name>TestApp</name> <label>My Example App</label> <description>A description</description> <author>Your Company Ltd.</author> <copyright>(c) by Your Company Ltd.</copyright> <version>1.0.0</version> <icon></icon> <license>MIT</license> </meta> </manifest>


    public function testLegacyTestMethodIsDetectedAsSuch()
    {
        $deprecation = new Deprecation('💩', $this->debugBacktrace(), __FILE__);
        $this->assertTrue($deprecation->isLegacy('whatever'));
    }

    public function testItCanBeConvertedToAString()
    {
        $deprecation = new Deprecation('💩', $this->debugBacktrace(), __FILE__);
        $this->assertStringContainsString('💩', $deprecation->toString());
        $this->assertStringContainsString(__FUNCTION__, $deprecation->toString());
    }

    public function testItRulesOutFilesOutsideVendorsAsIndirect()
    {
        $deprecation = new Deprecation('💩', $this->debugBacktrace(), __FILE__);
        $this->assertNotSame(Deprecation::TYPE_INDIRECT, $deprecation->getType());
    }

    /** * @dataProvider mutedProvider */
$container->register(MigrationSource::class D '.core.V6_4', MigrationSource::class)->setPublic(true);
        $container->register(MigrationSource::class D '.core.V6_5', MigrationSource::class)->setPublic(true);
        $container->register(MigrationSource::class D '.core.V6_6', MigrationSource::class)->setPublic(true);

        $container->addCompilerPass(new StorefrontMigrationReplacementCompilerPass());
        $container->compile();

        $calls = $container->getDefinition(MigrationSource::class D '.core.V6_3')->getMethodCalls();
        static::assertCount(1, $calls);

        static::assertSame('addDirectory', $calls[0][0]);
        static::assertStringContainsString('Migration/V6_3', $calls[0][1][0]);
        static::assertSame('Shopware\Storefront\Migration\V6_3', $calls[0][1][1]);
    }
}


        $commandTester = new CommandTester(
            new ResolveAppUrlChangeCommand($urlChangeStrategy)
        );

        $commandTester->setInputs(['testStrategy']);
        $commandTester->execute([]);

        static::assertEquals(0, $commandTester->getStatusCode());

        static::assertStringContainsString('Choose what strategy should be applied, to resolve the app url change?:', $commandTester->getDisplay());
        static::assertStringContainsString('testStrategy', $commandTester->getDisplay());
        static::assertStringContainsString('secondStrategy', $commandTester->getDisplay());
        static::assertStringContainsString('[OK] Strategy "testStrategy" was applied successfully', $commandTester->getDisplay());
    }

    public function testResolveAppUrlChangeWithProvidedStrategy(): void
    {
        $urlChangeStrategy = $this->createMock(Resolver::class);
        $urlChangeStrategy->expects(static::once())
            ->method('getAvailableStrategies')
            ->willReturn([
                
$output = \Drupal::service('renderer')->renderRoot($output);

    $this->assertStringNotContainsString('custom text', $output, 'Empty handler was not rendered on a non empty table.');

    // Render an empty result, and ensure that the area handler is rendered.     $view->setDisplay('default');
    $view->executed = TRUE;
    $view->result = [];
    $output = $view->preview();
    $output = \Drupal::service('renderer')->renderRoot($output);

    $this->assertStringContainsString('custom text', $output, 'Empty handler got rendered on an empty table.');
  }

  /** * Prepares a view executable by initializing everything which is needed. * * @param \Drupal\views\ViewExecutable $view * The executable to prepare. */
  protected function prepareView(ViewExecutable $view) {
    $view->setDisplay();
    $view->initStyle();
    
// Ensure that invalidation works on both pages.     // Page 2.     $view->setCurrentPage(1);
    \Drupal::request()->query->set('page', 1);
    $entities[0]->name->value = $random_name = $this->randomMachineName();
    $entities[0]->save();
    $build = $this->assertViewsCacheTags($view$tags_page_2$do_assert_views_caches$tags_page_2);
    // @todo Static render arrays don't support different pages yet, see     // https://www.drupal.org/node/2500701.     // $this->assertViewsCacheTagsFromStaticRenderArray($view, $tags_page_2, $do_assert_views_caches);     $this->assertStringContainsString($random_name(string) $build['#markup']);
    $view->destroy();

    // Page 1.     $view->setCurrentPage(0);
    \Drupal::request()->query->set('page', 0);
    $entities[1]->name->value = $random_name = $this->randomMachineName();
    $entities[1]->save();
    $build = $this->assertViewsCacheTags($view$tags_page_1$do_assert_views_caches$tags_page_1);
    $this->assertViewsCacheTagsFromStaticRenderArray($view$tags_page_1$do_assert_views_caches);
    $this->assertStringContainsString($random_name(string) $build['#markup']);
    $view->destroy();

    
$view->field['name']->options['type'] = 'user_name';
    $view->field['name']->init($view$view->getDisplay('default'));
    $view->field['name']->options['id'] = 'name';
    $this->executeView($view);

    $anon_name = $this->config('user.settings')->get('anonymous');
    $view->result[0]->_entity->setUsername('');
    $view->result[0]->_entity->uid->value = 0;
    $render = $renderer->executeInRenderContext(new RenderContext()function D) use ($view) {
      return $view->field['name']->advancedRender($view->result[0]);
    });
    $this->assertStringContainsString($anon_name$render, 'For user 0 it should use the default anonymous name by default.');

    $render = $renderer->executeInRenderContext(new RenderContext()function D) use ($view$new_user) {
      return $view->field['name']->advancedRender($view->result[$new_user->id()]);
    });
    $this->assertStringContainsString($new_user->getDisplayName()$render, 'If link to user is checked the username should be part of the output.');
    $this->assertStringContainsString('user/' . $new_user->id()$render, 'If link to user is checked the link to the user should appear as well.');

    $view->field['name']->options['link_to_user'] = FALSE;
    $view->field['name']->options['type'] = 'string';
    $render = $renderer->executeInRenderContext(new RenderContext()function D) use ($view$new_user) {
      return $view->field['name']->advancedRender($view->result[$new_user->id()]);
    });
$view->header['test_example']->options['string'] = $header_string;
    $view->header['test_example']->options['empty'] = TRUE;

    $view->footer['test_example']->options['string'] = $footer_string;
    $view->footer['test_example']->options['empty'] = TRUE;

    $view->empty['test_example']->options['string'] = $empty_string;

    // Check whether the strings exist in the output and are sanitized.     $output = $view->preview();
    $output = $this->container->get('renderer')->renderRoot($output);
    $this->assertStringContainsString(Xss::filterAdmin($header_string)$output, 'Views header exists in the output and is sanitized');
    $this->assertStringContainsString(Xss::filterAdmin($footer_string)$output, 'Views footer exists in the output and is sanitized');
    $this->assertStringContainsString(Xss::filterAdmin($empty_string)$output, 'Views empty exists in the output and is sanitized');
    $this->assertStringNotContainsString('<script', $output, 'Script tags were escaped');
  }

  /** * Tests the access for an area. */
  public function testAreaAccess() {
    // Test with access denied for the area handler.     $view = Views::getView('test_example_area_access');
    
Home | Imprint | This part of the site doesn't use cookies.