Commit 9eac4460 authored by alexpott's avatar alexpott

Issue #1676910 by cs_shadow, penyaskito, lokeoke | xjm: Rename randomName() to randomMachineName().

parent 22835842
......@@ -41,7 +41,7 @@ function testActionConfiguration() {
// Make a POST request to the individual action configuration page.
$edit = array();
$action_label = $this->randomName();
$action_label = $this->randomMachineName();
$edit['label'] = $action_label;
$edit['id'] = strtolower($action_label);
$edit['url'] = 'admin';
......@@ -57,7 +57,7 @@ function testActionConfiguration() {
preg_match('|admin/config/system/actions/configure/(.+)|', $this->getUrl(), $matches);
$aid = $matches[1];
$edit = array();
$new_action_label = $this->randomName();
$new_action_label = $this->randomMachineName();
$edit['label'] = $new_action_label;
$edit['url'] = 'admin';
$this->drupalPostForm(NULL, $edit, t('Save'));
......
......@@ -85,7 +85,7 @@ function deleteFeed(FeedInterface $feed) {
* A feed array.
*/
function getFeedEditArray($feed_url = NULL, array $edit = array()) {
$feed_name = $this->randomName(10);
$feed_name = $this->randomMachineName(10);
if (!$feed_url) {
$feed_url = url('rss.xml', array(
'query' => array('feed' => $feed_name),
......@@ -113,7 +113,7 @@ function getFeedEditArray($feed_url = NULL, array $edit = array()) {
* A feed object.
*/
function getFeedEditObject($feed_url = NULL, array $values = array()) {
$feed_name = $this->randomName(10);
$feed_name = $this->randomMachineName(10);
if (!$feed_url) {
$feed_url = url('rss.xml', array(
'query' => array('feed' => $feed_name),
......@@ -326,8 +326,8 @@ function createSampleNodes($count = 5) {
// Post $count article nodes.
for ($i = 0; $i < $count; $i++) {
$edit = array();
$edit['title[0][value]'] = $this->randomName();
$edit['body[0][value]'] = $this->randomName();
$edit['title[0][value]'] = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomMachineName();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
}
}
......
......@@ -81,7 +81,7 @@ function testHtmlEntitiesSample() {
function testRedirectFeed() {
// Simulate a typo in the URL to force a curl exception.
$invalid_url = url('aggregator/redirect', array('absolute' => TRUE));
$feed = entity_create('aggregator_feed', array('url' => $invalid_url, 'title' => $this->randomName()));
$feed = entity_create('aggregator_feed', array('url' => $invalid_url, 'title' => $this->randomMachineName()));
$feed->save();
$feed->refreshItems();
......@@ -95,7 +95,7 @@ function testRedirectFeed() {
function testInvalidFeed() {
// Simulate a typo in the URL to force a curl exception.
$invalid_url = 'http:/www.drupal.org';
$feed = entity_create('aggregator_feed', array('url' => $invalid_url, 'title' => $this->randomName()));
$feed = entity_create('aggregator_feed', array('url' => $invalid_url, 'title' => $this->randomMachineName()));
$feed->save();
// Update the feed. Use the UI to be able to check the message easily.
......
......@@ -63,11 +63,11 @@ protected function setUp() {
*/
public function testAggregatorItemView() {
$feed = $this->feedStorage->create(array(
'title' => $this->randomName(),
'title' => $this->randomMachineName(),
'url' => 'http://drupal.org/',
'refresh' => 900,
'checked' => 123543535,
'description' => $this->randomName(),
'description' => $this->randomMachineName(),
));
$feed->save();
......@@ -77,10 +77,10 @@ public function testAggregatorItemView() {
$values = array();
$values['fid'] = $feed->id();
$values['timestamp'] = mt_rand(REQUEST_TIME - 10, REQUEST_TIME + 10);
$values['title'] = $this->randomName();
$values['description'] = $this->randomName();
$values['title'] = $this->randomMachineName();
$values['description'] = $this->randomMachineName();
// Add a image to ensure that the sanitizing can be tested below.
$values['author'] = $this->randomName() . '<img src="http://example.com/example.png" \>"';
$values['author'] = $this->randomMachineName() . '<img src="http://example.com/example.png" \>"';
$values['link'] = 'http://drupal.org/node/' . mt_rand(1000, 10000);
$values['guid'] = $this->randomString();
......
......@@ -34,7 +34,7 @@ public function testBasicAuth() {
$this->assertResponse('200', 'HTTP response is OK');
$this->curlClose();
$this->basicAuthGet('router_test/test11', $account->getUsername(), $this->randomName());
$this->basicAuthGet('router_test/test11', $account->getUsername(), $this->randomMachineName());
$this->assertNoText($account->getUsername(), 'Bad basic auth credentials do not authenticate the user.');
$this->assertResponse('403', 'Access is not granted.');
$this->curlClose();
......
......@@ -64,7 +64,7 @@ function testCachePerRole() {
));
// Enable our test block. Set some content for it to display.
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalLogin($this->normal_user);
$this->drupalGet('');
......@@ -72,7 +72,7 @@ function testCachePerRole() {
// Change the content, but the cached copy should still be served.
$old_content = $current_content;
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('');
$this->assertText($old_content, 'Block is served from the cache.');
......@@ -85,7 +85,7 @@ function testCachePerRole() {
// Test whether the cached data is served for the correct users.
$old_content = $current_content;
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalLogout();
$this->drupalGet('');
......@@ -112,14 +112,14 @@ function testCacheGlobal() {
'max_age' => 600,
));
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('');
$this->assertText($current_content, 'Block content displays.');
$old_content = $current_content;
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalLogout();
......@@ -135,7 +135,7 @@ function testNoCache() {
'max_age' => 0,
));
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
// If max_age = 0 has no effect, the next request would be cached.
......@@ -143,7 +143,7 @@ function testNoCache() {
$this->assertText($current_content, 'Block content displays.');
// A cached copy should not be served.
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('');
$this->assertText($current_content, 'Maximum age of zero prevents blocks from being cached.');
......@@ -158,7 +158,7 @@ function testCachePerUser() {
'contexts' => array('cache_context.user'),
));
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalLogin($this->normal_user);
......@@ -166,7 +166,7 @@ function testCachePerUser() {
$this->assertText($current_content, 'Block content displays.');
$old_content = $current_content;
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('');
......@@ -190,14 +190,14 @@ function testCachePerPage() {
'contexts' => array('cache_context.url'),
));
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('test-page');
$this->assertText($current_content, 'Block content displays on the test page.');
$old_content = $current_content;
$current_content = $this->randomName();
$current_content = $this->randomMachineName();
\Drupal::state()->set('block_test.content', $current_content);
$this->drupalGet('user');
......
......@@ -65,7 +65,7 @@ protected function setUp() {
*/
public function testBlockConfigSchema() {
foreach ($this->blockManager->getDefinitions() as $block_id => $definition) {
$id = strtolower($this->randomName());
$id = strtolower($this->randomMachineName());
$block = Block::create(array(
'id' => $id,
'theme' => 'stark',
......@@ -74,7 +74,7 @@ public function testBlockConfigSchema() {
'region' => 'content',
'plugin' => $block_id,
'settings' => array(
'label' => $this->randomName(),
'label' => $this->randomMachineName(),
'provider' => 'system',
'label_display' => FALSE,
),
......
......@@ -42,7 +42,7 @@ public function setUp() {
public function testBlockOperationAlter() {
// Add a test block, any block will do.
// Set the machine name so the test_operation link can be built later.
$block_id = Unicode::strtolower($this->randomName(16));
$block_id = Unicode::strtolower($this->randomMachineName(16));
$this->drupalPlaceBlock('system_powered_by_block', array('id' => $block_id));
// Get the Block listing.
......
......@@ -30,7 +30,7 @@ function setUp() {
// Enable the test_html block, to test HTML ID and attributes.
\Drupal::state()->set('block_test.attributes', array('data-custom-attribute' => 'foo'));
\Drupal::state()->set('block_test.content', $this->randomName());
\Drupal::state()->set('block_test.content', $this->randomMachineName());
$this->drupalPlaceBlock('test_html', array('id' => 'test_html_block'));
// Enable a menu block, to test more complicated HTML.
......
......@@ -65,7 +65,7 @@ public function testBlockLinks() {
}
// Create a menu in the default language.
$edit['label'] = $this->randomName();
$edit['label'] = $this->randomMachineName();
$edit['id'] = Unicode::strtolower($edit['label']);
$this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
$this->assertText(t('Menu @label has been added.', array('@label' => $edit['label'])));
......
......@@ -57,7 +57,7 @@ public function testLanguageBlockVisibility() {
// Enable a standard block and set the visibility setting for one language.
$edit = array(
'settings[visibility][language][langcodes][en]' => TRUE,
'id' => strtolower($this->randomName(8)),
'id' => strtolower($this->randomMachineName(8)),
'region' => 'sidebar_first',
);
$this->drupalPostForm('admin/structure/block/add/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block'));
......
......@@ -24,11 +24,11 @@ class BlockTest extends BlockTestBase {
function testBlockVisibility() {
$block_name = 'system_powered_by_block';
// Create a random title for the block.
$title = $this->randomName(8);
$title = $this->randomMachineName(8);
// Enable a standard block.
$default_theme = \Drupal::config('system.theme')->get('default');
$edit = array(
'id' => strtolower($this->randomName(8)),
'id' => strtolower($this->randomMachineName(8)),
'region' => 'sidebar_first',
'settings[label]' => $title,
);
......@@ -65,11 +65,11 @@ function testBlockVisibility() {
function testBlockVisibilityListedEmpty() {
$block_name = 'system_powered_by_block';
// Create a random title for the block.
$title = $this->randomName(8);
$title = $this->randomMachineName(8);
// Enable a standard block.
$default_theme = \Drupal::config('system.theme')->get('default');
$edit = array(
'id' => strtolower($this->randomName(8)),
'id' => strtolower($this->randomMachineName(8)),
'region' => 'sidebar_first',
'settings[label]' => $title,
'settings[visibility][request_path][negate]' => TRUE,
......@@ -98,7 +98,7 @@ function testBlock() {
// Select the 'Powered by Drupal' block to be configured and moved.
$block = array();
$block['id'] = 'system_powered_by_block';
$block['settings[label]'] = $this->randomName(8);
$block['settings[label]'] = $this->randomMachineName(8);
$block['theme'] = \Drupal::config('system.theme')->get('default');
$block['region'] = 'header';
......@@ -161,7 +161,7 @@ public function testBlockThemeSelector() {
$this->assertTitle(t('Block layout') . ' | Drupal');
// Select the 'Powered by Drupal' block to be placed.
$block = array();
$block['id'] = strtolower($this->randomName());
$block['id'] = strtolower($this->randomMachineName());
$block['theme'] = $theme;
$block['region'] = 'content';
$this->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, t('Save block'));
......@@ -198,8 +198,8 @@ function testThemeName() {
function testHideBlockTitle() {
$block_name = 'system_powered_by_block';
// Create a random title for the block.
$title = $this->randomName(8);
$id = strtolower($this->randomName(8));
$title = $this->randomMachineName(8);
$id = strtolower($this->randomMachineName(8));
// Enable a standard block.
$default_theme = \Drupal::config('system.theme')->get('default');
$edit = array(
......
......@@ -33,7 +33,7 @@ protected function setUp() {
* Test XSS in title.
*/
function testXSSInTitle() {
\Drupal::state()->set('block_test.content', $this->randomName());
\Drupal::state()->set('block_test.content', $this->randomMachineName());
$this->drupalGet('');
$this->assertNoRaw('<script>alert("XSS label");</script>', 'The block title was properly sanitized when rendered.');
......
......@@ -194,7 +194,7 @@ public function testMachineNameSuggestion() {
public function testBlockPlacementIndicator() {
// Select the 'Powered by Drupal' block to be placed.
$block = array();
$block['id'] = strtolower($this->randomName());
$block['id'] = strtolower($this->randomMachineName());
$block['theme'] = 'stark';
$block['region'] = 'content';
......
......@@ -225,7 +225,7 @@ public function testBlockViewBuilderAlter() {
$this->setBlockCacheConfig(array(
'max_age' => 600,
));
$alter_add_key = $this->randomName();
$alter_add_key = $this->randomMachineName();
\Drupal::state()->set('block_test_view_alter_cache_key', $alter_add_key);
$expected_keys = array_merge($default_keys, array($alter_add_key));
$build = $this->getBlockRenderArray();
......@@ -239,7 +239,7 @@ public function testBlockViewBuilderAlter() {
$this->container->get('cache.render')->delete($cid);
// Advanced: cached block, but an alter hook adds an additional cache tag.
$alter_add_tag = $this->randomName();
$alter_add_tag = $this->randomMachineName();
\Drupal::state()->set('block_test_view_alter_cache_tag', $alter_add_tag);
$expected_tags = NestedArray::mergeDeep($default_tags, array($alter_add_tag => TRUE));
$build = $this->getBlockRenderArray();
......
......@@ -31,15 +31,15 @@ function testNewDefaultThemeBlocks() {
// Add two instances of the user login block.
$this->drupalPlaceBlock('user_login_block', array(
'id' => $default_theme . '_' . strtolower($this->randomName(8)),
'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)),
));
$this->drupalPlaceBlock('user_login_block', array(
'id' => $default_theme . '_' . strtolower($this->randomName(8)),
'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)),
));
// Add an instance of a different block.
$this->drupalPlaceBlock('system_powered_by_block', array(
'id' => $default_theme . '_' . strtolower($this->randomName(8)),
'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)),
));
// Enable a different theme.
......
......@@ -52,7 +52,7 @@ public function testBlockCategory() {
// Create a new view in the UI.
$edit = array();
$edit['label'] = $this->randomString();
$edit['id'] = strtolower($this->randomName());
$edit['id'] = strtolower($this->randomMachineName());
$edit['show[wizard_key]'] = 'standard:views_test_data';
$edit['description'] = $this->randomString();
$edit['block[create]'] = TRUE;
......
......@@ -89,7 +89,7 @@ public function testConditionsBagInitialization() {
$this->assertEquals(4, $conditions_bag->count(), "There are 4 condition plugins");
$instance_id = $this->randomName();
$instance_id = $this->randomMachineName();
$pages = 'node/1';
$condition_config = array('id' => 'request_path', 'pages' => $pages);
$block_base->setVisibilityConfig($instance_id, $condition_config);
......
......@@ -49,7 +49,7 @@ class BlockConfigEntityUnitTest extends UnitTestCase {
* {@inheritdoc}
*/
public function setUp() {
$this->entityTypeId = $this->randomName();
$this->entityTypeId = $this->randomMachineName();
$this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$this->entityType->expects($this->any())
......@@ -81,7 +81,7 @@ public function testCalculateDependencies() {
->setMethods(array('getPluginBags'))
->getMock();
// Create a configurable plugin that would add a dependency.
$instance_id = $this->randomName();
$instance_id = $this->randomMachineName();
$instance = new TestConfigurablePlugin(array(), $instance_id, array('provider' => 'test'));
// Create a plugin bag to contain the instance.
......
......@@ -72,7 +72,7 @@ public function setUpDisplayVariant($configuration = array(), $definition = arra
* @covers ::getRegionAssignments
*/
public function testBuild() {
$theme = $this->randomName();
$theme = $this->randomMachineName();
$display_variant = $this->setUpDisplayVariant();
$this->themeNegotiator->expects($this->any())
->method('determineActiveTheme')
......
......@@ -53,7 +53,7 @@ public function testBlockContentCreation() {
// Create a block.
$edit = array();
$edit['info[0][value]'] = 'Test Block';
$edit['body[0][value]'] = $this->randomName(16);
$edit['body[0][value]'] = $this->randomMachineName(16);
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
// Check that the Basic block has been created.
......@@ -97,8 +97,8 @@ public function testBlockContentCreation() {
*/
public function testDefaultBlockContentCreation() {
$edit = array();
$edit['info[0][value]'] = $this->randomName(8);
$edit['body[0][value]'] = $this->randomName(16);
$edit['info[0][value]'] = $this->randomMachineName(8);
$edit['body[0][value]'] = $this->randomMachineName(16);
// Don't pass the custom block type in the url so the default is forced.
$this->drupalPostForm('block/add', $edit, t('Save'));
......@@ -157,8 +157,8 @@ public function testFailedBlockCreation() {
public function testBlockDelete() {
// Create a block.
$edit = array();
$edit['info[0][value]'] = $this->randomName(8);
$body = $this->randomName(16);
$edit['info[0][value]'] = $this->randomMachineName(8);
$body = $this->randomMachineName(16);
$edit['body[0][value]'] = $body;
$this->drupalPostForm('block/add/basic', $edit, t('Save'));
......@@ -190,8 +190,8 @@ public function testBlockDelete() {
// Create another block and force the plugin cache to flush.
$edit2 = array();
$edit2['info[0][value]'] = $this->randomName(8);
$body2 = $this->randomName(16);
$edit2['info[0][value]'] = $this->randomMachineName(8);
$body2 = $this->randomMachineName(16);
$edit2['body[0][value]'] = $body2;
$this->drupalPostForm('block/add/basic', $edit2, t('Save'));
......@@ -200,8 +200,8 @@ public function testBlockDelete() {
// Create another block with no instances, and test we don't get a
// confirmation message about deleting instances.
$edit3 = array();
$edit3['info[0][value]'] = $this->randomName(8);
$body = $this->randomName(16);
$edit3['info[0][value]'] = $this->randomMachineName(8);
$body = $this->randomMachineName(16);
$edit3['body[0][value]'] = $body;
$this->drupalPostForm('block/add/basic', $edit3, t('Save'));
......
......@@ -55,7 +55,7 @@ public function testBlockFields() {
// Create a field with settings to validate.
$this->fieldStorage = entity_create('field_storage_config', array(
'name' => drupal_strtolower($this->randomName()),
'name' => drupal_strtolower($this->randomMachineName()),
'entity_type' => 'block_content',
'type' => 'link',