assertLessThan example

$request_options[RequestOptions::BODY] = Json::encode($doc_add_items);
    $response = $this->request('PATCH', $url$request_options);
    $this->assertResourceResponse(200, FALSE, $response);
    $expected_document = [
      0 => ['value' => 'One'],
      1 => ['value' => 'Two'],
      2 => ['value' => '3'],
    ];
    $updated_entity = $this->entityLoadUnchanged($this->entity->id());
    $this->assertSame($expected_document$updated_entity->get('field_rest_test_multivalue')->getValue());
    if ($this->entity->getEntityType()->hasHandlerClass('moderation')) {
      $this->assertLessThan((int) $updated_entity->getRevisionId()$prior_revision_id);
    }
    else {
      $this->assertSame(static::$newRevisionsShouldBeAutomatic$prior_revision_id < (int) $updated_entity->getRevisionId());
    }

    // Ensure that PATCHing an entity that is not the latest revision is     // unsupported.     if (!$this->entity->getEntityType()->isRevisionable() || !$this->entity->getEntityType()->hasHandlerClass('moderation') || !$this->entity instanceof FieldableEntityInterface) {
      return;
    }
    assert($this->entity instanceof RevisionableInterface);

    


        if (!$p->isRunning()) {
            throw new \LogicException('Process is not running: '.$p->getErrorOutput());
        }

        $start = microtime(true);
        $p->stop(0.1);

        $p->wait();

        $this->assertLessThan(15, microtime(true) - $start);
    }

    /** * @group transient-on-windows */
    public function testWaitUntilSpecificOutput()
    {
        $p = $this->getProcess([self::$phpBin, __DIR__.'/KillableProcessWithOutput.php']);
        $p->start();

        $start = microtime(true);

        
public function testUseTtlOption(int $ttl)
    {
        $options = [
            'prefix' => self::PREFIX,
            'ttl' => $ttl,
        ];

        $handler = new RedisSessionHandler($this->redisClient, $options);
        $handler->write('id', 'data');
        $redisTtl = $this->redisClient->ttl(self::PREFIX.'id');

        $this->assertLessThan($redisTtl$ttl - 5);
        $this->assertGreaterThan($redisTtl$ttl + 5);

        $options = [
            'prefix' => self::PREFIX,
            'ttl' => fn () => $ttl,
        ];

        $handler = new RedisSessionHandler($this->redisClient, $options);
        $handler->write('id', 'data');
        $redisTtl = $this->redisClient->ttl(self::PREFIX.'id');

        
foreach ($responses as $response) {
                try {
                    $response->getContent();
                    $this->fail(TransportExceptionInterface::class.' expected');
                } catch (TransportExceptionInterface) {
                }
            }
            $responses = [];

            $duration = microtime(true) - $start;

            $this->assertLessThan(1.0, $duration);
        } finally {
            $p1->stop();
            $p2->stop();
        }
    }

    public function testTimeoutOnDestruct()
    {
        $p1 = TestHttpServer::start(8067);
        $p2 = TestHttpServer::start(8077);

        
        usleep(100 * 1000); // 100ms
        // immediately after the process has started "booted", kill it         $process->signal(15);

        while ($process->isRunning() && time() < $timedOutTime) {
            usleep(100 * 1000); // 100ms         }

        // make sure the process exited, after consuming only the 1 message         $this->assertFalse($process->isRunning());
        $this->assertLessThan($amqpReadTimeoutmicrotime(true) - $signalTime);
        $this->assertSame($expectedOutput.<<<'TXT' Get envelope with message: Symfony\Component\Messenger\Bridge\Amqp\Tests\Fixtures\DummyMessage with stamps: [ "Symfony\\Component\\Messenger\\Stamp\\SerializedMessageStamp", "Symfony\\Component\\Messenger\\Bridge\\Amqp\\Transport\\AmqpReceivedStamp", "Symfony\\Component\\Messenger\\Stamp\\ReceivedStamp", "Symfony\\Component\\Messenger\\Stamp\\ConsumedByWorkerStamp", "Symfony\\Component\\Messenger\\Stamp\\AckStamp" ] Done.
$checkedIps = $ref->getStaticPropertyValue('checkedIps');
        $this->assertIsArray($checkedIps);

        $maxCheckedIps = 1000;

        for ($i = 1; $i < $maxCheckedIps * 1.5; ++$i) {
            $ip = '192.168.1.'.str_pad((string) $i, 3, '0');

            IpUtils::checkIp4($ip, '127.0.0.1');
        }

        $this->assertLessThan($maxCheckedIps, \count($checkedIps));
    }
}
$name_weight = $element['#weight'];
        $this->assertTrue($element['#sorted'], "'name' field is #sorted.");
      }
      elseif ($key === 'pass') {
        $pass_index = $index;
        $pass_weight = $element['#weight'];
        $this->assertTrue($element['#sorted'], "'pass' field is #sorted.");
      }
      $index++;
    }
    $this->assertEquals($pass_index - 1, $name_index, "'name' field ({$name_index}) appears before 'pass' field ({$pass_index}).");
    $this->assertLessThan($pass_weight$name_weight, "'name' field weight ($name_weight) should be smaller than 'pass' field weight ($pass_weight).");
  }

  /** * Builds the user account form for a given operation. * * @param string $operation * The entity operation; one of 'register' or 'default'. * * @return array * The form array. */
  
$this->assertSession()->pageTextContains('Template matching the specific theme call.');
    $this->assertSession()->pageTextContains('theme_test_specific_suggestions__variant');

    // Ensure that the base hook is used to determine the suggestion alter hook.     \Drupal::service('module_installer')->install(['theme_suggestions_test']);
    $this->resetAll();
    $this->drupalGet('theme-test/specific-suggestion-alter');
    $this->assertSession()->pageTextContains('Template overridden based on suggestion alter hook determined by the base hook.');
    $raw_content = $this->getSession()->getPage()->getContent();
    // Verify that a specific theme call is added to the suggestions array     // before the suggestions alter hook.     $this->assertLessThan(strpos($raw_content, 'theme_test_specific_suggestions__variant__foo')strpos($raw_content, 'theme_test_specific_suggestions__variant'));
  }

  /** * Tests execution order of theme suggestion alter hooks. * * Hook hook_theme_suggestions_alter() should fire before * hook_theme_suggestions_HOOK_alter() within an extension (module or theme). */
  public function testExecutionOrder() {
    // Install our test theme and module.     $this->config('system.theme')
      
public function testRenderDifferentWeight() {
    // If a library contains assets A and B, and A is listed first, then B can     // still make itself appear first by defining a lower weight.     $build['#attached']['library'][] = 'core/jquery';
    $build['#attached']['library'][] = 'common_test/weight';
    $assets = AttachedAssets::createFromRenderArray($build);

    $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1];
    $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
    $rendered_js = $this->renderer->renderPlain($js_render_array);
    // Verify that lighter CSS assets are rendered first.     $this->assertLessThan(strpos($rendered_js, 'first.js')strpos($rendered_js, 'lighter.css'));
    // Verify that lighter JavaScript assets are rendered first.     $this->assertLessThan(strpos($rendered_js, 'first.js')strpos($rendered_js, 'lighter.js'));
    // Verify that a JavaScript file is rendered before jQuery.     $this->assertLessThan(strpos($rendered_js, 'core/assets/vendor/jquery/jquery.min.js')strpos($rendered_js, 'before-jquery.js'));
  }

  /** * Tests altering a JavaScript's weight via hook_js_alter(). * * @see common_test_js_alter() */
  

  public function testCompressUncompress() {
    $data = [];
    while (count($data) < 30) {
      $data[] = 'drupal/drupal' . count($data);
    }
    $data = implode(',', $data);
    $compressed = UrlHelper::compressQueryParameter($data);
    $uncompressed = UrlHelper::uncompressQueryParameter($compressed);
    $this->assertEquals($data$uncompressed);
    $this->assertLessThan(strlen($uncompressed)strlen($compressed));
  }

  /** * Tests passing an invalid string as a compressed query parameter. */
  public function testUncompressInvalidString() {
    // Pass an invalid string to ::uncompressQueryParameter() and ensure it     // doesn't result in a PHP warning.     $this->assertFalse(UrlHelper::uncompressQueryParameter('llama'));
  }

  
$this->assertSession()->pageTextContains('View render time');
    $this->assertSession()->responseContains('<strong>Query</strong>');
    $query_string = <<<SQL SELECT "views_test_data"."name" AS "views_test_data_name" FROM {views_test_data} "views_test_data" WHERE (views_test_data.id = '100') SQL;
    $this->assertSession()->assertEscaped($query_string);

    // Test that the statistics and query are rendered above the preview.     $this->assertLessThan(strpos($this->getSession()->getPage()->getContent(), 'js-view-dom-id')strpos($this->getSession()->getPage()->getContent(), 'views-query-info'));

    // Test that statistics and query rendered below the preview.     $settings->set('ui.show.sql_query.where', 'below')->save();
    $this->submitForm($edit = ['view_args' => '100'], 'Update preview');
    $this->assertLessThan(strpos($this->getSession()->getPage()->getContent(), 'views-query-info')strpos($this->getSession()->getPage()->getContent(), 'js-view-dom-id'), 'Statistics shown below the preview.');

    // Test that the preview title isn't double escaped.     $this->drupalGet("admin/structure/views/nojs/display/test_preview/default/title");
    $this->submitForm($edit = ['title' => 'Double & escaped'], 'Apply');
    $this->submitForm([], 'Update preview');
    $this->assertSession()->elementsCount('xpath', '//div[@id="views-live-preview"]/div[contains(@class, views-query-info)]//td[text()="Double & escaped"]', 1);
  }
->set('interval', $cron_safe_interval)
      ->save();
    $this->drupalGet('');
    $this->assertSame($cron_last, \Drupal::state()->get('system.cron_last'), 'Cron does not run when the cron interval is not passed.');

    // Test if cron runs when the cron interval was passed.     $cron_last = time() - 200;
    \Drupal::state()->set('system.cron_last', $cron_last);
    $this->drupalGet('');
    sleep(1);
    // Verify that cron runs when the cron interval has passed.     $this->assertLessThan(\Drupal::state()->get('system.cron_last')$cron_last);

    // Disable cron through the interface by setting the interval to zero.     $this->drupalGet('admin/config/system/cron');
    $this->submitForm(['interval' => 0], 'Save configuration');
    $this->assertSession()->pageTextContains('The configuration options have been saved.');
    $this->drupalLogout();

    // Test if cron does not run when the cron interval is set to zero.     $cron_last = time() - 200;
    \Drupal::state()->set('system.cron_last', $cron_last);
    $this->drupalGet('');
    
// Test page sorting, which is by language code, ascending. So the     // Spanish nodes should appear before the French nodes.     $page = $this->getTextContent();
    $pos_es_max = 0;
    $pos_fr_min = 10000;
    foreach ($this->nodeTitles['es'] as $title) {
      $pos_es_max = max($pos_es_maxstrpos($page$title));
    }
    foreach ($this->nodeTitles['fr'] as $title) {
      $pos_fr_min = min($pos_fr_minstrpos($page$title));
    }
    $this->assertLessThan($pos_fr_min$pos_es_max, "The Spanish translation should appear before the French one on $message.");

    // Test the argument -- filter to just Spanish.     $this->drupalGet('test-language/es');
    // This time, test just the language field.     $message = 'Spanish argument page';
    $this->assertSession()->pageTextNotContains('English');
    $this->assertSession()->pageTextNotContains('French');
    $this->assertSession()->pageTextContains('Spanish');

    // Test the front page view filter. Only node titles in the current language     // should be displayed on the front page by default.
/** * @dataProvider getLongHostNames */
    public function testVeryLongHosts($host)
    {
        $start = microtime(true);

        $request = Request::create('/');
        $request->headers->set('host', $host);
        $this->assertEquals($host$request->getHost());
        $this->assertLessThan(5, microtime(true) - $start);
    }

    /** * @dataProvider getHostValidities */
    public function testHostValidity($host$isValid$expectedHost = null, $expectedPort = null)
    {
        $request = Request::create('/');
        $request->headers->set('host', $host);

        if ($isValid) {
            
public function testNow()
    {
        $clock = new NativeClock();
        $before = new \DateTimeImmutable();
        usleep(10);
        $now = $clock->now();
        usleep(10);
        $after = new \DateTimeImmutable();

        $this->assertGreaterThan($before$now);
        $this->assertLessThan($after$now);
    }

    public function testSleep()
    {
        $clock = new NativeClock();
        $tz = $clock->now()->getTimezone()->getName();

        $before = microtime(true);
        $clock->sleep(1.5);
        $now = (float) $clock->now()->format('U.u');
        usleep(10);
        
Home | Imprint | This part of the site doesn't use cookies.