/**
  * Test enumeration of anonymous and authenticated keys.
  */
 public function testKeyEnumKeys()
 {
     global $base_root;
     variable_set('authcache_roles', array());
     $expect = array($base_root);
     $result = authcache_enum_keys();
     $this->assertEqual($expect, $result);
     drupal_static_reset();
     // Test anonymous and authenticated roles.
     variable_set('authcache_roles', array(DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID));
     $result = authcache_enum_keys();
     $anonymous_key = array_pop($result);
     $this->assertEqual($base_root, $anonymous_key);
     // Expect 1 additional key for authenticated users.
     $this->assertEqual(1, count($result));
     drupal_static_reset();
     // Test additional roles.
     $rid1 = $this->drupalCreateRole(array());
     $rid2 = $this->drupalCreateRole(array());
     variable_set('authcache_roles', array(DRUPAL_ANONYMOUS_RID => DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID => DRUPAL_AUTHENTICATED_RID, $rid1 => $rid1, $rid2 => $rid2));
     $result = authcache_enum_keys();
     $anonymous_key = array_pop($result);
     $this->assertEqual($base_root, $anonymous_key);
     // Expect 4 keys for authenticated users:
     // * Only authenticated rid
     // * Only rid1
     // * Only rid2
     // * rid1 and rid2
     $this->assertEqual(4, count($result));
 }
コード例 #2
0
ファイル: PODContext.php プロジェクト: nucivic/dkanextension
 /**
  * @Then I should see a valid catalog xml
  */
 public function iShouldSeeAValidCatalogXml()
 {
     // Change /catalog.xml path to /catalog during tests. The '.' on the filename breaks tests on CircleCI's server.
     $dcat = open_data_schema_map_api_load('dcat_v1_1');
     if ($dcat->endpoint !== 'catalog') {
         $dcat->endpoint = 'catalog';
         drupal_write_record('open_data_schema_map', $dcat, 'id');
         drupal_static_reset('open_data_schema_map_api_load_all');
         menu_rebuild();
     }
     // Change /catalog.json path to /catalogjson during tests. The '.' on the filename breaks tests on CircleCI's server.
     $dcat_json = open_data_schema_map_api_load('dcat_v1_1_json');
     if ($dcat_json->endpoint !== 'catalogjson') {
         $dcat_json->endpoint = 'catalogjson';
         drupal_write_record('open_data_schema_map', $dcat_json, 'id');
         drupal_static_reset('open_data_schema_map_api_load_all');
         menu_rebuild();
     }
     // Get base URL.
     $url = $this->getMinkParameter('base_url') ? $this->getMinkParameter('base_url') : "http://127.0.0.1::8888";
     $url_xml = $url . '/catalog';
     $url_json = $url . '/catalogjson';
     $this->visitPath($url_xml);
     $this->assertSession()->statusCodeEquals('200');
     // Validate DCAT.
     $results = open_data_schema_dcat_process_validate($url_json, TRUE);
     if ($results['errors']) {
         throw new \Exception(sprintf('catalog.xml is not valid.'));
     }
 }
コード例 #3
0
 private function downloadModules(DrupalStyle $io, $modules, $latest, $path = null, $resultList = [])
 {
     if (!$resultList) {
         $resultList = ['invalid' => [], 'uninstalled' => [], 'dependencies' => []];
     }
     drupal_static_reset('system_rebuild_module_data');
     $validator = $this->getApplication()->getValidator();
     $missingModules = $validator->getMissingModules($modules);
     $invalidModules = [];
     if ($missingModules) {
         $io->info(sprintf($this->trans('commands.module.install.messages.getting-missing-modules'), implode(', ', $missingModules)));
         foreach ($missingModules as $missingModule) {
             $version = $this->releasesQuestion($io, $missingModule, $latest);
             if ($version) {
                 $this->downloadProject($io, $missingModule, $version, 'module', $path);
             } else {
                 $invalidModules[] = $missingModule;
                 unset($modules[array_search($missingModule, $modules)]);
             }
             $this->getApplication()->getSite()->discoverModules();
         }
     }
     $unInstalledModules = $validator->getUninstalledModules($modules);
     $dependencies = $this->calculateDependencies($unInstalledModules);
     $resultList = ['invalid' => array_unique(array_merge($resultList['invalid'], $invalidModules)), 'uninstalled' => array_unique(array_merge($resultList['uninstalled'], $unInstalledModules)), 'dependencies' => array_unique(array_merge($resultList['dependencies'], $dependencies))];
     if (!$dependencies) {
         return $resultList;
     }
     return $this->downloadModules($io, $dependencies, $latest, $path, $resultList);
 }
 protected function setUp()
 {
     parent::setUp();
     // Set up an additional language.
     $this->langcodes = array(language_default()->getId(), 'es');
     ConfigurableLanguage::createFromLangcode('es')->save();
     // Create a content type.
     $this->bundle = $this->randomMachineName();
     $this->contentType = $this->drupalCreateContentType(array('type' => $this->bundle));
     // Enable translation for the current entity type and ensure the change is
     // picked up.
     content_translation_set_config('node', $this->bundle, 'enabled', TRUE);
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedBundles();
     \Drupal::service('router.builder')->rebuild();
     // Add a translatable field to the content type.
     entity_create('field_storage_config', array('field_name' => 'field_test_text', 'entity_type' => 'node', 'type' => 'text', 'cardinality' => 1, 'translatable' => TRUE))->save();
     entity_create('field_config', array('entity_type' => 'node', 'field_name' => 'field_test_text', 'bundle' => $this->bundle, 'label' => 'Test text-field'))->save();
     entity_get_form_display('node', $this->bundle, 'default')->setComponent('field_test_text', array('type' => 'text_textfield', 'weight' => 0))->save();
     // Enable content translation.
     $configuration = array('langcode' => language_default()->getId(), 'language_show' => TRUE);
     language_save_default_configuration('node', $this->bundle, $configuration);
     // Create a translator user.
     $permissions = array('access contextual links', 'administer nodes', "edit any {$this->bundle} content", 'translate any entity');
     $this->translator = $this->drupalCreateUser($permissions);
 }
コード例 #5
0
 /**
  * Tests locale_get_plural() and format_plural() functionality.
  */
 public function testGetPluralFormat()
 {
     // Import some .po files with formulas to set up the environment.
     // These will also add the languages to the system.
     $this->importPoFile($this->getPoFileWithSimplePlural(), array('langcode' => 'fr'));
     $this->importPoFile($this->getPoFileWithComplexPlural(), array('langcode' => 'hr'));
     // Attempt to import some broken .po files as well to prove that these
     // will not overwrite the proper plural formula imported above.
     $this->importPoFile($this->getPoFileWithMissingPlural(), array('langcode' => 'fr', 'overwrite_options[not_customized]' => TRUE));
     $this->importPoFile($this->getPoFileWithBrokenPlural(), array('langcode' => 'hr', 'overwrite_options[not_customized]' => TRUE));
     // Reset static caches from locale_get_plural() to ensure we get fresh data.
     drupal_static_reset('locale_get_plural');
     drupal_static_reset('locale_get_plural:plurals');
     drupal_static_reset('locale');
     // Expected plural translation strings for each plural index.
     $plural_strings = array('en' => array(0 => '1 hour', 1 => '@count hours'), 'fr' => array(0 => '@count heure', 1 => '@count heures'), 'hr' => array(0 => '@count sat', 1 => '@count sata', 2 => '@count sati'), 'hu' => array(0 => '1 hour', -1 => '@count hours'));
     // Expected plural indexes precomputed base on the plural formulas with
     // given $count value.
     $plural_tests = array('en' => array(1 => 0, 0 => 1, 5 => 1, 123 => 1, 235 => 1), 'fr' => array(1 => 0, 0 => 0, 5 => 1, 123 => 1, 235 => 1), 'hr' => array(1 => 0, 21 => 0, 0 => 2, 2 => 1, 8 => 2, 123 => 1, 235 => 2), 'hu' => array(1 => -1, 21 => -1, 0 => -1));
     foreach ($plural_tests as $langcode => $tests) {
         foreach ($tests as $count => $expected_plural_index) {
             // Assert that the we get the right plural index.
             $this->assertIdentical(locale_get_plural($count, $langcode), $expected_plural_index, 'Computed plural index for ' . $langcode . ' for count ' . $count . ' is ' . $expected_plural_index);
             // Assert that the we get the right translation for that. Change the
             // expected index as per the logic for translation lookups.
             $expected_plural_index = $count == 1 ? 0 : $expected_plural_index;
             $expected_plural_string = str_replace('@count', $count, $plural_strings[$langcode][$expected_plural_index]);
             $this->assertIdentical(format_plural($count, '1 hour', '@count hours', array(), array('langcode' => $langcode)), $expected_plural_string, 'Plural translation of 1 hours / @count hours for count ' . $count . ' in ' . $langcode . ' is ' . $expected_plural_string);
         }
     }
 }
コード例 #6
0
 public function __construct($order_id)
 {
     $args = func_get_args();
     array_shift($args);
     $page_id = array_shift($args);
     $order = commerce_order_load($order_id);
     if (!$order) {
         $this->setErrors("Order {$order_id} does not exist.");
         $this->setInitialized(FALSE);
         return;
     }
     $checkout_page = NULL;
     drupal_static_reset();
     $checkout_pages = commerce_checkout_pages();
     if (is_null($page_id)) {
         $checkout_page = reset($checkout_pages);
     } elseif (!empty($checkout_pages[$page_id])) {
         $checkout_page = $checkout_pages[$page_id];
     }
     if (is_null($checkout_page)) {
         $this->setErrors("Checkout page not defined correctly.");
         $this->setInitialized(FALSE);
     }
     $this->includeFile('inc', 'commerce_checkout', 'includes/commerce_checkout.pages');
     parent::__construct('commerce_checkout_form_' . $checkout_page['page_id'], $order, $checkout_page);
     $this->page_id = $checkout_page['page_id'];
     $this->order_id = $order_id;
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $modules = $input->getArgument('module');
     $latest = $input->getOption('latest');
     $this->getDrupalHelper()->loadLegacyFile('core/includes/bootstrap.inc');
     $resultList = $this->downloadModules($io, $modules, $latest);
     $invalidModules = $resultList['invalid'];
     $unInstalledModules = $resultList['uninstalled'];
     if ($invalidModules) {
         foreach ($invalidModules as $invalidModule) {
             unset($modules[array_search($invalidModule, $modules)]);
             $io->error(sprintf('Invalid module name: %s', $invalidModule));
         }
     }
     if (!$unInstalledModules) {
         $io->warning($this->trans('commands.module.install.messages.nothing'));
         return 0;
     }
     try {
         $io->comment(sprintf($this->trans('commands.module.install.messages.installing'), implode(', ', $unInstalledModules)));
         $moduleInstaller = $this->getModuleInstaller();
         drupal_static_reset('system_rebuild_module_data');
         $moduleInstaller->install($unInstalledModules, true);
         $io->success(sprintf($this->trans('commands.module.install.messages.success'), implode(', ', $unInstalledModules)));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     $this->getChain()->addCommand('cache:rebuild', ['cache' => 'all']);
 }
コード例 #8
0
/**
 *	Asserts that we create a new search page and remove it again
 */
function testNewAndRemoveSearchPage()
{
    // Create a new search page
    $this->drupalLogin($this->admin_user);
    $this->drupalGet('admin/config/search/apachesolr/search-pages');
    $this->assertText(t('Add search page'), t('Create new search page link is available'));
    $this->clickLink(t('Add search page'));
    $this->assertText(t('The human-readable name of the search page configuration.'), t('Search page creation page succesfully added'));
    $edit = array('page_id' => 'solr_testingsuite', 'env_id' => 'solr', 'label' => 'Test Search Page', 'description' => 'Test Description', 'page_title' => 'Test Title', 'search_path' => 'search/searchdifferentpath');
    $this->drupalPost($this->getUrl(), $edit, t('Save configuration'));
    $this->assertResponse(200);
    // Make sure the menu is recognized
    drupal_static_reset('apachesolr_search_page_load');
    menu_cache_clear_all();
    menu_rebuild();
    $this->drupalGet('admin/config/search/apachesolr/search-pages');
    $this->assertText(t('Test Search Page'), t('Search Page was succesfully created'));
    // Remove the same environment
    $this->clickLink(t('Delete'));
    $this->assertText(t('search page configuration will be deleted.This action cannot be undone.'), t('Delete confirmation page was succesfully loaded'));
    $this->drupalPost($this->getUrl(), array(), t('Delete page'));
    $this->assertResponse(200);
    drupal_static_reset('apachesolr_search_page_load');
    $this->drupalGet('admin/config/search/apachesolr/search-pages');
    $this->assertNoText(t('Test Search Page'), t('Search Environment was succesfully deleted'));
}
コード例 #9
0
ファイル: Config.php プロジェクト: janoka/platform-dev
 /**
  * Set language negotiation.
  *
  * @param string $language_negotiation
  *    Language negotiation name.
  * @param string $type
  *    Language type.
  *
  * @see language_types_configurable()
  */
 public function setLanguageNegotiation($language_negotiation, $type = LANGUAGE_TYPE_INTERFACE)
 {
     include_once DRUPAL_ROOT . '/includes/language.inc';
     $negotiation = array($language_negotiation => -10, 'language-default' => 10);
     // Reset available language provider.
     drupal_static_reset("language_negotiation_info");
     language_negotiation_set($type, $negotiation);
 }
コード例 #10
0
 public static function setUpBeforeClass()
 {
     // Change /data.json path to /json during tests.
     $data_json = open_data_schema_map_api_load('data_json_1_1');
     $data_json->endpoint = 'json';
     drupal_write_record('open_data_schema_map', $data_json, 'id');
     drupal_static_reset('open_data_schema_map_api_load_all');
     menu_rebuild();
 }
 /**
  * Creates a protected user.
  *
  * @param array $protections
  *   (optional) The active protections.
  *   Defaults to an empty array.
  *
  * @return object
  *   The created user.
  */
 protected function createProtectedUser(array $protections = array())
 {
     // Create a user.
     $account = $this->drupalCreateUser();
     // Protect this user.
     $protection_rule = $this->createProtectionRule($account->id(), $protections, 'user');
     $protection_rule->save();
     // Reset available permissions.
     drupal_static_reset('checkPermissions');
     return $account;
 }
コード例 #12
0
 /**
  * Enables translations where it needed.
  */
 protected function enableTranslation()
 {
     // Enable translation for the current entity type and ensure the change is
     // picked up.
     \Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
     \Drupal::service('content_translation.manager')->setEnabled('taxonomy_term', $this->vocabulary->id(), TRUE);
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedDefinitions();
     \Drupal::service('router.builder')->rebuild();
     \Drupal::service('entity.definition_update_manager')->applyUpdates();
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 public function resetCache(array $ids = NULL) {
   drupal_static_reset('taxonomy_term_count_nodes');
   $this->parents = array();
   $this->parentsAll = array();
   $this->children = array();
   $this->treeChildren = array();
   $this->treeParents = array();
   $this->treeTerms = array();
   $this->trees = array();
   parent::resetCache($ids);
 }
コード例 #14
0
ファイル: TermStorage.php プロジェクト: alnutile/drunatra
 /**
  * {@inheritdoc}
  */
 public function resetCache(array $ids = NULL)
 {
     drupal_static_reset('taxonomy_term_count_nodes');
     drupal_static_reset('taxonomy_get_tree');
     drupal_static_reset('taxonomy_get_tree:parents');
     drupal_static_reset('taxonomy_get_tree:terms');
     drupal_static_reset('taxonomy_term_load_parents');
     drupal_static_reset('taxonomy_term_load_parents_all');
     drupal_static_reset('taxonomy_term_load_children');
     parent::resetCache($ids);
 }
コード例 #15
0
 /**
  * If $sticky is FALSE, no tableheader.js should be included.
  */
 function testThemeTableNoStickyHeaders()
 {
     $header = array('one', 'two', 'three');
     $rows = array(array(1, 2, 3), array(4, 5, 6), array(7, 8, 9));
     $attributes = array();
     $caption = NULL;
     $colgroups = array();
     $table = array('#type' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => $attributes, '#caption' => $caption, '#colgroups' => $colgroups, '#sticky' => FALSE);
     $this->render($table);
     $js = _drupal_add_js();
     $this->assertFalse(isset($js['core/misc/tableheader.js']), 'tableheader.js not found.');
     $this->assertNoRaw('sticky-enabled');
     drupal_static_reset('_drupal_add_js');
 }
コード例 #16
0
/**
 *	Asserts that we can edit a search environment
 */
function testEditSearchEnvironment()
{
    $this->drupalLogin($this->admin_user);
    $this->drupalGet('admin/config/search/apachesolr/settings');
    $this->clickLink(t('Edit'));
    $this->assertText(t('Example: http://localhost:8983/solr'), t('Edit page was succesfully loaded'));
    $edit = array('name' => 'new description foo bar', 'url' => 'http://localhost:8983/solr/core_does_not_exists');
    $this->drupalPost($this->getUrl(), $edit, t('Save'));
    $this->assertResponse(200);
    drupal_static_reset('apachesolr_load_all_environments');
    drupal_static_reset('apachesolr_get_solr');
    $this->drupalGet('admin/config/search/apachesolr/settings');
    $this->assertText(t('new description foo bar'), t('Search environment description was succesfully edited'));
    $this->assertText('http://localhost:8983/solr/core_does_not_exists', t('Search environment url was succesfully edited'));
}
コード例 #17
0
 /**
  * Tests that drupal_html_id() cleans the ID properly.
  */
 function testDrupalHTMLId()
 {
     // Verify that letters, digits, and hyphens are not stripped from the ID.
     $id = 'abcdefghijklmnopqrstuvwxyz-0123456789';
     $this->assertIdentical(drupal_html_id($id), $id, 'Verify valid characters pass through.');
     // Verify that invalid characters are stripped from the ID.
     $this->assertIdentical(drupal_html_id('invalid,./:@\\^`{Üidentifier'), 'invalididentifier', 'Strip invalid characters.');
     // Verify Drupal coding standards are enforced.
     $this->assertIdentical(drupal_html_id('ID NAME_[1]'), 'id-name-1', 'Enforce Drupal coding standards.');
     // Reset the static cache so we can ensure the unique id count is at zero.
     drupal_static_reset('drupal_html_id');
     // Clean up IDs with invalid starting characters.
     $this->assertIdentical(drupal_html_id('test-unique-id'), 'test-unique-id', 'Test the uniqueness of IDs #1.');
     $this->assertIdentical(drupal_html_id('test-unique-id'), 'test-unique-id--2', 'Test the uniqueness of IDs #2.');
     $this->assertIdentical(drupal_html_id('test-unique-id'), 'test-unique-id--3', 'Test the uniqueness of IDs #3.');
 }
コード例 #18
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $module = $input->getArgument('module');
     $latest = $input->getOption('latest');
     $composer = $input->getOption('composer');
     $this->get('site')->loadLegacyFile('core/includes/bootstrap.inc');
     if ($composer) {
         foreach ($module as $moduleItem) {
             $command = sprintf('composer show drupal/%s ', $moduleItem);
             $shellProcess = $this->get('shell_process');
             if ($shellProcess->exec($command)) {
                 $io->info(sprintf('Module %s was downloaded with Composer.', $moduleItem));
             } else {
                 $io->error(sprintf('Module %s seems not to be installed with Composer. Halting.', $moduleItem));
                 return 0;
             }
         }
         $unInstalledModules = $module;
     } else {
         $resultList = $this->downloadModules($io, $module, $latest);
         $invalidModules = $resultList['invalid'];
         $unInstalledModules = $resultList['uninstalled'];
         if ($invalidModules) {
             foreach ($invalidModules as $invalidModule) {
                 unset($module[array_search($invalidModule, $module)]);
                 $io->error(sprintf('Invalid module name: %s', $invalidModule));
             }
         }
         if (!$unInstalledModules) {
             $io->warning($this->trans('commands.module.install.messages.nothing'));
             return 0;
         }
     }
     try {
         $io->comment(sprintf($this->trans('commands.module.install.messages.installing'), implode(', ', $unInstalledModules)));
         $moduleInstaller = $this->getDrupalService('module_installer');
         drupal_static_reset('system_rebuild_module_data');
         $moduleInstaller->install($unInstalledModules, true);
         $io->success(sprintf($this->trans('commands.module.install.messages.success'), implode(', ', $unInstalledModules)));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     $this->get('chain_queue')->addCommand('cache:rebuild', ['cache' => 'all']);
 }
コード例 #19
0
 protected function setUp()
 {
     parent::setUp();
     // Enable additional languages.
     $langcodes = ['es', 'ast'];
     foreach ($langcodes as $langcode) {
         ConfigurableLanguage::createFromLangcode($langcode)->save();
     }
     // Enable translation for the current entity type and ensure the change is
     // picked up.
     \Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedDefinitions();
     \Drupal::service('router.builder')->rebuild();
     \Drupal::service('entity.definition_update_manager')->applyUpdates();
     $this->baseUser1 = $this->drupalCreateUser(['access content overview']);
     $this->baseUser2 = $this->drupalCreateUser(['access content overview', 'create content translations', 'update content translations', 'delete content translations']);
 }
コード例 #20
0
 /**
  * Submit the form.
  *
  * @return Response
  *   Response object.
  */
 public function submit()
 {
     $response = $this->pressButton(t('Log In'));
     // Reset the static variables that can get affected when a user logs in.
     drupal_static_reset('menu_get_item');
     drupal_static_reset('menu_tree');
     drupal_static_reset('menu_tree_page_data');
     drupal_static_reset('menu_tree_set_path');
     drupal_static_reset('Menu::getBlocks');
     if (!$response->getSuccess()) {
         return $response;
     }
     // Get the user from form_state.
     $form_state = $this->getFormState();
     $uid = $form_state['uid'];
     $userObject = new User($uid);
     $this->setEntityObject($userObject);
     $response->setVar($userObject);
     return $response;
 }
コード例 #21
0
 /**
  * Tests drupal_static() function.
  *
  * Tests that a variable reference returned by drupal_static() gets reset when
  * drupal_static_reset() is called.
  */
 function testDrupalStatic()
 {
     $name = __CLASS__ . '_' . __METHOD__;
     $var =& drupal_static($name, 'foo');
     $this->assertEqual($var, 'foo', 'Variable returned by drupal_static() was set to its default.');
     // Call the specific reset and the global reset each twice to ensure that
     // multiple resets can be issued without odd side effects.
     $var = 'bar';
     drupal_static_reset($name);
     $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of name-specific reset.');
     $var = 'bar';
     drupal_static_reset($name);
     $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of name-specific reset.');
     $var = 'bar';
     drupal_static_reset();
     $this->assertEqual($var, 'foo', 'Variable was reset after first invocation of global reset.');
     $var = 'bar';
     drupal_static_reset();
     $this->assertEqual($var, 'foo', 'Variable was reset after second invocation of global reset.');
 }
コード例 #22
0
ファイル: FrameworkTest.php プロジェクト: anyforsoft/csua_d8
 /**
  * Tests AjaxResponse::prepare() AJAX commands ordering.
  */
 public function testOrder()
 {
     $path = drupal_get_path('module', 'system');
     $expected_commands = array();
     // Expected commands, in a very specific order.
     $expected_commands[0] = new SettingsCommand(array('ajax' => 'test'), TRUE);
     drupal_static_reset('_drupal_add_css');
     $attached = array('#attached' => array('css' => array($path . '/css/system.admin.css' => array(), $path . '/css/system.maintenance.css' => array())));
     drupal_render($attached);
     drupal_process_attached($attached);
     $expected_commands[1] = new AddCssCommand(drupal_get_css(_drupal_add_css(), TRUE));
     drupal_static_reset('_drupal_add_js');
     $attached = array('#attached' => array('js' => array($path . '/system.js' => array())));
     drupal_render($attached);
     drupal_process_attached($attached);
     $expected_commands[2] = new PrependCommand('head', drupal_get_js('header', _drupal_add_js(), TRUE));
     drupal_static_reset('_drupal_add_js');
     $attached = array('#attached' => array('js' => array($path . '/system.modules.js' => array('scope' => 'footer'))));
     drupal_render($attached);
     drupal_process_attached($attached);
     $expected_commands[3] = new AppendCommand('body', drupal_get_js('footer', _drupal_add_js(), TRUE));
     $expected_commands[4] = new HtmlCommand('body', 'Hello, world!');
     // Load any page with at least one CSS file, at least one JavaScript file
     // and at least one #ajax-powered element. The latter is an assumption of
     // drupalPostAjaxForm(), the two former are assumptions of
     // AjaxReponse::ajaxRender().
     // @todo refactor AJAX Framework + tests to make less assumptions.
     $this->drupalGet('ajax_forms_test_lazy_load_form');
     // Verify AJAX command order — this should always be the order:
     // 1. JavaScript settings
     // 2. CSS files
     // 3. JavaScript files in the header
     // 4. JavaScript files in the footer
     // 5. Any other AJAX commands, in whatever order they were added.
     $commands = $this->drupalPostAjaxForm(NULL, array(), NULL, 'ajax-test/order', array(), array(), NULL, array());
     $this->assertCommand(array_slice($commands, 0, 1), $expected_commands[0]->render(), 'Settings command is first.');
     $this->assertCommand(array_slice($commands, 1, 1), $expected_commands[1]->render(), 'CSS command is second (and CSS files are ordered correctly).');
     $this->assertCommand(array_slice($commands, 2, 1), $expected_commands[2]->render(), 'Header JS command is third.');
     $this->assertCommand(array_slice($commands, 3, 1), $expected_commands[3]->render(), 'Footer JS command is fourth.');
     $this->assertCommand(array_slice($commands, 4, 1), $expected_commands[4]->render(), 'HTML command is fifth.');
 }
コード例 #23
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $module = $input->getArgument('module');
     $unInstalledDependencies = $this->calculateDependencies((array) $module);
     if (!$unInstalledDependencies) {
         $io->warning($this->trans('commands.module.install.dependencies.messages.no-depencies'));
         return 0;
     }
     try {
         $io->comment(sprintf($this->trans('commands.module.install.dependencies.messages.installing'), implode(', ', $unInstalledModules)));
         $moduleInstaller = $this->getDrupalService('module_installer');
         drupal_static_reset('system_rebuild_module_data');
         $moduleInstaller->install($unInstalledDependencies, true);
         $io->success(sprintf($this->trans('commands.module.install.dependencies.messages.success'), implode(', ', $unInstalledDependencies)));
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     $this->get('chain_queue')->addCommand('cache:rebuild', ['cache' => 'all']);
 }
コード例 #24
0
 /**
  * Tests the rendering of blocks.
  */
 public function testBasicRendering()
 {
     \Drupal::state()->set('block_test.content', '');
     $entity = $this->controller->create(array('id' => 'test_block1', 'theme' => 'stark', 'plugin' => 'test_html'));
     $entity->save();
     // Test the rendering of a block.
     $entity = entity_load('block', 'test_block1');
     $output = entity_view($entity, 'block');
     $expected = array();
     $expected[] = '<div class="block block-block-test" id="block-test-block1">';
     $expected[] = '  ';
     $expected[] = '    ';
     $expected[] = '';
     $expected[] = '  <div class="content">';
     $expected[] = '          ';
     $expected[] = '      </div>';
     $expected[] = '</div>';
     $expected[] = '';
     $expected_output = implode("\n", $expected);
     $this->assertEqual(drupal_render($output), $expected_output);
     // Reset the HTML IDs so that the next render is not affected.
     drupal_static_reset('drupal_html_id');
     // Test the rendering of a block with a given title.
     $entity = $this->controller->create(array('id' => 'test_block2', 'theme' => 'stark', 'plugin' => 'test_html', 'settings' => array('label' => 'Powered by Bananas')));
     $entity->save();
     $output = entity_view($entity, 'block');
     $expected = array();
     $expected[] = '<div class="block block-block-test" id="block-test-block2">';
     $expected[] = '  ';
     $expected[] = '      <h2>Powered by Bananas</h2>';
     $expected[] = '    ';
     $expected[] = '';
     $expected[] = '  <div class="content">';
     $expected[] = '          ';
     $expected[] = '      </div>';
     $expected[] = '</div>';
     $expected[] = '';
     $expected_output = implode("\n", $expected);
     $this->assertEqual(drupal_render($output), $expected_output);
 }
コード例 #25
0
 /**
  * Set up configuration for multiple languages.
  */
 function setUpLanguages()
 {
     // Add languages.
     $this->defaultLanguage = 'en';
     $this->secondaryLanguage = 'es';
     $this->addLanguage($this->secondaryLanguage);
     // Display the language widget.
     $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'simplenews_issue');
     $config->setLanguageAlterable(TRUE);
     $config->save();
     // Make Simplenews issue translatable.
     \Drupal::service('content_translation.manager')->setEnabled('node', 'simplenews_issue', TRUE);
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedDefinitions();
     \Drupal::service('router.builder')->rebuild();
     \Drupal::service('entity.definition_update_manager')->applyUpdates();
     // Make Simplenews issue body translatable.
     $field = FieldConfig::loadByName('node', 'simplenews_issue', 'body');
     $field->setTranslatable(TRUE);
     $field->save();
     $this->rebuildContainer();
 }
コード例 #26
0
 /**
  * Tests locale_get_plural() and \Drupal::translation()->formatPlural()
  * functionality.
  */
 public function testGetPluralFormat()
 {
     // Import some .po files with formulas to set up the environment.
     // These will also add the languages to the system.
     $this->importPoFile($this->getPoFileWithSimplePlural(), array('langcode' => 'fr'));
     $this->importPoFile($this->getPoFileWithComplexPlural(), array('langcode' => 'hr'));
     // Attempt to import some broken .po files as well to prove that these
     // will not overwrite the proper plural formula imported above.
     $this->importPoFile($this->getPoFileWithMissingPlural(), array('langcode' => 'fr', 'overwrite_options[not_customized]' => TRUE));
     $this->importPoFile($this->getPoFileWithBrokenPlural(), array('langcode' => 'hr', 'overwrite_options[not_customized]' => TRUE));
     // Reset static caches from locale_get_plural() to ensure we get fresh data.
     drupal_static_reset('locale_get_plural');
     drupal_static_reset('locale_get_plural:plurals');
     drupal_static_reset('locale');
     // Expected plural translation strings for each plural index.
     $plural_strings = array('en' => array(0 => '1 hour', 1 => '@count hours'), 'fr' => array(0 => '@count heure', 1 => '@count heures'), 'hr' => array(0 => '@count sat', 1 => '@count sata', 2 => '@count sati'), 'hu' => array(0 => '1 hour', -1 => '@count hours'));
     // Expected plural indexes precomputed base on the plural formulas with
     // given $count value.
     $plural_tests = array('en' => array(1 => 0, 0 => 1, 5 => 1, 123 => 1, 235 => 1), 'fr' => array(1 => 0, 0 => 0, 5 => 1, 123 => 1, 235 => 1), 'hr' => array(1 => 0, 21 => 0, 0 => 2, 2 => 1, 8 => 2, 123 => 1, 235 => 2), 'hu' => array(1 => -1, 21 => -1, 0 => -1));
     foreach ($plural_tests as $langcode => $tests) {
         foreach ($tests as $count => $expected_plural_index) {
             // Assert that the we get the right plural index.
             $this->assertIdentical(locale_get_plural($count, $langcode), $expected_plural_index, 'Computed plural index for ' . $langcode . ' for count ' . $count . ' is ' . $expected_plural_index);
             // Assert that the we get the right translation for that. Change the
             // expected index as per the logic for translation lookups.
             $expected_plural_index = $count == 1 ? 0 : $expected_plural_index;
             $expected_plural_string = str_replace('@count', $count, $plural_strings[$langcode][$expected_plural_index]);
             $this->assertIdentical(\Drupal::translation()->formatPlural($count, '1 hour', '@count hours', array(), array('langcode' => $langcode))->render(), $expected_plural_string, 'Plural translation of 1 hours / @count hours for count ' . $count . ' in ' . $langcode . ' is ' . $expected_plural_string);
             // DO NOT use translation to pass translated strings into
             // PluralTranslatableMarkup::createFromTranslatedString() this way. It
             // is designed to be used with *already* translated text like settings
             // from configuration. We use PHP translation here just because we have
             // the expected result data in that format.
             $translated_string = \Drupal::translation()->translate('1 hour' . PluralTranslatableMarkup::DELIMITER . '@count hours', array(), array('langcode' => $langcode));
             $plural = PluralTranslatableMarkup::createFromTranslatedString($count, $translated_string, array(), array('langcode' => $langcode));
             $this->assertIdentical($plural->render(), $expected_plural_string);
         }
     }
 }
コード例 #27
0
 /**
  * Tests that the taxonomy term view is working properly.
  */
 public function testTaxonomyTermView()
 {
     // Create terms in the vocabulary.
     $term = $this->createTerm($this->vocabulary);
     // Post an article.
     $edit = array();
     $edit['title[0][value]'] = $original_title = $this->randomMachineName();
     $edit['body[0][value]'] = $this->randomMachineName();
     $edit["{$this->field_name_1}[]"] = $term->id();
     $this->drupalPostForm('node/add/article', $edit, t('Save'));
     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $this->drupalGet('taxonomy/term/' . $term->id());
     $this->assertText($term->label());
     $this->assertText($node->label());
     \Drupal::moduleHandler()->install(array('language', 'content_translation'));
     $language = ConfigurableLanguage::createFromLangcode('ur');
     $language->save();
     // Enable translation for the article content type and ensure the change is
     // picked up.
     content_translation_set_config('node', 'article', 'enabled', TRUE);
     $roles = $this->admin_user->getRoles(TRUE);
     Role::load(reset($roles))->grantPermission('create content translations')->grantPermission('translate any entity')->save();
     drupal_static_reset();
     \Drupal::entityManager()->clearCachedDefinitions();
     \Drupal::service('router.builder')->rebuild();
     $edit['title[0][value]'] = $translated_title = $this->randomMachineName();
     $this->drupalPostForm('node/' . $node->id() . '/translations/add/en/ur', $edit, t('Save (this translation)'));
     $this->drupalGet('taxonomy/term/' . $term->id());
     $this->assertText($term->label());
     $this->assertText($original_title);
     $this->assertNoText($translated_title);
     $this->drupalGet('ur/taxonomy/term/' . $term->id());
     $this->assertText($term->label());
     $this->assertNoText($original_title);
     $this->assertText($translated_title);
 }
コード例 #28
0
 /**
  * Tests that drupal_get_filename() works when the file is not in database.
  */
 function testDrupalGetFilename()
 {
     // drupal_get_profile() is using obtaining the profile from state if the
     // install_state global is not set.
     global $install_state;
     $install_state['parameters']['profile'] = 'testing';
     // Rebuild system.module.files state data.
     // @todo Remove as part of https://www.drupal.org/node/2186491
     drupal_static_reset('system_rebuild_module_data');
     system_rebuild_module_data();
     // Retrieving the location of a module.
     $this->assertIdentical(drupal_get_filename('module', 'system'), 'core/modules/system/system.info.yml');
     // Retrieving the location of a theme.
     \Drupal::service('theme_handler')->install(array('stark'));
     $this->assertIdentical(drupal_get_filename('theme', 'stark'), 'core/themes/stark/stark.info.yml');
     // Retrieving the location of a theme engine.
     $this->assertIdentical(drupal_get_filename('theme_engine', 'twig'), 'core/themes/engines/twig/twig.info.yml');
     // Retrieving the location of a profile. Profiles are a special case with
     // a fixed location and naming.
     $this->assertIdentical(drupal_get_filename('profile', 'testing'), 'core/profiles/testing/testing.info.yml');
     // Generate a non-existing module name.
     $non_existing_module = uniqid("", TRUE);
     // Set a custom error handler so we can ignore the file not found error.
     set_error_handler(function ($severity, $message, $file, $line) {
         // Skip error handling if this is a "file not found" error.
         if (strstr($message, 'is missing from the file system:')) {
             \Drupal::state()->set('get_filename_test_triggered_error', TRUE);
             return;
         }
         throw new \ErrorException($message, 0, $severity, $file, $line);
     });
     $this->assertNull(drupal_get_filename('module', $non_existing_module), 'Searching for an item that does not exist returns NULL.');
     $this->assertTrue(\Drupal::state()->get('get_filename_test_triggered_error'), 'Searching for an item that does not exist triggers an error.');
     // Restore the original error handler.
     restore_error_handler();
 }
コード例 #29
0
 /**
  * Tests term indentation.
  */
 function testTermIndentation()
 {
     // Create three taxonomy terms.
     $term1 = $this->createTerm($this->vocabulary);
     $term2 = $this->createTerm($this->vocabulary);
     $term3 = $this->createTerm($this->vocabulary);
     // Indent the second term under the first one.
     $edit = array('terms[tid:' . $term2->id() . ':0][term][tid]' => 2, 'terms[tid:' . $term2->id() . ':0][term][parent]' => 1, 'terms[tid:' . $term2->id() . ':0][term][depth]' => 1, 'terms[tid:' . $term2->id() . ':0][weight]' => 1);
     // Submit the edited form and check for HTML indentation element presence.
     $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
     $this->assertPattern('|<div class="indentation">&nbsp;</div>|');
     // Check explicitly that term 2's parent is term 1.
     $parents = taxonomy_term_load_parents($term2->id());
     $this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent');
     // Move the second term back out to the root level.
     $edit = array('terms[tid:' . $term2->id() . ':0][term][tid]' => 2, 'terms[tid:' . $term2->id() . ':0][term][parent]' => 0, 'terms[tid:' . $term2->id() . ':0][term][depth]' => 0, 'terms[tid:' . $term2->id() . ':0][weight]' => 1);
     $this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
     // All terms back at the root level, no identation should be present.
     $this->assertNoPattern('|<div class="indentation">&nbsp;</div>|');
     // Check explicitly that term 2 has no parents.
     drupal_static_reset();
     $parents = taxonomy_term_load_parents($term2->id());
     $this->assertTrue(empty($parents), 'Term 2 has no parents now');
 }
コード例 #30
0
ファイル: Drupal8.php プロジェクト: lmakarov/DrupalDriver
 /**
  * {@inheritdoc}
  */
 public function clearStaticCaches()
 {
     drupal_static_reset();
     \Drupal::service('cache_tags.invalidator')->resetChecksums();
 }