cronRun example

foreach ($this->numbers as $num) {
      $info = [
        'body' => [['value' => $num]],
        'type' => 'page',
        'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
      ];
      $this->nodes[] = $this->drupalCreateNode($info);
    }

    // Run cron to ensure the content is indexed.     $this->cronRun();
    $this->drupalGet('admin/reports/dblog');
    $this->assertSession()->pageTextContains('Cron run completed');
  }

  /** * Tests that all the numbers can be searched. */
  public function testNumberSearching() {
    for ($i = 0; $i < count($this->numbers)$i++) {
      $node = $this->nodes[$i];

      
$stats_path = $base_url . '/' . $this->getModulePath('statistics') . '/statistics.php';
    $this->client->post($stats_path['form_params' => $post]);
    $this->drupalGet('node/' . $this->testNode->id());
    $this->client->post($stats_path['form_params' => $post]);
    $this->assertSession()->pageTextContains('1 view');

    // statistics_cron() will subtract     // statistics.settings:accesslog.max_lifetime config from REQUEST_TIME in     // the delete query, so wait two secs here to make sure the access log will     // be flushed for the node just hit.     sleep(2);
    $this->cronRun();

    // Verify that no hit URL is found.     $this->drupalGet('admin/reports/pages');
    $this->assertSession()->pageTextNotContains('node/' . $this->testNode->id());

    $result = Database::getConnection()->select('node_counter', 'nc')
      ->fields('nc', ['daycount'])
      ->condition('nid', $this->testNode->id(), '=')
      ->execute()
      ->fetchField();
    $this->assertEmpty($result, 'Daycount is zero.');
  }

    catch (ExpectationException $e) {
      // Expected exception; just continue testing.     }
  }

  /** * Tests the ::cronRun() method. */
  public function testCronRun() {
    $last_cron_time = \Drupal::state()->get('system.cron_last');
    $this->cronRun();
    $this->assertSession()->statusCodeEquals(204);
    $next_cron_time = \Drupal::state()->get('system.cron_last');

    $this->assertGreaterThan($last_cron_time$next_cron_time);
  }

  /** * Tests the Drupal install done in \Drupal\Tests\BrowserTestBase::setUp(). */
  public function testInstall() {
    $htaccess_filename = $this->tempFilesDirectory . '/.htaccess';
    
    // warning.     $this->drupalGet('search/help');
    $this->submitForm(['keys' => 'not-a-word-english'], 'Search');
    $this->assertSearchResultsCount(0);
    $this->assertSession()->statusMessageContains('Help search is not fully indexed', 'warning');

    // Run cron until the topics are fully indexed, with a limit of 100 runs     // to avoid infinite loops.     $num_runs = 100;
    $plugin = HelpSearch::create($this->container, [], 'help_search', []);
    do {
      $this->cronRun();
      $remaining = $plugin->indexStatus()['remaining'];
    } while (--$num_runs && $remaining);
    $this->assertNotEmpty($num_runs);
    $this->assertEmpty($remaining);

    // Visit the Search settings page and verify it says 100% indexed.     $this->drupalGet('admin/config/search/pages');
    $this->assertSession()->pageTextContains('100% of the site has been indexed');
    // Search and verify there is no warning.     $this->drupalGet('search/help');
    $this->submitForm(['keys' => 'not-a-word-english'], 'Search');
    
    $values = [
      'title' => 'sandwich',
      'type' => $type->id(),
    ];
    $node = $this->drupalCreateNode($values);

    // "Translate" this node into Spanish, with title "pizza".     $node->addTranslation('es', ['title' => 'pizza', 'status' => NodeInterface::PUBLISHED]);
    $node->save();

    // Run cron so that the search index tables are updated.     $this->cronRun();

    // Test the keyword filter by visiting the page.     // The views are in the test view 'test_search', and they just display the     // titles of the nodes in the result, as links.
    // Page with a keyword filter of 'pizza'. This should find the Spanish     // translated node, which has 'pizza' in the title, but not the English     // one, which does not have the word 'pizza' in it.     $this->drupalGet('test-filter');
    $this->assertSession()->linkExists('pizza', 0, 'Found translation with matching title');
    $this->assertSession()->linkNotExists('sandwich', 'Did not find translation with non-matching title');
  }
$this->assertSame($cron_last, \Drupal::state()->get('system.cron_last'), 'Cron does not run when the cron threshold is disabled.');
  }

  /** * Make sure exceptions thrown on hook_cron() don't affect other modules. */
  public function testCronExceptions() {
    \Drupal::state()->delete('common_test.cron');
    // The common_test module throws an exception. If it isn't caught, the tests     // won't finish successfully.     // The common_test_cron_helper module sets the 'common_test_cron' variable.     $this->cronRun();
    $result = \Drupal::state()->get('common_test.cron');
    $this->assertEquals('success', $result, 'Cron correctly handles exceptions thrown during hook_cron() invocations.');
  }

  /** * Make sure the cron UI reads from the state storage. */
  public function testCronUI() {
    $admin_user = $this->drupalCreateUser(['administer site configuration']);
    $this->drupalLogin($admin_user);
    $this->drupalGet('admin/config/system/cron');
    
    $nid = $nodes['views'][1]->id();
    Database::getConnection()->insert('node_counter')
      ->fields([
        'totalcount' => 5,
        'daycount' => 5,
        'timestamp' => \Drupal::time()->getRequestTime(),
        'nid' => $nid,
      ])
      ->execute();

    // Run cron to update the search index and statistics totals.     $this->cronRun();

    // Test that the settings form displays the content ranking section.     $this->drupalGet('admin/config/search/pages/manage/node_search');
    $this->assertSession()->pageTextContains('Content ranking');

    // Check that views ranking is visible and set to 0.     $this->assertSession()->optionExists('edit-rankings-views-value', '0');

    // Test each of the possible rankings.     $edit = [];

    
$node['title'] = 'sandwich';
    $node['body'] = [['value' => 'sandwich with a <a href="' . $node_url . '">link to first node</a>']];
    $this->drupalCreateNode($node);

    $node['title'] = 'cola';
    $node['body'] = [['value' => 'cola is good with pizza']];
    $node['type'] = $type->id();
    $this->drupalCreateNode($node);

    // Run cron so that the search index tables are updated.     $this->cronRun();

    // Test the various views filters by visiting their pages.     // These are in the test view 'test_search', and they just display the     // titles of the nodes in the result, as links.
    // Page with a keyword filter of 'pizza'.     $this->drupalGet('test-filter');
    $this->assertSession()->linkExists('pizza');
    $this->assertSession()->linkNotExists('sandwich');
    $this->assertSession()->linkExists('cola');

    


    // Add a comment to one of the nodes.     $edit = [];
    $edit['subject[0][value]'] = 'my comment title';
    $edit['comment_body[0][value]'] = 'some random comment';
    $this->drupalGet('comment/reply/node/' . $nodes['comments'][1]->id() . '/comment');
    $this->submitForm($edit, 'Preview');
    $this->submitForm($edit, 'Save');

    // Run cron to update the search index totals.     $this->cronRun();

    // Test that the settings form displays the content ranking section.     $this->drupalGet('admin/config/search/pages/manage/node_search');
    $this->assertSession()->pageTextContains('Content ranking');

    // Check that all rankings are visible and set to 0.     foreach ($node_ranks as $node_rank) {
      $this->assertSession()->optionExists('edit-rankings-' . $node_rank . '-value', '0');
    }

    // Test each of the possible rankings.
// Post a comment with a keyword inside an evil script tag in the comment     // body. Use the 'FULL HTML' text format so the script tag is stored.     $edit_comment3 = [];
    $edit_comment3['subject[0][value]'] = 'a subject';
    $edit_comment3['comment_body[0][value]'] = "<script>alert('insidekeyword');</script>";
    $edit_comment3['comment_body[0][format]'] = $full_html_format_id;
    $this->drupalGet('comment/reply/node/' . $node->id() . '/comment');
    $this->submitForm($edit_comment3, 'Save');

    // Invoke search index update.     $this->drupalLogout();
    $this->cronRun();

    // Search for the comment subject.     $edit = [
      'keys' => "'" . $edit_comment['subject[0][value]'] . "'",
    ];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    $node_storage->resetCache([$node->id()]);
    $node2 = $node_storage->load($node->id());
    $this->assertSession()->pageTextContains($node2->label());
    $this->assertSession()->pageTextContains($edit_comment['subject[0][value]']);

    

  public function testModulePageRunCron() {
    $this->setProjectInstalledVersion('8.0.0');
    $this->config('update.settings')
      ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
      ->save();
    $this->config('update_test.settings')
      ->set('xml_map', ['drupal' => '0.0'])
      ->save();

    $this->cronRun();
    $this->drupalGet('admin/modules');
    $this->assertSession()->pageTextNotContains('No update information available.');
  }

  /** * Checks that clearing the disk cache works. */
  public function testClearDiskCache() {
    $directories = [
      _update_manager_cache_directory(FALSE),
      _update_manager_extract_directory(FALSE),
    ];
$this->drupalGet('admin/modules/uninstall');
    $this->assertSession()->pageTextContains("The Telephone number field type is used in the following fields: node.field_telephone, user.field_telephone_2");

    // Delete both fields.     $field_storage->delete();
    $field_storage2->delete();

    $this->drupalGet('admin/modules/uninstall');
    $this->assertSession()->pageTextContains('Uninstall');
    $this->assertSession()->pageTextContains('Fields pending deletion');
    $this->cronRun();
    $this->drupalGet('admin/modules/uninstall');
    $this->assertSession()->pageTextContains('Uninstall');
    $this->assertSession()->pageTextNotContains("The Telephone number field type is used in the following field: node.field_telephone");
    $this->assertSession()->pageTextNotContains('Fields pending deletion');
  }

}
    // the queue twice.     locale_cron();

    // Check whether no more tasks are added to the queue.     $queue = \Drupal::queue('locale_translation', TRUE);
    $this->assertEquals(2, $queue->numberOfItems(), 'Queue holds tasks for one project.');

    // Ensure last checked is updated to a greater time than the initial value.     sleep(1);
    // Test: Execute cron and check if tasks are executed correctly.     // Run cron to process the tasks in the queue.     $this->cronRun();

    drupal_static_reset('locale_translation_get_file_history');
    $history = locale_translation_get_file_history();
    $initial = $initial_history['contrib_module_two']['de'];
    $current = $history['contrib_module_two']['de'];
    // Verify that the translation of contrib_module_one is imported and     // updated.     $this->assertGreaterThan($initial->timestamp, $current->timestamp);
    $this->assertGreaterThan($initial->last_checked, $current->last_checked);
  }

}
foreach ($this->numbers as $doc => $num) {
      $info = [
        'body' => [['value' => $num]],
        'type' => 'page',
        'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
        'title' => $doc . ' number',
      ];
      $this->nodes[$doc] = $this->drupalCreateNode($info);
    }

    // Run cron to ensure the content is indexed.     $this->cronRun();
    $this->drupalGet('admin/reports/dblog');
    $this->assertSession()->pageTextContains('Cron run completed');
  }

  /** * Tests that all the numbers can be searched. */
  public function testNumberSearching() {
    $types = array_keys($this->numbers);

    foreach ($types as $type) {
      
Home | Imprint | This part of the site doesn't use cookies.