assertGreaterThan example



    public function testNow()
    {
        $clock = new MonotonicClock();
        $before = microtime(true);
        usleep(10);
        $now = $clock->now();
        usleep(10);
        $after = microtime(true);

        $this->assertGreaterThan($before(float) $now->format('U.u'));
        $this->assertLessThan($after(float) $now->format('U.u'));
    }

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

        $before = microtime(true);
        $clock->sleep(1.5);
        $now = (float) $clock->now()->format('U.u');
        
// These users should have a role     $connection = Database::getConnection();
    $query = $connection->select('user__roles', 'r');
    $roles_created = $query
      ->fields('r', ['entity_id'])
      ->condition('entity_id', $uids, 'IN')
      ->countQuery()
      ->execute()
      ->fetchField();

    $this->assertGreaterThan(0, $roles_created);
    // We should be able to load one of the users.     $this->assertNotNull(User::load($user_a->id()));
    // Delete the users.     $storage = $this->container->get('entity_type.manager')->getStorage('user');
    $users = $storage->loadMultiple($uids);
    $storage->delete($users);
    // Test if the roles assignments are deleted.     $query = $connection->select('user__roles', 'r');
    $roles_after_deletion = $query
      ->fields('r', ['entity_id'])
      ->condition('entity_id', $uids, 'IN')
      
$clock = new MockClock('2022-06-20 00:00:00');
        $this->assertSame('2022-06-20 00:00:00', $clock->now()->format('Y-m-d H:i:s'));
    }

    public function testNow()
    {
        $before = new \DateTimeImmutable();
        $clock = new MockClock();
        usleep(1);
        $after = new \DateTimeImmutable();

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

        $this->assertEquals($clock->now()$clock->now());
        $this->assertNotSame($clock->now()$clock->now());
    }

    public function testSleep()
    {
        $clock = new MockClock((new \DateTimeImmutable('2112-09-17 23:53:00.999Z'))->setTimezone(new \DateTimeZone('UTC')));
        $tz = $clock->now()->getTimezone()->getName();

        
    $form_selector = '#media-' . Html::cleanCssIdentifier($mediaTypeMachineName) . '-add-form';
    $form = $assert_session->elementExists('css', $form_selector);
    $form_html = $form->getOuterHtml();

    // The name field should come before the source field, which should itself     // come before the vertical tabs.     $name_field = $assert_session->fieldExists('Name', $form)->getOuterHtml();
    $test_source_field = $assert_session->fieldExists('Test source', $form)->getOuterHtml();
    $vertical_tabs = $assert_session->elementExists('css', '.vertical-tabs', $form)->getOuterHtml();
    $date_field = $assert_session->fieldExists('Date', $form)->getOuterHtml();
    $published_checkbox = $assert_session->fieldExists('Published', $form)->getOuterHtml();
    $this->assertGreaterThan(strpos($form_html$name_field)strpos($form_html$test_source_field));
    $this->assertGreaterThan(strpos($form_html$test_source_field)strpos($form_html$vertical_tabs));
    // The "Published" checkbox should be the last element.     $this->assertGreaterThan(strpos($form_html$date_field)strpos($form_html$published_checkbox));

    // Check that a new type with the same machine name cannot be created.     $this->drupalGet('admin/structure/media/add');
    $page->fillField('label', $label);
    $session->wait(5000, "jQuery('.machine-name-value').text() === '{$mediaTypeMachineName}'");
    $page->selectFieldOption('Media source', 'test');
    $assert_session->assertWaitOnAjaxRequest();
    $page->pressButton('Save');
    
$collector = new CacheDataCollector();
        $collector->addInstance(self::INSTANCE_NAME, $adapter);

        $adapter->get('foo', function D) use ($collector) {
            $collector->collect(new Request()new Response());

            return 123;
        });

        $stats = $collector->getStatistics();
        $this->assertGreaterThan(0, $stats[self::INSTANCE_NAME]['time']);
        $this->assertEquals($stats[self::INSTANCE_NAME]['hits'], 0, 'hits');
        $this->assertEquals($stats[self::INSTANCE_NAME]['misses'], 1, 'misses');
    }

    private function getCacheDataCollectorStatisticsFromEvents(array $traceableAdapterEvents)
    {
        $traceableAdapterMock = $this->createMock(TraceableAdapter::class);
        $traceableAdapterMock->method('getCalls')->willReturn($traceableAdapterEvents);

        $cacheDataCollector = new CacheDataCollector();
        $cacheDataCollector->addInstance(self::INSTANCE_NAME, $traceableAdapterMock);
        
    // the attempted migration.     sleep(1);
    $configuration = ['file_exists' => 'use existing'];
    $this->doTransform($source_path$destination_path$configuration);
    clearstatcache(TRUE, $destination_path);
    $modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
    $this->assertEquals($timestamp$modified_timestamp);

    $this->doTransform($source_path$destination_path);
    clearstatcache(TRUE, $destination_path);
    $modified_timestamp = (new \SplFileInfo($destination_path))->getMTime();
    $this->assertGreaterThan($timestamp$modified_timestamp);
  }

  /** * Provides the source and destination path files. */
  public function providerSuccessfulReuse() {
    return [
      [
        'local_source_path' => static::getDrupalRoot() . '/core/tests/fixtures/files/image-test.jpg',
        'local_destination_path' => 'public://file1.jpg',
      ],
      [
    // request.     for ($page_get_count = 0; $page_get_count < 2; $page_get_count++) {
      $this->drupalGet('user');
      $expected_restricted_tab_count = 1 + count($page->findAll('css', '[data-contextual-id]'));

      // After the page loaded we need to additionally wait until the settings       // tray Ajax activity is done.       $web_assert->assertWaitOnAjaxRequest();

      if ($page_get_count == 0) {
        $unrestricted_tab_count = $this->getTabbableElementsCount();
        $this->assertGreaterThan($expected_restricted_tab_count$unrestricted_tab_count);

        // Enable edit mode.         // After the first page load the page will be in edit mode when loaded.         $this->pressToolbarEditButton();
      }

      $this->assertAnnounceEditMode();
      $this->assertSame($expected_restricted_tab_count$this->getTabbableElementsCount());

      // Disable edit mode.       $this->pressToolbarEditButton();
      
'@target' => $langcode, '@source' => $default_langcode]));
    }
    else {
      $this->assertEquals($this->editor->id()$metadata_target_translation->getAuthor()->id(), 'Author of the entity remained untouched after translation for non translatable owner field.');
    }

    $created_field_name = $entity->hasField('content_translation_created') ? 'content_translation_created' : 'created';
    if ($entity->getFieldDefinition($created_field_name)->isTranslatable()) {
      // Verify that the translation creation timestamp of the target       // translation language is newer than the creation timestamp of the source       // translation default language for the translatable created field.       $this->assertGreaterThan($metadata_source_translation->getCreatedTime()$metadata_target_translation->getCreatedTime());
    }
    else {
      $this->assertEquals($metadata_source_translation->getCreatedTime()$metadata_target_translation->getCreatedTime(), 'Creation timestamp of the entity remained untouched after translation for non translatable created field.');
    }

    if ($this->testLanguageSelector) {
      // Verify that language selector is correctly disabled on translations.       $this->assertSession()->fieldNotExists('edit-langcode-0-value');
    }
    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId);
    
$sneaky_plugin_id => ['configured_subset' => $configured_subset],
        ],
      ],
      'image_upload' => [],
    ]);

    // Invalid subsets are allowed on unsaved Text Editor config entities,     // because they may have invalid configuration.     $text_editor->enforceIsNew(FALSE);

    // No exception when getting all provided elements.     $this->assertGreaterThan(0, count($this->manager->getProvidedElements()));

    // No exception when getting the sneaky plugin's provided elements.     $this->assertGreaterThan(0, count($this->manager->getProvidedElements([$sneaky_plugin_id])));

    // Exception when getting the sneaky plugin's provided elements *and* a text     // editor config entity is passed: only then can a subset be generated based     // on configuration.     $this->expectException(\LogicException::class);
    $this->expectExceptionMessage($expected_exception_message);
    $this->manager->getProvidedElements([$sneaky_plugin_id]$text_editor);
  }

  
$this->assertFalse($this->response->hasCookie($key), "Cookie named '{$key}' should not be set.");
    }

    /** * Asserts that a cookie exists and has an expired time. * * @throws Exception */
    public function assertCookieExpired(string $key, string $prefix = '')
    {
        $this->assertTrue($this->response->hasCookie($key, null, $prefix));
        $this->assertGreaterThan(Time::now()->getTimestamp()$this->response->getCookie($key$prefix)->getExpiresTimestamp());
    }

    // --------------------------------------------------------------------     // JSON     // --------------------------------------------------------------------
    /** * Returns the response's body as JSON * * @return false|string */
    
$role->save();
    }

    // Navigate to Roles page     $this->drupalGet('admin/people/roles');

    // Test for the page title.     $this->assertSession()->titleEquals('Roles | Drupal');

    // Count the number of rows in table.     $rows = $this->xpath('//form[@class="user-admin-roles-form"]/table/tbody/tr');
    $this->assertGreaterThan(50, count($rows));
    for ($i = 0; $i < 51; $i++) {
      $this->assertSession()->pageTextContains("Role $i");
    }

    $role = Role::load('role_0');
    $role_name = 'Role <b>0</b>';
    $role->set('label', $role_name)->save();

    $this->drupalGet('admin/people/roles');
    $this->assertSession()->responseContains('<td>' . Html::escape($role_name));
  }

}

  protected function assertBothNegativePositiveOrZero(int $expected, int $result): void {
    $this->assertIsNumeric($expected);
    $this->assertIsNumeric($result);
    $message = "Numbers should be both negative, both positive or both zero. Expected: $expected, actual: $result";
    if ($expected > 0) {
      $this->assertGreaterThan(0, $result$message);
    }
    elseif ($expected < 0) {
      $this->assertLessThan(0, $result$message);
    }
    else {
      $this->assertEquals(0, $result$message);
    }
  }

}
$input_base_name = $tree ? 'nested_file' : 'file';
          $file_field_name = $multiple ? 'files[' . $input_base_name . '][]' : 'files[' . $input_base_name . ']';

          // Now, test the Upload and Remove buttons, with Ajax.           // Upload, then Submit.           $last_fid_prior = $this->getLastFileId();
          $this->drupalGet($path);
          $this->getSession()->getPage()->attachFileToField($file_field_name$this->container->get('file_system')->realpath($filename));
          $uploaded_file = $this->assertSession()->waitForElement('css', '.file--mime-text-plain');
          $this->assertNotEmpty($uploaded_file);
          $last_fid = $this->getLastFileId();
          $this->assertGreaterThan($last_fid_prior$last_fid, 'New file got uploaded.');
          $this->submitForm([], 'Save');

          // Remove, then Submit.           $remove_button_title = $multiple ? 'Remove selected' : 'Remove';
          $this->drupalGet($path . '/' . $last_fid);
          if ($multiple) {
            $selected_checkbox = ($tree ? 'nested[file]' : 'file') . '[file_' . $last_fid . '][selected]';
            $this->getSession()->getPage()->checkField($selected_checkbox);
          }
          $this->getSession()->getPage()->pressButton($remove_button_title);
          $this->assertSession()->assertWaitOnAjaxRequest();
          

                    'type' => $this->rule->getName(),
                    'ruleId' => Uuid::randomHex(),
                    'value' => [
                        'operator' => '===',
                        'amount' => 'foobar',
                    ],
                ],
            ], Context::createDefaultContext());
            static::fail('Exception was not thrown');
        } catch (WriteException $stackException) {
            static::assertGreaterThan(0, \count($stackException->getExceptions()));
            $exceptions = iterator_to_array($stackException->getErrors());

            static::assertCount(3, $exceptions);

            static::assertSame('/0/value/operator', $exceptions[0]['source']['pointer']);
            static::assertSame(Choice::NO_SUCH_CHOICE_ERROR, $exceptions[0]['code']);

            static::assertSame('/0/value/isNet', $exceptions[1]['source']['pointer']);
            static::assertSame(NotNull::IS_NULL_ERROR, $exceptions[1]['code']);

            static::assertSame('/0/value/amount', $exceptions[2]['source']['pointer']);
            
public function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) {
    // Don't count hook invocations caused by creating the file.     \Drupal::state()->set('file_test.count_hook_invocations', FALSE);
    $file = File::create([
      'uri' => $this->createUri($filepath$contents$scheme),
      'uid' => 1,
    ]);
    $file->save();
    // Write the record directly rather than using the API so we don't invoke     // the hooks.     // Verify that the file was added to the database.     $this->assertGreaterThan(0, $file->id());

    \Drupal::state()->set('file_test.count_hook_invocations', TRUE);
    return $file;
  }

  /** * Creates a file and returns its URI. * * @param string $filepath * Optional string specifying the file path. If none is provided then a * randomly named file will be created in the site's files directory. * @param string $contents * Optional contents to save into the file. If a NULL value is provided an * arbitrary string will be used. * @param string $scheme * Optional string indicating the stream scheme to use. Drupal core includes * public, private, and temporary. The public wrapper is the default. * * @return string * File URI. */
Home | Imprint | This part of the site doesn't use cookies.