示例#1
0
 /**
  * Submits forms with select and checkbox elements via Ajax.
  */
 function testSimpleAjaxFormValue()
 {
     // Verify form values of a select element.
     foreach (array('red', 'green', 'blue') as $item) {
         $edit = array('select' => $item);
         $commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, 'select');
         $expected = new DataCommand('#ajax_selected_color', 'form_state_value_select', $item);
         $this->assertCommand($commands, $expected->render(), 'Verification of AJAX form values from a selectbox issued with a correct value.');
     }
     // Verify form values of a checkbox element.
     foreach (array(FALSE, TRUE) as $item) {
         $edit = array('checkbox' => $item);
         $commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, 'checkbox');
         $expected = new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $item);
         $this->assertCommand($commands, $expected->render(), 'Verification of AJAX form values from a checkbox issued with a correct value.');
     }
     // Verify that AJAX elements with invalid callbacks return error code 500.
     // Ensure the test error log is empty before these tests.
     $this->assertNoErrorsLogged();
     // We don't need to check for the X-Drupal-Ajax-Token header with these
     // invalid requests.
     $this->assertAjaxHeader = FALSE;
     foreach (array('null', 'empty', 'nonexistent') as $key) {
         $element_name = 'select_' . $key . '_callback';
         $edit = array($element_name => 'red');
         $commands = $this->drupalPostAjaxForm('ajax_forms_test_get_form', $edit, $element_name);
         $this->assertResponse(500);
     }
     // Switch this back to the default.
     $this->assertAjaxHeader = TRUE;
     // The exceptions are expected. Do not interpret them as a test failure.
     // Not using File API; a potential error must trigger a PHP warning.
     unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
 }
 /**
  * {@inheritdoc}
  */
 protected function visitInstaller()
 {
     // Place a custom local translation in the translations directory.
     mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
     file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
     file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.fr.po', $this->getPo('fr'));
     // Pass a different language code than the one set in the distribution
     // profile. This distribution language should still be used.
     // The unrouted URL assembler does not exist at this point, so we build the
     // URL ourselves.
     $this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=fr');
     // The language should have been automatically detected, all following
     // screens should be translated already.
     $elements = $this->xpath('//input[@type="submit"]/@value');
     $this->assertEqual((string) current($elements), 'Save and continue de');
     $this->translations['Save and continue'] = 'Save and continue de';
     // Check the language direction.
     $direction = (string) current($this->xpath('/html/@dir'));
     $this->assertEqual($direction, 'ltr');
     // Verify that the distribution name appears.
     $this->assertRaw($this->info['distribution']['name']);
     // Verify that the requested theme is used.
     $this->assertRaw($this->info['distribution']['install']['theme']);
     // Verify that the "Choose profile" step does not appear.
     $this->assertNoText('profile');
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     require_once \Drupal::root() . '/core/includes/update.inc';
     $this->user = $this->drupalCreateUser(['administer software updates', 'access site in maintenance mode']);
     $this->updateUrl = Url::fromRoute('system.db_update');
 }
示例#4
0
    /**
     * Tests the drupal_rewrite_settings() function.
     */
    function testDrupalRewriteSettings()
    {
        include_once \Drupal::root() . '/core/includes/install.inc';
        $site_path = $this->container->get('site.path');
        $tests = array(array('original' => '$no_index_value_scalar = TRUE;', 'settings' => array('no_index_value_scalar' => (object) array('value' => FALSE, 'comment' => 'comment')), 'expected' => '$no_index_value_scalar = false; // comment'), array('original' => '$no_index_value_scalar = TRUE;', 'settings' => array('no_index_value_foo' => array('foo' => array('value' => (object) array('value' => NULL, 'required' => TRUE, 'comment' => 'comment')))), 'expected' => <<<'EXPECTED'
$no_index_value_scalar = TRUE;
$no_index_value_foo['foo']['value'] = NULL; // comment
EXPECTED
), array('original' => '$no_index_value_array = array("old" => "value");', 'settings' => array('no_index_value_array' => (object) array('value' => FALSE, 'required' => TRUE, 'comment' => 'comment')), 'expected' => '$no_index_value_array = array("old" => "value");
$no_index_value_array = false; // comment'), array('original' => '$has_index_value_scalar["foo"]["bar"] = NULL;', 'settings' => array('has_index_value_scalar' => array('foo' => array('bar' => (object) array('value' => FALSE, 'required' => TRUE, 'comment' => 'comment')))), 'expected' => '$has_index_value_scalar["foo"]["bar"] = false; // comment'), array('original' => '$has_index_value_scalar["foo"]["bar"] = "foo";', 'settings' => array('has_index_value_scalar' => array('foo' => array('value' => (object) array('value' => array('value' => 2), 'required' => TRUE, 'comment' => 'comment')))), 'expected' => <<<'EXPECTED'
$has_index_value_scalar["foo"]["bar"] = "foo";
$has_index_value_scalar['foo']['value'] = array (
  'value' => 2,
); // comment
EXPECTED
));
        foreach ($tests as $test) {
            $filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php';
            file_put_contents(\Drupal::root() . '/' . $filename, "<?php\n" . $test['original'] . "\n");
            drupal_rewrite_settings($test['settings'], $filename);
            $this->assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
        }
        // Test that <?php gets added to the start of an empty settings file.
        // Set the array of settings that will be written to the file.
        $test = array('settings' => array('no_index' => (object) array('value' => TRUE, 'required' => TRUE)), 'expected' => '$no_index = true;');
        // Make an empty file.
        $filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php';
        file_put_contents(\Drupal::root() . '/' . $filename, "");
        // Write the setting to the file.
        drupal_rewrite_settings($test['settings'], $filename);
        // Check that the result is just the php opening tag and the settings.
        $this->assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
    }
 /**
  * Tests running update.php with some form of broken routing.
  */
 public function testWithBrokenRouting()
 {
     // Make sure we can get to the front page.
     $this->drupalGet('<front>');
     $this->assertResponse(200);
     // Simulate a broken router, and make sure the front page is
     // inaccessible.
     \Drupal::state()->set('update_script_test_broken_inbound', TRUE);
     \Drupal::service('cache_tags.invalidator')->invalidateTags(['route_match', 'rendered']);
     $this->drupalGet('<front>');
     $this->assertResponse(500);
     // The exceptions are expected. Do not interpret them as a test failure.
     // Not using File API; a potential error must trigger a PHP warning.
     unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
     foreach ($this->assertions as $key => $assertion) {
         if (strpos($assertion['message'], 'core/modules/system/tests/modules/update_script_test/src/PathProcessor/BrokenInboundPathProcessor.php') !== FALSE) {
             unset($this->assertions[$key]);
             $this->deleteAssert($assertion['message_id']);
         }
     }
     $this->runUpdates();
     // Remove the simulation of the broken router, and make sure we can get to
     // the front page again.
     \Drupal::state()->set('update_script_test_broken_inbound', FALSE);
     $this->drupalGet('<front>');
     $this->assertResponse(200);
 }
示例#6
0
 /**
  * Parse input options decide on a database.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  *   Input object.
  * @return \Drupal\Core\Database\Connection
  */
 protected function getDatabaseConnection(InputInterface $input)
 {
     // Load connection from a url.
     if ($input->getOption('database-url')) {
         // @todo this could probably be refactored to not use a global connection.
         // Ensure database connection isn't set.
         if (Database::getConnectionInfo('db-tools')) {
             throw new \RuntimeException('Database "db-tools" is already defined. Cannot define database provided.');
         }
         $info = Database::convertDbUrlToConnectionInfo($input->getOption('database-url'), \Drupal::root());
         Database::addConnectionInfo('db-tools', 'default', $info);
         $key = 'db-tools';
     } else {
         $key = $input->getOption('database');
     }
     // If they supplied a prefix, replace it in the connection information.
     $prefix = $input->getOption('prefix');
     if ($prefix) {
         $info = Database::getConnectionInfo($key)['default'];
         $info['prefix']['default'] = $prefix;
         Database::removeConnection($key);
         Database::addConnectionInfo($key, 'default', $info);
     }
     return Database::getConnection('default', $key);
 }
 protected function setUp()
 {
     // Only install update_test_2.module, even though its updates have a
     // dependency on update_test_3.module.
     parent::setUp();
     require_once \Drupal::root() . '/core/includes/update.inc';
 }
 protected function setUp()
 {
     parent::setUp();
     require_once \Drupal::root() . '/core/includes/update.inc';
     $this->update_url = $GLOBALS['base_url'] . '/update.php';
     $this->update_user = $this->drupalCreateUser(array('administer software updates'));
 }
示例#9
0
 /**
  * Tests that files in different directories take precedence as expected.
  */
 function testDirectoryPrecedence()
 {
     // Define the module files we will search for, and the directory precedence
     // we expect.
     $expected_directories = array('drupal_system_listing_compatible_test' => array('core/profiles/testing/modules', 'core/modules/system/tests/modules'));
     // This test relies on two versions of the same module existing in
     // different places in the filesystem. Without that, the test has no
     // meaning, so assert their presence first.
     foreach ($expected_directories as $module => $directories) {
         foreach ($directories as $directory) {
             $filename = "{$directory}/{$module}/{$module}.info.yml";
             $this->assertTrue(file_exists(\Drupal::root() . '/' . $filename), format_string('@filename exists.', array('@filename' => $filename)));
         }
     }
     // Now scan the directories and check that the files take precedence as
     // expected.
     $listing = new ExtensionDiscovery(\Drupal::root());
     $listing->setProfileDirectories(array('core/profiles/testing'));
     $files = $listing->scan('module');
     foreach ($expected_directories as $module => $directories) {
         $expected_directory = array_shift($directories);
         $expected_uri = "{$expected_directory}/{$module}/{$module}.info.yml";
         $this->assertEqual($files[$module]->getPathname(), $expected_uri, format_string('Module @actual was found at @expected.', array('@actual' => $files[$module]->getPathname(), '@expected' => $expected_uri)));
     }
 }
 /**
  * Ensures that the user page is available after installation.
  */
 public function testInstaller()
 {
     $this->assertUrl('user/1');
     $this->assertResponse(200);
     // Confirm that we are logged-in after installation.
     $this->assertText($this->rootUser->getUsername());
     // @todo hmmm this message is wrong!
     // Verify that the confirmation message appears.
     require_once \Drupal::root() . '/core/includes/install.inc';
     $this->assertRaw(t('Congratulations, you installed @drupal!', array('@drupal' => drupal_install_profile_distribution_name())));
     // Ensure that all modules, profile and themes have been installed and have
     // expected weights.
     $sync = \Drupal::service('config.storage.sync');
     $sync_core_extension = $sync->read('core.extension');
     $this->assertIdentical($sync_core_extension, \Drupal::config('core.extension')->get());
     // Ensure that the correct install profile has been written to settings.php.
     $listing = new ExtensionDiscovery(\Drupal::root());
     $listing->setProfileDirectories([]);
     $profiles = array_intersect_key($listing->scan('profile'), $sync_core_extension['module']);
     $current_profile = Settings::get('install_profile');
     $this->assertFalse(empty($current_profile), 'The $install_profile setting exists');
     $this->assertEqual($current_profile, key($profiles));
     // Test that any configuration entities in sync have been created.
     // @todo
 }
 protected function tearDown()
 {
     // This test intentionally throws an exception in a PHP shutdown function.
     // Prevent it from being interpreted as an actual test failure.
     // Not using File API; a potential error must trigger a PHP warning.
     unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
     parent::tearDown();
 }
示例#12
0
 /**
  * Tests project and child project showing correct title.
  *
  * @see https://drupal.org/node/2409515
  */
 public function testGetProjectTitleWithChild()
 {
     // Get the project title from it's directory. If it can't find the title
     // it will choose the first project title in the directory.
     $directory = \Drupal::root() . '/core/modules/system/tests/modules/module_handler_test_multiple';
     $title = Updater::getProjectTitle($directory);
     $this->assertEqual('module handler test multiple', $title);
 }
示例#13
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     // Set the path of the module dynamically.
     $module_path = str_replace(\Drupal::root(), '', __DIR__);
     $module_path = str_replace('tests/src/Unit/Menu', '', $module_path);
     $module_path = trim($module_path, '/');
     $this->directoryList = array('search_api' => $module_path);
 }
 public function getForm(array &$form, array &$form_state, \Payment $payment)
 {
     $form['holder'] = array('#type' => 'textfield', '#title' => t('Account holder'));
     include_once \Drupal::root() . '/includes/locale.inc';
     $form['ibanbic'] = array('#type' => 'container');
     $form['ibanbic']['iban'] = array('#type' => 'textfield', '#title' => t('IBAN'), '#required' => FALSE, '#default_value' => NULL, '#size' => 48, '#maxlength' => 48);
     $form['ibanbic']['bic'] = array('#type' => 'textfield', '#title' => t('BIC'), '#required' => FALSE, '#default_value' => NULL, '#size' => 16, '#maxlength' => 16);
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 protected function getAllFolders()
 {
     if (!isset($this->folders)) {
         $listing = new ExtensionDiscovery(\Drupal::root());
         $modules = $listing->scan('module');
         $this->folders = $this->getComponentNames(array('behat_test' => $modules['behat_test']));
     }
     return $this->folders;
 }
 protected function setUp()
 {
     parent::setUp();
     $this->expectedDefinitions = array('example_1' => array('id' => 'example_1', 'custom' => 'John', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\custom_annotation\\Example1', 'provider' => 'plugin_test'), 'example_2' => array('id' => 'example_2', 'custom' => 'Paul', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\custom_annotation\\Example2', 'provider' => 'plugin_test'));
     $base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src';
     $root_namespaces = new \ArrayObject(array('Drupal\\plugin_test' => $base_directory));
     $this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/custom_annotation', $root_namespaces, 'Drupal\\plugin_test\\Plugin\\Annotation\\PluginExample');
     $this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $root_namespaces, 'Drupal\\plugin_test\\Plugin\\Annotation\\PluginExample');
 }
 /**
  * Returns a map of all config object names and their folders.
  *
  * The list is based on enabled modules and themes. The active configuration
  * storage is used rather than \Drupal\Core\Extension\ModuleHandler and
  *  \Drupal\Core\Extension\ThemeHandler in order to resolve circular
  * dependencies between these services and \Drupal\Core\Config\ConfigInstaller
  * and \Drupal\Core\Config\TypedConfigManager.
  *
  * @return array
  *   An array mapping config object names with directories.
  */
 protected function getAllFolders()
 {
     if (!isset($this->folders)) {
         $this->folders = array();
         $this->folders += $this->getCoreNames();
         $install_profile = Settings::get('install_profile');
         $profile = drupal_get_profile();
         $extensions = $this->configStorage->read('core.extension');
         // @todo Remove this scan as part of https://www.drupal.org/node/2186491
         $listing = new ExtensionDiscovery(\Drupal::root());
         if (!empty($extensions['module'])) {
             $modules = $extensions['module'];
             // Remove the install profile as this is handled later.
             unset($modules[$install_profile]);
             $profile_list = $listing->scan('profile');
             if ($profile && isset($profile_list[$profile])) {
                 // Prime the drupal_get_filename() static cache with the profile info
                 // file location so we can use drupal_get_path() on the active profile
                 // during the module scan.
                 // @todo Remove as part of https://www.drupal.org/node/2186491
                 drupal_get_filename('profile', $profile, $profile_list[$profile]->getPathname());
             }
             $module_list_scan = $listing->scan('module');
             $module_list = array();
             foreach (array_keys($modules) as $module) {
                 if (isset($module_list_scan[$module])) {
                     $module_list[$module] = $module_list_scan[$module];
                 }
             }
             $this->folders += $this->getComponentNames($module_list);
         }
         if (!empty($extensions['theme'])) {
             $theme_list_scan = $listing->scan('theme');
             foreach (array_keys($extensions['theme']) as $theme) {
                 if (isset($theme_list_scan[$theme])) {
                     $theme_list[$theme] = $theme_list_scan[$theme];
                 }
             }
             $this->folders += $this->getComponentNames($theme_list);
         }
         if ($this->includeProfile) {
             // The install profile can override module default configuration. We do
             // this by replacing the config file path from the module/theme with the
             // install profile version if there are any duplicates.
             if (isset($profile)) {
                 if (!isset($profile_list)) {
                     $profile_list = $listing->scan('profile');
                 }
                 if (isset($profile_list[$profile])) {
                     $profile_folders = $this->getComponentNames(array($profile_list[$profile]));
                     $this->folders = $profile_folders + $this->folders;
                 }
             }
         }
     }
     return $this->folders;
 }
 protected function setUp()
 {
     parent::setUp();
     $this->expectedDefinitions = array('apple' => array('id' => 'apple', 'label' => 'Apple', 'color' => 'green', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Apple', 'provider' => 'plugin_test'), 'banana' => array('id' => 'banana', 'label' => 'Banana', 'color' => 'yellow', 'uses' => array('bread' => t('Banana bread')), 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Banana', 'provider' => 'plugin_test'), 'cherry' => array('id' => 'cherry', 'label' => 'Cherry', 'color' => 'red', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Cherry', 'provider' => 'plugin_test'), 'kale' => array('id' => 'kale', 'label' => 'Kale', 'color' => 'green', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Kale', 'provider' => 'plugin_test'), 'orange' => array('id' => 'orange', 'label' => 'Orange', 'color' => 'orange', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Orange', 'provider' => 'plugin_test'));
     $base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src';
     $namespaces = new \ArrayObject(array('Drupal\\plugin_test' => $base_directory));
     $this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/fruit', $namespaces);
     $this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $namespaces);
 }
 /**
  * Ensures that the user page is available after installation.
  */
 public function testInstaller()
 {
     // Do assertions from parent.
     require_once \Drupal::root() . '/core/includes/install.inc';
     $this->assertRaw(t('Congratulations, you installed @drupal fr!', array('@drupal' => drupal_install_profile_distribution_name())));
     // Even though we began the install in English the configuration is French
     // so that takes precedence.
     $this->assertEqual('fr', \Drupal::config('system.site')->get('default_langcode'));
     $this->assertFalse(\Drupal::service('language_manager')->isMultilingual());
 }
示例#20
0
 /**
  * Ensures that the user page is available after installation.
  */
 public function testInstaller()
 {
     $this->assertUrl('user/1');
     $this->assertResponse(200);
     // Confirm that we are logged-in after installation.
     $this->assertText($this->rootUser->getUsername());
     // Verify that the confirmation message appears.
     require_once \Drupal::root() . '/core/includes/install.inc';
     $this->assertRaw(t('Congratulations, you installed @drupal!', array('@drupal' => drupal_install_profile_distribution_name())));
 }
示例#21
0
 /**
  * @return \Drupal\Core\Extension\Extension[]
  */
 private function discoverModules()
 {
     /*
      * @todo Remove DrupalExtensionDiscovery subclass once
      * https://www.drupal.org/node/2503927 is fixed.
      */
     $discovery = new DrupalExtensionDiscovery(\Drupal::root());
     $discovery->reset();
     return $discovery->scan('module');
 }
示例#22
0
 protected function setUp()
 {
     parent::setUp();
     entity_create('field_storage_config', array('entity_type' => 'entity_test', 'field_name' => 'image_test', 'type' => 'image', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED))->save();
     entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => 'image_test', 'bundle' => 'entity_test'))->save();
     file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg');
     $this->image = entity_create('file', array('uri' => 'public://example.jpg'));
     $this->image->save();
     $this->imageFactory = $this->container->get('image.factory');
 }
示例#23
0
 protected function setUp()
 {
     parent::setUp();
     // Theme settings rely on System module's system.theme.global configuration.
     $this->installConfig(array('system'));
     if (!isset($this->availableThemes)) {
         $discovery = new ExtensionDiscovery(\Drupal::root());
         $this->availableThemes = $discovery->scan('theme');
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $this->expectedDefinitions = array('custom_example_1' => array('id' => 'custom_example_1', 'custom' => 'Tim', 'class' => 'Drupal\\plugin_test\\CustomDirectoryExample1', 'provider' => 'plugin_test'), 'custom_example_2' => array('id' => 'custom_example_2', 'custom' => 'Meghan', 'class' => 'Drupal\\plugin_test\\CustomDirectoryExample2', 'provider' => 'plugin_test'), 'apple' => array('id' => 'apple', 'label' => 'Apple', 'color' => 'green', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Apple', 'provider' => 'plugin_test'), 'banana' => array('id' => 'banana', 'label' => 'Banana', 'color' => 'yellow', 'uses' => array('bread' => t('Banana bread'), 'loaf' => array('singular' => '@count loaf', 'plural' => '@count loaves', 'context' => NULL)), 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Banana', 'provider' => 'plugin_test'), 'cherry' => array('id' => 'cherry', 'label' => 'Cherry', 'color' => 'red', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Cherry', 'provider' => 'plugin_test'), 'kale' => array('id' => 'kale', 'label' => 'Kale', 'color' => 'green', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Kale', 'provider' => 'plugin_test'), 'orange' => array('id' => 'orange', 'label' => 'Orange', 'color' => 'orange', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Orange', 'provider' => 'plugin_test'), 'extending_non_installed_class' => array('id' => 'extending_non_installed_class', 'label' => 'A plugin whose class is extending from a non-installed module class', 'color' => 'pink', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\ExtendingNonInstalledClass', 'provider' => 'plugin_test'));
     $base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src';
     $namespaces = new \ArrayObject(array('Drupal\\plugin_test' => $base_directory));
     $this->discovery = new AnnotatedClassDiscovery('', $namespaces);
     $empty_namespaces = new \ArrayObject();
     $this->emptyDiscovery = new AnnotatedClassDiscovery('', $empty_namespaces);
 }
 /**
  * Tests the output process.
  */
 public function testProcessOutbound()
 {
     $expected_cacheability = (new BubbleableMetadata())->addCacheContexts(['route'])->setCacheMaxAge(Cache::PERMANENT);
     $request_stack = \Drupal::requestStack();
     /** @var \Symfony\Component\Routing\RequestContext $request_context */
     $request_context = \Drupal::service('router.request_context');
     // Test request with subdir on homepage.
     $server = ['SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/subdir/', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<front>');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/subdir/');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
     // Test request with subdir on other page.
     $server = ['SCRIPT_NAME' => '/subdir/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/subdir/node/add', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'node.add');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/node/add'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/subdir/node/add');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
     // Test request without subdir on the homepage.
     $server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<front>');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
     // Test request without subdir on other page.
     $server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/node/add', 'GET', [], [], [], $server);
     $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'node.add');
     $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('/node/add'));
     $request_stack->push($request);
     $request_context->fromRequest($request);
     $url = GeneratedUrl::createFromObject($expected_cacheability)->setGeneratedUrl('/node/add');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
     // Test request without a found route. This happens for example on an
     // not found exception page.
     $server = ['SCRIPT_NAME' => '/index.php', 'SCRIPT_FILENAME' => \Drupal::root() . '/index.php', 'SERVER_NAME' => 'http://www.example.com'];
     $request = Request::create('/invalid-path', 'GET', [], [], [], $server);
     $request_stack->push($request);
     $request_context->fromRequest($request);
     // In case we have no routing, the current route should point to the front,
     // and the cacheability does not depend on the 'route' cache context, since
     // no route was involved at all: this is fallback behavior.
     $url = GeneratedUrl::createFromObject((new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT))->setGeneratedUrl('/');
     $this->assertEqual($url, $this->urlGenerator->generateFromRoute('<current>', [], [], TRUE));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->expectedDefinitions = array('apple' => array('id' => 'apple', 'label' => 'Apple', 'color' => 'green', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Apple', 'provider' => 'plugin_test'), 'banana' => array('id' => 'banana', 'label' => 'Banana', 'color' => 'yellow', 'uses' => array('bread' => t('Banana bread'), 'loaf' => array('singular' => '@count loaf', 'plural' => '@count loaves', 'context' => NULL)), 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Banana', 'provider' => 'plugin_test'), 'cherry' => array('id' => 'cherry', 'label' => 'Cherry', 'color' => 'red', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Cherry', 'provider' => 'plugin_test'), 'kale' => array('id' => 'kale', 'label' => 'Kale', 'color' => 'green', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Kale', 'provider' => 'plugin_test'), 'orange' => array('id' => 'orange', 'label' => 'Orange', 'color' => 'orange', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\Orange', 'provider' => 'plugin_test'), 'big_apple' => array('id' => 'big_apple', 'label' => 'Big Apple', 'color' => 'green', 'class' => 'Drupal\\plugin_test_extended\\Plugin\\plugin_test\\fruit\\BigApple', 'provider' => 'plugin_test_extended'), 'extending_non_installed_class' => array('id' => 'extending_non_installed_class', 'label' => 'A plugin whose class is extending from a non-installed module class', 'color' => 'pink', 'class' => 'Drupal\\plugin_test\\Plugin\\plugin_test\\fruit\\ExtendingNonInstalledClass', 'provider' => 'plugin_test'));
     $base_directory = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test/src';
     $base_directory2 = \Drupal::root() . '/core/modules/system/tests/modules/plugin_test_extended/src';
     $namespaces = new \ArrayObject(array('Drupal\\plugin_test' => $base_directory, 'Drupal\\plugin_test_extended' => $base_directory2));
     $annotation_namespaces = ['Drupal\\plugin_test\\Plugin\\Annotation', 'Drupal\\plugin_test_extended\\Plugin\\Annotation'];
     $this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/fruit', $namespaces, 'Drupal\\Component\\Annotation\\Plugin', $annotation_namespaces);
     $this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $namespaces);
 }
示例#27
0
 /**
  * @param string $type
  * @return \Drupal\Core\Extension\Extension[]
  */
 public function discoverExtensions($type = 'module')
 {
     $this->getDrupalHelper()->loadLegacyFile('/core/modules/system/system.module');
     system_rebuild_module_data();
     /*
      * @see Remove DrupalExtensionDiscovery subclass once
      * https://www.drupal.org/node/2503927 is fixed.
      */
     $discovery = new DrupalExtensionDiscovery(\Drupal::root());
     $discovery->reset();
     return $discovery->scan($type);
 }
示例#28
0
 /**
  * {@inheritdoc}
  */
 protected function getAllFolders()
 {
     if (!isset($this->folders)) {
         $this->folders = $this->getCoreNames();
         $listing = new ExtensionDiscovery(\Drupal::root());
         $listing->setProfileDirectories(array());
         $this->folders += $this->getComponentNames($listing->scan('profile'));
         $this->folders += $this->getComponentNames($listing->scan('module'));
         $this->folders += $this->getComponentNames($listing->scan('theme'));
     }
     return $this->folders;
 }
示例#29
0
 /**
  * Tests using entity fields of the image field type.
  */
 public function testImageItem()
 {
     // Create a test entity with the image field set.
     $entity = EntityTest::create();
     $entity->image_test->target_id = $this->image->id();
     $entity->image_test->alt = $alt = $this->randomMachineName();
     $entity->image_test->title = $title = $this->randomMachineName();
     $entity->name->value = $this->randomMachineName();
     $entity->save();
     $entity = entity_load('entity_test', $entity->id());
     $this->assertTrue($entity->image_test instanceof FieldItemListInterface, 'Field implements interface.');
     $this->assertTrue($entity->image_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
     $this->assertEqual($entity->image_test->target_id, $this->image->id());
     $this->assertEqual($entity->image_test->alt, $alt);
     $this->assertEqual($entity->image_test->title, $title);
     $image = $this->imageFactory->get('public://example.jpg');
     $this->assertEqual($entity->image_test->width, $image->getWidth());
     $this->assertEqual($entity->image_test->height, $image->getHeight());
     $this->assertEqual($entity->image_test->entity->id(), $this->image->id());
     $this->assertEqual($entity->image_test->entity->uuid(), $this->image->uuid());
     // Make sure the computed entity reflects updates to the referenced file.
     file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example-2.jpg');
     $image2 = File::create(['uri' => 'public://example-2.jpg']);
     $image2->save();
     $entity->image_test->target_id = $image2->id();
     $entity->image_test->alt = $new_alt = $this->randomMachineName();
     // The width and height is only updated when width is not set.
     $entity->image_test->width = NULL;
     $entity->save();
     $this->assertEqual($entity->image_test->entity->id(), $image2->id());
     $this->assertEqual($entity->image_test->entity->getFileUri(), $image2->getFileUri());
     $image = $this->imageFactory->get('public://example-2.jpg');
     $this->assertEqual($entity->image_test->width, $image->getWidth());
     $this->assertEqual($entity->image_test->height, $image->getHeight());
     $this->assertEqual($entity->image_test->alt, $new_alt);
     // Check that the image item can be set to the referenced file directly.
     $entity->image_test = $this->image;
     $this->assertEqual($entity->image_test->target_id, $this->image->id());
     // Delete the image and try to save the entity again.
     $this->image->delete();
     $entity = EntityTest::create(array('mame' => $this->randomMachineName()));
     $entity->save();
     // Test image item properties.
     $expected = array('target_id', 'entity', 'alt', 'title', 'width', 'height');
     $properties = $entity->getFieldDefinition('image_test')->getFieldStorageDefinition()->getPropertyDefinitions();
     $this->assertEqual(array_keys($properties), $expected);
     // Test the generateSampleValue() method.
     $entity = EntityTest::create();
     $entity->image_test->generateSampleItems();
     $this->entityValidateAndSave($entity);
     $this->assertEqual($entity->image_test->entity->get('filemime')->value, 'image/jpeg');
 }
 /**
  * {@inheritdoc}
  */
 protected function getAllFolders()
 {
     if (!isset($this->folders)) {
         $this->folders = $this->getComponentNames('core', array('core'));
         // @todo Refactor getComponentNames() to use the extension list directly.
         $listing = new ExtensionDiscovery(\Drupal::root());
         $listing->setProfileDirectories(array());
         $this->folders += $this->getComponentNames('profile', array_keys($listing->scan('profile')));
         $this->folders += $this->getComponentNames('module', array_keys($listing->scan('module')));
         $this->folders += $this->getComponentNames('theme', array_keys($listing->scan('theme')));
     }
     return $this->folders;
 }