Esempio n. 1
0
 /**
  * Tests block_example functionality.
  */
 public function testBlockExampleBasic()
 {
     // Login the admin user.
     $this->drupalLogin($this->webUser);
     $theme_name = \Drupal::config('system.theme')->get('default');
     // Verify the blocks are listed to be added.
     $this->drupalGet('admin/structure/block/list/' . $theme_name);
     $this->assertRaw(t('Title of first block (example_configurable_text)'), 'Block configurable-string found.');
     $this->assertRaw(t('Example: empty block'), 'Block empty-block found.');
     $this->assertRaw(t('Example: uppercase this please'), 'Block uppercase found.');
     // Define and place blocks.
     $settings_configurable = array('label' => t('Title of first block (example_configurable_text)'), 'id' => 'block_example_example_configurable_text', 'theme' => $theme_name);
     $this->drupalPlaceBlock('example_configurable_text', $settings_configurable);
     $settings_uppercase = array('label' => t('Configurable block to be uppercased'), 'id' => 'block_example_example_uppercased', 'theme' => $theme_name);
     $this->drupalPlaceBlock('example_uppercase', $settings_uppercase);
     $settings_empty = array('label' => t('Example: empty block'), 'id' => 'block_example_example_empty', 'theme' => $theme_name);
     $this->drupalPlaceBlock('example_empty', $settings_empty);
     // Verify that blocks are there. Empty block will not be shown, because it
     // is empty.
     $this->drupalGet('/');
     $this->assertRaw($settings_configurable['label'], 'Block configurable test not found.');
     $this->assertNoRaw($settings_uppercase['label'], 'Block uppercase with normal label not found.');
     $this->assertRaw(Unicode::strtoupper($settings_uppercase['label']), 'Block uppercase with uppercased label found.');
     $this->assertNoRaw($settings_empty['label'], 'Block empty not found.');
     // Change content of configurable text block.
     $edit = array('settings[block_example_string_text]' => $this->randomMachineName());
     $this->drupalPostForm('admin/structure/block/manage/' . $settings_configurable['id'], $edit, t('Save block'));
     // Verify that new content is shown.
     $this->drupalGet('/');
     $this->assertRaw($edit['settings[block_example_string_text]'], 'Content of configurable text block successfully verified.');
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public static function valueCallback(&$element, $input, FormStateInterface $form_state)
 {
     if ($input !== FALSE && $input !== NULL) {
         // Make sure element properties are set.
         $element['#allow_null'] = isset($element['#allow_null']) ? $element['#allow_null'] : FALSE;
         $element['#allow_opacity'] = isset($element['#allow_opacity']) ? $element['#allow_opacity'] : FALSE;
         // Normalize returned element values to a RGBA hex value.
         $val = '';
         if ($element['#allow_null'] && !empty($input['container']['transparent'])) {
             return '';
         } elseif ($element['#allow_null'] || $element['#allow_opacity']) {
             $val = Unicode::strtoupper($input['container']['hex']);
         } else {
             $val = Unicode::strtoupper($input['hex']);
         }
         if ($val[0] != '#') {
             $val = '#' . $val;
         }
         if ($element['#allow_opacity']) {
             $val .= ColorUtility::opacityToAlpha($input['container']['opacity']);
         }
         return $val;
     }
     return '';
 }
Esempio n. 3
0
 /**
  * Convert percent opacity to hex alpha.
  *
  * @param int $value
  *   Opacity as percentage (0 = transparent, 100 = fully opaque).
  *
  * @return string|null
  *   Opacity as HEX (#00 = transparent, #FF = fully opaque).
  */
 public static function opacityToAlpha($value)
 {
     if (!$value || $value < 0 || $value > 100) {
         return NULL;
     }
     return Unicode::strtoupper(str_pad(dechex(ceil($value / 100 * 255)), 2, '0', STR_PAD_LEFT));
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function compile(\Twig_Compiler $compiler)
 {
     $compiler->addDebugInfo($this);
     $options = $this->getNode('options');
     list($singular, $tokens) = $this->compileString($this->getNode('body'));
     $plural = NULL;
     if (NULL !== $this->getNode('plural')) {
         list($plural, $pluralTokens) = $this->compileString($this->getNode('plural'));
         $tokens = array_merge($tokens, $pluralTokens);
     }
     // Start writing with the function to be called.
     $compiler->write('echo ' . (empty($plural) ? 't' : '\\Drupal::translation()->formatPlural') . '(');
     // Move the count to the beginning of the parameters list.
     if (!empty($plural)) {
         $compiler->raw('abs(')->subcompile($this->getNode('count'))->raw('), ');
     }
     // Write the singular text parameter.
     $compiler->subcompile($singular);
     // Write the plural text parameter, if necessary.
     if (!empty($plural)) {
         $compiler->raw(', ')->subcompile($plural);
     }
     // Write any tokens found as an associative array parameter, otherwise just
     // leave as an empty array.
     $compiler->raw(', array(');
     foreach ($tokens as $token) {
         $compiler->string($token->getAttribute('placeholder'))->raw(' => ')->subcompile($token)->raw(', ');
     }
     $compiler->raw(')');
     // Write any options passed.
     if (!empty($options)) {
         $compiler->raw(', ')->subcompile($options);
     }
     // Write function closure.
     $compiler->raw(')');
     // Append translation debug markup, if necessary.
     if ($compiler->getEnvironment()->isDebug()) {
         $compiler->raw(" . '\n<!-- TRANSLATION: ");
         $compiler->subcompile($singular);
         if (!empty($plural)) {
             $compiler->raw(', PLURAL: ')->subcompile($plural);
         }
         if (!empty($options)) {
             foreach ($options->getKeyValuePairs() as $pair) {
                 $compiler->raw(', ' . Unicode::strtoupper($pair['key']->getAttribute('value')) . ': ')->subcompile($pair['value']);
             }
         }
         $compiler->raw(" -->\n'");
     }
     // End writing.
     $compiler->raw(";\n");
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function query($group_by = FALSE)
 {
     $this->fillValue();
     $condition_operator = empty($this->options['not']) ? '=' : '<>';
     if (count($this->value) > 1) {
         $conditions = $this->query->createConditionGroup(Unicode::strtoupper($this->operator));
         // $conditions will be NULL if there were errors in the query.
         if ($conditions) {
             foreach ($this->value as $value) {
                 $conditions->addCondition($this->realField, $value, $condition_operator);
             }
             $this->query->addConditionGroup($conditions);
         }
     } else {
         $this->query->addCondition($this->realField, reset($this->value), $condition_operator);
     }
 }
 /**
  * Tests the default glossary view.
  */
 public function testGlossaryView()
 {
     // Create a content type and add some nodes, with a non-random title.
     $type = $this->drupalCreateContentType();
     $nodes_per_char = array('d' => 1, 'r' => 4, 'u' => 10, 'p' => 2, 'a' => 3, 'l' => 6);
     $nodes_by_char = [];
     foreach ($nodes_per_char as $char => $count) {
         $setting = array('type' => $type->id());
         for ($i = 0; $i < $count; $i++) {
             $node = $setting;
             $node['title'] = $char . $this->randomString(3);
             $node = $this->drupalCreateNode($node);
             $nodes_by_char[$char][] = $node;
         }
     }
     // Execute glossary view
     $view = Views::getView('glossary');
     $view->setDisplay('attachment_1');
     $view->executeDisplay('attachment_1');
     // Check that the amount of nodes per char.
     foreach ($view->result as $item) {
         $this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records);
     }
     // Enable the glossary to be displayed.
     $view->storage->enable()->save();
     $this->container->get('router.builder')->rebuildIfNeeded();
     $url = Url::fromRoute('view.glossary.page_1');
     // Verify cache tags.
     $this->assertPageCacheContextsAndTags($url, ['timezone', 'languages:' . LanguageInterface::TYPE_CONTENT, 'languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url', 'user.node_grants:view', 'user.permissions', 'route'], ['config:views.view.glossary', 'node:' . $nodes_by_char['a'][0]->id(), 'node:' . $nodes_by_char['a'][1]->id(), 'node:' . $nodes_by_char['a'][2]->id(), 'node:1', 'node:16', 'node:2', 'node:21', 'node:6', 'node_list', 'user:0', 'user_list', 'rendered', 'config:user.role.anonymous']);
     // Check the actual page response.
     $this->drupalGet($url);
     $this->assertResponse(200);
     foreach ($nodes_per_char as $char => $count) {
         $href = Url::fromRoute('view.glossary.page_1', ['arg_0' => $char])->toString();
         $label = Unicode::strtoupper($char);
         // Get the summary link for a certain character. Filter by label and href
         // to ensure that both of them are correct.
         $result = $this->xpath('//a[contains(@href, :href) and normalize-space(text())=:label]/..', array(':href' => $href, ':label' => $label));
         $this->assertTrue(count($result));
         // The rendered output looks like "| (count)" so let's figure out the int.
         $result_count = trim(str_replace(array('|', '(', ')'), '', (string) $result[0]));
         $this->assertEqual($result_count, $count, 'The expected number got rendered.');
     }
 }
Esempio n. 7
0
 /**
  * Tests the default glossary view.
  */
 public function testGlossaryView()
 {
     // create a contentype and add some nodes, with a non random title.
     $type = $this->drupalCreateContentType();
     $nodes_per_char = array('d' => 1, 'r' => 4, 'u' => 10, 'p' => 2, 'a' => 3, 'l' => 6);
     foreach ($nodes_per_char as $char => $count) {
         $setting = array('type' => $type->type);
         for ($i = 0; $i < $count; $i++) {
             $node = $setting;
             $node['title'] = $char . $this->randomString(3);
             $this->drupalCreateNode($node);
         }
     }
     // Execute glossary view
     $view = Views::getView('glossary');
     $view->setDisplay('attachment_1');
     $view->executeDisplay('attachment_1');
     // Check that the amount of nodes per char.
     foreach ($view->result as $item) {
         $this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records);
     }
     // Enable the glossary to be displayed.
     $view->storage->enable()->save();
     // Check the actual page response.
     $this->drupalGet('glossary');
     $this->assertResponse(200);
     foreach ($nodes_per_char as $char => $count) {
         $href = url('glossary/' . $char);
         $label = Unicode::strtoupper($char);
         // Get the summary link for a certain character. Filter by label and href
         // to ensure that both of them are correct.
         $result = $this->xpath('//a[contains(@href, :href) and normalize-space(text())=:label]/..', array(':href' => $href, ':label' => $label));
         $this->assertTrue(count($result));
         // The rendered output looks like "| (count)" so let's figure out the int.
         $result_count = trim(str_replace(array('|', '(', ')'), '', (string) $result[0]));
         $this->assertEqual($result_count, $count, 'The expected number got rendered.');
     }
 }
Esempio n. 8
0
 /**
  * Transform a string by a certain method.
  *
  * @param $string
  *    The input you want to transform.
  * @param $option
  *    How do you want to transform it, possible values:
  *      - upper: Uppercase the string.
  *      - lower: lowercase the string.
  *      - ucfirst: Make the first char uppercase.
  *      - ucwords: Make each word in the string uppercase.
  *
  * @return string
  *    The transformed string.
  */
 protected function caseTransform($string, $option)
 {
     switch ($option) {
         default:
             return $string;
         case 'upper':
             return Unicode::strtoupper($string);
         case 'lower':
             return Unicode::strtolower($string);
         case 'ucfirst':
             return Unicode::ucfirst($string);
         case 'ucwords':
             return Unicode::ucwords($string);
     }
 }
Esempio n. 9
0
 /**
  * Determines if the provided classname is a unit test.
  *
  * @param $classname
  *   The test classname.
  *
  * @return bool
  *   TRUE if the class is a unit test. FALSE if not.
  */
 public static function isUnitTest($classname)
 {
     if (strpos($classname, 'Drupal\\Tests\\') === 0) {
         $namespace = explode('\\', $classname);
         $first_letter = Unicode::substr($namespace[2], 0, 1);
         if (Unicode::strtoupper($first_letter) === $first_letter) {
             // A core unit test.
             return TRUE;
         } elseif ($namespace[3] == 'Unit') {
             // A module unit test.
             return TRUE;
         }
     }
     return FALSE;
 }
Esempio n. 10
0
 /**
  * Tests multibyte strtoupper.
  *
  * @dataProvider providerStrtoupper
  * @covers ::strtoupper
  * @covers ::caseFlip
  */
 public function testStrtoupper($text, $expected, $multibyte = FALSE)
 {
     $status = $multibyte ? Unicode::STATUS_MULTIBYTE : Unicode::STATUS_SINGLEBYTE;
     Unicode::setStatus($status);
     $this->assertEquals($expected, Unicode::strtoupper($text));
 }
 /**
  * {@inheritdoc}
  */
 public function getSummary()
 {
     $summary = array('#markup' => Unicode::strtoupper($this->configuration['extension']));
     $summary += parent::getSummary();
     return $summary;
 }
Esempio n. 12
0
 /**
  * Test case sensitive and in-sensitive query conditions.
  */
 public function testCaseSensitivity()
 {
     $bundle = $this->randomMachineName();
     $field_storage = FieldStorageConfig::create(array('field_name' => 'field_ci', 'entity_type' => 'entity_test_mulrev', 'type' => 'string', 'cardinality' => 1, 'translatable' => FALSE, 'settings' => array('case_sensitive' => FALSE)));
     $field_storage->save();
     FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => $bundle))->save();
     $field_storage = FieldStorageConfig::create(array('field_name' => 'field_cs', 'entity_type' => 'entity_test_mulrev', 'type' => 'string', 'cardinality' => 1, 'translatable' => FALSE, 'settings' => array('case_sensitive' => TRUE)));
     $field_storage->save();
     FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => $bundle))->save();
     $fixtures = array();
     for ($i = 0; $i < 2; $i++) {
         // If the last 4 of the string are all numbers, then there is no
         // difference between upper and lowercase and the case sensitive CONTAINS
         // test will fail. Ensure that can not happen by appending a non-numeric
         // character. See https://www.drupal.org/node/2397297.
         $string = $this->randomMachineName(7) . 'a';
         $fixtures[] = array('original' => $string, 'uppercase' => Unicode::strtoupper($string), 'lowercase' => Unicode::strtolower($string));
     }
     EntityTestMulRev::create(array('type' => $bundle, 'name' => $this->randomMachineName(), 'langcode' => 'en', 'field_ci' => $fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 'field_cs' => $fixtures[0]['uppercase'] . $fixtures[1]['lowercase']))->save();
     // Check the case insensitive field, = operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['lowercase'] . $fixtures[1]['lowercase'])->execute();
     $this->assertIdentical(count($result), 1, 'Case insensitive, lowercase');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['uppercase'] . $fixtures[1]['uppercase'])->execute();
     $this->assertIdentical(count($result), 1, 'Case insensitive, uppercase');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['uppercase'] . $fixtures[1]['lowercase'])->execute();
     $this->assertIdentical(count($result), 1, 'Case insensitive, mixed.');
     // Check the case sensitive field, = operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['lowercase'] . $fixtures[1]['lowercase'])->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['uppercase'] . $fixtures[1]['uppercase'])->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, uppercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['uppercase'] . $fixtures[1]['lowercase'])->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case insensitive field, IN operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', array($fixtures[0]['lowercase'] . $fixtures[1]['lowercase']), 'IN')->execute();
     $this->assertIdentical(count($result), 1, 'Case insensitive, lowercase');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', array($fixtures[0]['uppercase'] . $fixtures[1]['uppercase']), 'IN')->execute();
     $this->assertIdentical(count($result), 1, 'Case insensitive, uppercase');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', array($fixtures[0]['uppercase'] . $fixtures[1]['lowercase']), 'IN')->execute();
     $this->assertIdentical(count($result), 1, 'Case insensitive, mixed');
     // Check the case sensitive field, IN operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', array($fixtures[0]['lowercase'] . $fixtures[1]['lowercase']), 'IN')->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, lowercase');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', array($fixtures[0]['uppercase'] . $fixtures[1]['uppercase']), 'IN')->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, uppercase');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', array($fixtures[0]['uppercase'] . $fixtures[1]['lowercase']), 'IN')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, mixed');
     // Check the case insensitive field, STARTS_WITH operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['lowercase'], 'STARTS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[0]['uppercase'], 'STARTS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case sensitive field, STARTS_WITH operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['lowercase'], 'STARTS_WITH')->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[0]['uppercase'], 'STARTS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case insensitive field, ENDS_WITH operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[1]['lowercase'], 'ENDS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', $fixtures[1]['uppercase'], 'ENDS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case sensitive field, ENDS_WITH operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[1]['lowercase'], 'ENDS_WITH')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', $fixtures[1]['uppercase'], 'ENDS_WITH')->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, exact match.');
     // Check the case insensitive field, CONTAINS operator, use the inner 8
     // characters of the uppercase and lowercase strings.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8), 'CONTAINS')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_ci', Unicode::strtolower(Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8)), 'CONTAINS')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, exact match.');
     // Check the case sensitive field, CONTAINS operator.
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8), 'CONTAINS')->execute();
     $this->assertIdentical(count($result), 1, 'Case sensitive, lowercase.');
     $result = \Drupal::entityQuery('entity_test_mulrev')->condition('field_cs', Unicode::strtolower(Unicode::substr($fixtures[0]['uppercase'] . $fixtures[1]['lowercase'], 4, 8)), 'CONTAINS')->execute();
     $this->assertIdentical(count($result), 0, 'Case sensitive, exact match.');
 }
Esempio n. 13
0
 protected function applyModifiers($string, $modifiers)
 {
     if (!is_null($string) || strlen($string)) {
         if ($modifiers) {
             $original_string = $string;
             $prefix = '';
             $suffix = '';
             if (preg_match('/^(<span[^>]*>)(.*)(<\\/span>)$/i', $string, $matches)) {
                 $prefix = $matches[1];
                 $string = $matches[2];
                 $suffix = $matches[3];
             }
             for ($j = 0; $j < strlen($modifiers); $j++) {
                 switch ($modifiers[$j]) {
                     case 'L':
                         $string = Unicode::strtolower($string);
                         break;
                     case 'U':
                         $string = Unicode::strtoupper($string);
                         break;
                     case 'F':
                         $string = Unicode::ucfirst($string);
                         break;
                     case 'G':
                         if (!empty($string)) {
                             $parts = explode(' ', $string);
                             $string = array();
                             foreach ($parts as $part) {
                                 $string[] = Unicode::ucfirst($part);
                             }
                             $string = implode(' ', $string);
                         }
                         break;
                     case 'T':
                         $string = trim($string);
                         break;
                     case 'S':
                         $string = SafeMarkup::checkPlain($string);
                         break;
                 }
             }
             $string = $prefix . $string . $suffix;
         }
     }
     return $string;
 }
Esempio n. 14
0
 /**
  * Convert a dec to a hex.
  *
  * @param int $dec
  *   an integer number
  *
  * @return string
  *   the number represented as hex
  */
 protected function dec2hex($dec)
 {
     $hex = dechex($dec);
     return str_repeat("0", 2 - Unicode::strlen($hex)) . Unicode::strtoupper($hex);
 }
Esempio n. 15
0
 /**
  * Formats the address for display based on the country's address format.
  *
  * @return string
  *   An HTML formatted string containing the address.
  */
 public function __toString()
 {
     $variables = array('!company' => $this->company, '!first_name' => $this->first_name, '!last_name' => $this->last_name, '!street1' => $this->street1, '!street2' => $this->street2, '!city' => $this->city, '!postal_code' => $this->postal_code);
     $country = $this->country ? \Drupal::service('country_manager')->getCountry($this->country) : NULL;
     if ($country) {
         $variables += array('!zone_code' => $this->zone ?: $this->t('N/A'), '!zone_name' => isset($country->getZones()[$this->zone]) ? $country->getZones()[$this->zone] : $this->t('Unknown'), '!country_name' => $this->t($country->getName()), '!country_code2' => $country->id(), '!country_code3' => $country->getAlpha3());
         if ($this->country != $this->default_country) {
             $variables['!country_name_if'] = $variables['!country_name'];
             $variables['!country_code2_if'] = $variables['!country_code2'];
             $variables['!country_code3_if'] = $variables['!country_code3'];
         } else {
             $variables['!country_name_if'] = '';
             $variables['!country_code2_if'] = '';
             $variables['!country_code3_if'] = '';
         }
         $format = implode("\n", $country->getAddressFormat());
     } else {
         $format = "!company\n!first_name !last_name\n!street1\n!street2\n!city\n!postal_code";
     }
     $address = Html::escape(strtr($format, $variables));
     $address = trim(trim(preg_replace("/\n+/", "\n", $address), "\n"), ' ');
     if (\Drupal::config('uc_store.settings')->get('capitalize_address')) {
         $address = Unicode::strtoupper($address);
     }
     // <br> instead of <br />, because Twig will change it to <br> anyway and it's nice
     // to be able to test the Raw output.
     return nl2br($address, FALSE);
 }
Esempio n. 16
0
 /**
  * Set database-engine specific properties for a field.
  *
  * @param $field
  *   A field description array, as specified in the schema documentation.
  */
 protected function processField($field)
 {
     if (!isset($field['size'])) {
         $field['size'] = 'normal';
     }
     // Set the correct database-engine specific datatype.
     // In case one is already provided, force it to uppercase.
     if (isset($field['sqlite_type'])) {
         $field['sqlite_type'] = Unicode::strtoupper($field['sqlite_type']);
     } else {
         $map = $this->getFieldTypeMap();
         $field['sqlite_type'] = $map[$field['type'] . ':' . $field['size']];
         // Numeric fields with a specified scale have to be stored as floats.
         if ($field['sqlite_type'] === 'NUMERIC' && isset($field['scale'])) {
             $field['sqlite_type'] = 'FLOAT';
         }
     }
     if (isset($field['type']) && $field['type'] == 'serial') {
         $field['auto_increment'] = TRUE;
     }
     return $field;
 }
Esempio n. 17
0
 /**
  * Tests alias functionality through the node interfaces.
  */
 function testNodeAlias()
 {
     // Create test node.
     $node1 = $this->drupalCreateNode();
     // Create alias.
     $edit = array();
     $edit['path[0][alias]'] = '/' . $this->randomMachineName(8);
     $this->drupalPostForm('node/' . $node1->id() . '/edit', $edit, t('Save'));
     // Confirm that the alias works.
     $this->drupalGet($edit['path[0][alias]']);
     $this->assertText($node1->label(), 'Alias works.');
     $this->assertResponse(200);
     // Confirm the 'canonical' and 'shortlink' URLs.
     $elements = $this->xpath("//link[contains(@rel, 'canonical') and contains(@href, '" . $edit['path[0][alias]'] . "')]");
     $this->assertTrue(!empty($elements), 'Page contains canonical link URL.');
     $elements = $this->xpath("//link[contains(@rel, 'shortlink') and contains(@href, 'node/" . $node1->id() . "')]");
     $this->assertTrue(!empty($elements), 'Page contains shortlink URL.');
     $previous = $edit['path[0][alias]'];
     // Change alias to one containing "exotic" characters.
     $edit['path[0][alias]'] = '/alias' . "- ._~!\$'\"()*@[]?&+%#,;=:" . "%23%25%26%2B%2F%3F" . "中國書۞";
     $connection = Database::getConnection();
     if ($connection->databaseType() != 'sqlite') {
         // When using LIKE for case-insensitivity, the SQLite driver is
         // currently unable to find the upper-case versions of non-ASCII
         // characters.
         // @todo fix this in https://www.drupal.org/node/2607432
         $edit['path[0][alias]'] .= "ïвβéø";
     }
     $this->drupalPostForm('node/' . $node1->id() . '/edit', $edit, t('Save'));
     // Confirm that the alias works.
     $this->drupalGet(Unicode::strtoupper($edit['path[0][alias]']));
     $this->assertText($node1->label(), 'Changed alias works.');
     $this->assertResponse(200);
     // Make sure that previous alias no longer works.
     $this->drupalGet($previous);
     $this->assertNoText($node1->label(), 'Previous alias no longer works.');
     $this->assertResponse(404);
     // Create second test node.
     $node2 = $this->drupalCreateNode();
     // Set alias to second test node.
     // Leave $edit['path[0][alias]'] the same.
     $this->drupalPostForm('node/' . $node2->id() . '/edit', $edit, t('Save'));
     // Confirm that the alias didn't make a duplicate.
     $this->assertText(t('The alias is already in use.'), 'Attempt to moved alias was rejected.');
     // Delete alias.
     $this->drupalPostForm('node/' . $node1->id() . '/edit', array('path[0][alias]' => ''), t('Save'));
     // Confirm that the alias no longer works.
     $this->drupalGet($edit['path[0][alias]']);
     $this->assertNoText($node1->label(), 'Alias was successfully deleted.');
     $this->assertResponse(404);
     // Create third test node.
     $node3 = $this->drupalCreateNode();
     // Set its path alias to an absolute path.
     $edit = array('path[0][alias]' => '/' . $this->randomMachineName(8));
     $this->drupalPostForm('node/' . $node3->id() . '/edit', $edit, t('Save'));
     // Confirm that the alias was converted to a relative path.
     $this->drupalGet(trim($edit['path[0][alias]'], '/'));
     $this->assertText($node3->label(), 'Alias became relative.');
     $this->assertResponse(200);
     // Create fourth test node.
     $node4 = $this->drupalCreateNode();
     // Set its path alias to have a trailing slash.
     $edit = array('path[0][alias]' => '/' . $this->randomMachineName(8) . '/');
     $this->drupalPostForm('node/' . $node4->id() . '/edit', $edit, t('Save'));
     // Confirm that the alias was converted to a relative path.
     $this->drupalGet(trim($edit['path[0][alias]'], '/'));
     $this->assertText($node4->label(), 'Alias trimmed trailing slash.');
     $this->assertResponse(200);
 }
Esempio n. 18
0
 /**
  * Set database-engine specific properties for a field.
  *
  * @param $field
  *   A field description array, as specified in the schema documentation.
  */
 protected function processField($field)
 {
     if (!isset($field['size'])) {
         $field['size'] = 'normal';
     }
     // Set the correct database-engine specific datatype.
     // In case one is already provided, force it to uppercase.
     if (isset($field['mysql_type'])) {
         $field['mysql_type'] = Unicode::strtoupper($field['mysql_type']);
     } else {
         $map = $this->getFieldTypeMap();
         $field['mysql_type'] = $map[$field['type'] . ':' . $field['size']];
     }
     if (isset($field['type']) && $field['type'] == 'serial') {
         $field['auto_increment'] = TRUE;
     }
     return $field;
 }
Esempio n. 19
0
 /**
  * Test that text separated by block-level tags in HTML get separated by
  * (at least) a newline in the plaintext version.
  */
 public function testDrupalHtmlToTextBlockTagToNewline()
 {
     $input = '[text]' . '<blockquote>[blockquote]</blockquote>' . '<br />[br]' . '<dl><dt>[dl-dt]</dt>' . '<dt>[dt]</dt>' . '<dd>[dd]</dd>' . '<dd>[dd-dl]</dd></dl>' . '<h1>[h1]</h1>' . '<h2>[h2]</h2>' . '<h3>[h3]</h3>' . '<h4>[h4]</h4>' . '<h5>[h5]</h5>' . '<h6>[h6]</h6>' . '<hr />[hr]' . '<ol><li>[ol-li]</li>' . '<li>[li]</li>' . '<li>[li-ol]</li></ol>' . '<p>[p]</p>' . '<ul><li>[ul-li]</li>' . '<li>[li-ul]</li></ul>' . '[text]';
     $output = MailFormatHelper::htmlToText($input);
     $pass = $this->assertFalse(preg_match('/\\][^\\n]*\\[/s', $output), 'Block-level HTML tags should force newlines');
     if (!$pass) {
         $this->verbose($this->stringToHtml($output));
     }
     $output_upper = Unicode::strtoupper($output);
     $upper_input = Unicode::strtoupper($input);
     $upper_output = MailFormatHelper::htmlToText($upper_input);
     $pass = $this->assertEqual($upper_output, $output_upper, 'Tag recognition should be case-insensitive');
     if (!$pass) {
         $this->verbose($upper_output . '<br />should  be equal to <br />' . $output_upper);
     }
 }
Esempio n. 20
0
 public function testOrderCustomerView()
 {
     $order = $this->ucCreateOrder($this->customer);
     $this->drupalLogin($this->customer);
     $this->drupalGet('user/' . $this->customer->id() . '/orders');
     $this->assertText(t('My order history'));
     $this->drupalGet('user/' . $this->customer->id() . '/orders/' . $order->id());
     $this->assertResponse(200, 'Customer can view their own order.');
     $address = $order->getAddress('billing');
     $this->assertText(Unicode::strtoupper($address->first_name . ' ' . $address->last_name), 'Found customer name.');
     $this->drupalGet('admin/store/orders/' . $order->id());
     $this->assertResponse(403, 'Customer may not see the admin view of their order.');
     $this->drupalGet('admin/store/orders/' . $order->id() . '/edit');
     $this->assertResponse(403, 'Customer may not edit orders.');
 }