/** * Tests various different configurations of the 'text_format' element. */ public function testFilterForm() { $this->doFilterFormTestAsAdmin(); $this->doFilterFormTestAsNonAdmin(); // Ensure that enabling modules which provide filter plugins behaves // correctly. // @see https://www.drupal.org/node/2387983 \Drupal::service('module_installer')->install(['filter_test_plugin']); // Force rebuild module data. _system_rebuild_module_data(); }
/** * Tests the book_system_info_alter() method. */ public function testBookUninstall() { // No nodes exist. $module_data = _system_rebuild_module_data(); $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.'); $content_type = NodeType::create(array('type' => $this->randomMachineName(), 'name' => $this->randomString())); $content_type->save(); $book_config = $this->config('book.settings'); $allowed_types = $book_config->get('allowed_types'); $allowed_types[] = $content_type->id(); $book_config->set('allowed_types', $allowed_types)->save(); $node = Node::create(array('type' => $content_type->id())); $node->book['bid'] = 'new'; $node->save(); // One node in a book but not of type book. $module_data = _system_rebuild_module_data(); $this->assertTrue($module_data['book']->info['required'], 'The book module is required.'); $this->assertEqual($module_data['book']->info['explanation'], t('To uninstall Book, delete all content that is part of a book.')); $book_node = Node::create(array('type' => 'book')); $book_node->book['bid'] = FALSE; $book_node->save(); // Two nodes, one in a book but not of type book and one book node (which is // not in a book). $module_data = _system_rebuild_module_data(); $this->assertTrue($module_data['book']->info['required'], 'The book module is required.'); $this->assertEqual($module_data['book']->info['explanation'], t('To uninstall Book, delete all content that is part of a book.')); $node->delete(); // One node of type book but not actually part of a book. $module_data = _system_rebuild_module_data(); $this->assertTrue($module_data['book']->info['required'], 'The book module is required.'); $this->assertEqual($module_data['book']->info['explanation'], t('To uninstall Book, delete all content that has the Book content type.')); $book_node->delete(); // No nodes exist therefore the book module is not required. $module_data = _system_rebuild_module_data(); $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.'); $node = Node::create(array('type' => $content_type->id())); $node->save(); // One node exists but is not part of a book therefore the book module is // not required. $module_data = _system_rebuild_module_data(); $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.'); // Uninstall the Book module and check the node type is deleted. \Drupal::service('module_installer')->uninstall(array('book')); $this->assertNull(NodeType::load('book'), "The book node type does not exist."); }
/** * Tests that filter format dependency removal works. * * Ensure that modules providing filter plugins are required when the plugin * is in use, and that only disabled plugins are removed from format * configuration entities rather than the configuration entities being * deleted. * * @see \Drupal\filter\Entity\FilterFormat::onDependencyRemoval() * @see filter_system_info_alter() */ public function testDependencyRemoval() { $this->installSchema('user', array('users_data')); $filter_format = \Drupal\filter\Entity\FilterFormat::load('filtered_html'); // Disable the filter_test_restrict_tags_and_attributes filter plugin but // have custom configuration so that the filter plugin is still configured // in filtered_html the filter format. $filter_config = ['weight' => 20, 'status' => 0]; $filter_format->setFilterConfig('filter_test_restrict_tags_and_attributes', $filter_config)->save(); // Use the get method to match the assert after the module has been // uninstalled. $filters = $filter_format->get('filters'); $this->assertTrue(isset($filters['filter_test_restrict_tags_and_attributes']), 'The filter plugin filter_test_restrict_tags_and_attributes is configured by the filtered_html filter format.'); drupal_static_reset('filter_formats'); \Drupal::entityManager()->getStorage('filter_format')->resetCache(); $module_data = _system_rebuild_module_data(); $this->assertFalse(isset($module_data['filter_test']->info['required']), 'The filter_test module is required.'); // Verify that a dependency exists on the module that provides the filter // plugin since it has configuration for the disabled plugin. $this->assertEqual(['module' => ['filter_test']], $filter_format->getDependencies()); // Uninstall the module. \Drupal::service('module_installer')->uninstall(array('filter_test')); // Verify the filter format still exists but the dependency and filter is // gone. \Drupal::entityManager()->getStorage('filter_format')->resetCache(); $filter_format = \Drupal\filter\Entity\FilterFormat::load('filtered_html'); $this->assertEqual([], $filter_format->getDependencies()); // Use the get method since the FilterFormat::filters() method only returns // existing plugins. $filters = $filter_format->get('filters'); $this->assertFalse(isset($filters['filter_test_restrict_tags_and_attributes']), 'The filter plugin filter_test_restrict_tags_and_attributes is not configured by the filtered_html filter format.'); }
Run a function in the background. Notice that there is no return. <?php // Call watchdog('httprl-test', 'background watchdog call done'); // in the background/async. httprl_call_user_func_array_async('watchdog', array('httprl-test', 'background watchdog call done 2')); ?> Pass by reference example. Example is D7 only; pass by reference works in D6 & D7. <?php // Code from system_rebuild_module_data(). $modules = _system_rebuild_module_data(); ksort($modules); // Show first module before running system_get_files_database(). echo httprl_pr(current($modules)); // Bail out here if background callbacks are disabled. if (!httprl_is_background_callback_capable()) { return FALSE; } $callback_options = array(array('function' => 'system_get_files_database', 'return' => ''), &$modules, 'module'); httprl_queue_background_callback($callback_options); // Execute requests. httprl_send_request(); // Show first module after running system_get_files_database(). echo httprl_pr(current($modules)); ?>