commit e9b2ed3179ebba405a4dffac621f086f98842dc9 Author: xjm Date: Sat Jan 5 07:24:19 2013 -0600 11 diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php index 979caeb..1f13232 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorRenderingTest.php @@ -55,7 +55,7 @@ public function testBlockLinks() { 'title' => 'feed-' . $feed->title, 'block_count' => 2, ); - $this->drupalPlaceBlock("aggregator_feed_block:{$feed->fid}", NULL, $block); + $this->drupalPlaceBlock("aggregator_feed_block:{$feed->fid}", $block); // Confirm that the block is now being displayed on pages. $this->drupalGet('node'); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/ImportOpmlTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/ImportOpmlTest.php index cfe5d33..7a9f463 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/ImportOpmlTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/ImportOpmlTest.php @@ -49,7 +49,7 @@ function openImportForm() { ->execute(); // Enable the help block. - $this->drupalPlaceBlock('system_help_block', NULL, array('region' => 'help')); + $this->drupalPlaceBlock('system_help_block', array('region' => 'help')); $this->drupalGet('admin/config/services/aggregator/add/opml'); $this->assertText('A single OPML document may contain a collection of many feeds.', 'Found OPML help text.'); diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php index b4960ad..e0d37da 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php @@ -46,7 +46,7 @@ function setUp() { state()->set('block_test.content', $current_content); // Enable our test block. - $this->drupalPlaceBlock('test_html_id', '', array('machine_name' => 'test_id_block')); + $this->drupalPlaceBlock('test_html_id', array('machine_name' => 'test_id_block')); } /** diff --git a/core/modules/book/lib/Drupal/book/Tests/BookTest.php b/core/modules/book/lib/Drupal/book/Tests/BookTest.php index 452a639..16c8ae3 100644 --- a/core/modules/book/lib/Drupal/book/Tests/BookTest.php +++ b/core/modules/book/lib/Drupal/book/Tests/BookTest.php @@ -331,7 +331,7 @@ function testBookNavigationBlock() { */ function testNavigationBlockOnAccessModuleEnabled() { $this->drupalLogin($this->admin_user); - $block = $this->drupalPlaceBlock('book_navigation', '', array('book_block_mode' => 'book pages')); + $block = $this->drupalPlaceBlock('book_navigation', array('book_block_mode' => 'book pages')); // Give anonymous users the permission 'node test view'. $edit = array(); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php index 8a7edde..d4d3fe6 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentBlockTest.php @@ -46,7 +46,7 @@ public static function getInfo() { */ function testRecentCommentBlock() { $this->drupalLogin($this->admin_user); - $block = $this->drupalPlaceBlock('recent_comments', NULL, array('block_count' => 2)); + $block = $this->drupalPlaceBlock('recent_comments', array('block_count' => 2)); // Add some test comments, one without a subject. $comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName()); diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php index 1efaeae..de28051 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php @@ -57,17 +57,8 @@ public function testNewForumTopicsBlock() { // Create 5 forum topics. $topics = $this->createForumTopics(); - $block_id = 'forum_new_block'; - $default_theme = variable_get('theme_default', 'stark'); - - $block = array( - 'title' => $this->randomName(8), - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_second', - ); - // Enable the new forum topics block. - $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); + $block = $this->drupalPlaceBlock('forum_new_block'); $this->assertText(t('The block configuration has been saved.'), '"New forum topics" block was enabled'); $this->assertLink(t('More'), 0, 'New forum topics block has a "more"-link.'); @@ -79,7 +70,6 @@ public function testNewForumTopicsBlock() { } // Configure the new forum topics block to only show 2 topics. - $block['config_id'] = 'plugin.core.block.' . $default_theme . '.' . $block['machine_name']; $config = config($block['config_id']); $config->set('block_count', 2); $config->save(); @@ -122,19 +112,7 @@ public function testActiveForumTopicsBlock() { } // Enable the block. - $block_id = 'forum_active_block'; - $default_theme = variable_get('theme_default', 'stark'); - - $block = array( - 'title' => $this->randomName(8), - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_second', - ); - - // Enable the active forum block. - $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); - $this->assertText(t('The block configuration has been saved.'), 'Active forum topics forum block was enabled'); - + $block = $this->drupalPlaceBlock('forum_active_block'); $this->assertLink(t('More'), 0, 'Active forum topics block has a "more"-link.'); $this->assertLinkByHref('forum', 0, 'Active forum topics block has a "more"-link.'); @@ -151,7 +129,6 @@ public function testActiveForumTopicsBlock() { } // Configure the active forum block to only show 2 topics. - $block['config_id'] = 'plugin.core.block.' . $default_theme . '.' . $block['machine_name']; $config = config($block['config_id']); $config->set('block_count', 2); $config->save(); diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php index 5d3594a..e619923 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php @@ -75,26 +75,10 @@ function testForumNodeAccess() { $public_node = $this->drupalGetNodeByTitle($public_node_title); $this->assertTrue(!empty($public_node), 'New public forum node found in database.'); - $default_theme = variable_get('theme_default', 'stark'); - // Enable the active forum block. - $block_id = 'forum_active_block'; - $block = array( - 'title' => $this->randomName(8), - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_second', - ); - $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); - $this->assertText(t('The block configuration has been saved.'), 'Active forum topics block enabled'); - - // Enable the new forum block. - $block_id = 'forum_new_block'; - $block = array( - 'title' => $this->randomName(8), - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_second', - ); - $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); - $this->assertText(t('The block configuration has been saved.'), 'New forum topics block enabled'); + + // Enable the new and active forum blocks. + $this->drupalPlaceBlock('forum_active_block'); + $this->drupalPlaceBlock('forum_new_block'); // Test for $access_user. $this->drupalLogin($access_user); @@ -112,4 +96,5 @@ function testForumNodeAccess() { $this->assertNoText($private_node->title, 'Private node not found in block by $no_access_user'); $this->assertText($public_node->title, 'Public node found in block by $no_access_user'); } + } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php index 6ff3024..8effdfe 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php @@ -42,16 +42,7 @@ function setUp() { */ function testLanguageBlock() { // Enable the language switching block. - $language_type = LANGUAGE_TYPE_INTERFACE; - $block_id = 'language_block:' . $language_type; - $default_theme = variable_get('theme_default', 'stark'); - $block = array( - 'title' => $this->randomName(8), - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_first', - ); - $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); - $this->assertText(t('The block configuration has been saved.'), 'Block enabled'); + $block = $this->drupalPlaceBlock('language_block:' . LANGUAGE_TYPE_INTERFACE, array('machine_name' => 'test_language_block')); // Add language. $edit = array( @@ -65,10 +56,10 @@ function testLanguageBlock() { // Assert that the language switching block is displayed on the frontpage. $this->drupalGet(''); - $this->assertText($block['title'], 'Language switcher block found.'); + $this->assertText($block['subject'], 'Language switcher block found.'); // Assert that only the current language is marked as active. - list($language_switcher) = $this->xpath('//div[@id=:id]/div[@class="content"]', array(':id' => 'block-' . strtolower($block['machine_name']))); + list($language_switcher) = $this->xpath('//div[@id=:id]/div[@class="content"]', array(':id' => 'block-test-language-block')); $links = array( 'active' => array(), 'inactive' => array(), @@ -97,4 +88,5 @@ function testLanguageBlock() { $this->assertIdentical($links, array('active' => array('en'), 'inactive' => array('fr')), 'Only the current language list item is marked as active on the language switcher block.'); $this->assertIdentical($anchors, array('active' => array('en'), 'inactive' => array('fr')), 'Only the current language anchor is marked as active on the language switcher block.'); } + } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php index 4b8b512..e86ad6c 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php @@ -402,15 +402,7 @@ function testUrlLanguageFallback() { $this->drupalGet('admin/config/regional/language/detection'); // Enable the language switcher block. - $block_id = 'language_block:' . LANGUAGE_TYPE_INTERFACE; - $default_theme = variable_get('theme_default', 'stark'); - $block = array( - 'title' => $this->randomName(8), - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_first', - ); - $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); - $this->assertText(t('The block configuration has been saved.'), 'Block enabled'); + $this->drupalPlaceBlock('language_block:' . LANGUAGE_TYPE_INTERFACE, array('machine_name' => 'test_language_block')); // Access the front page without specifying any valid URL language prefix // and having as browser language preference a non-default language. @@ -420,7 +412,7 @@ function testUrlLanguageFallback() { // Check that the language switcher active link matches the given browser // language. - $args = array(':id' => 'block-' . strtolower($block['machine_name']), ':url' => base_path() . $GLOBALS['script_path'] . $langcode_browser_fallback); + $args = array(':id' => 'block-test-language-block', ':url' => base_path() . $GLOBALS['script_path'] . $langcode_browser_fallback); $fields = $this->xpath('//div[@id=:id]//a[@class="language-link active" and starts-with(@href, :url)]', $args); $this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->name, 'The browser language is the URL active language'); diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index ac2e4c3..97534fe 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -16,7 +16,7 @@ class MenuTest extends WebTestBase { * * @var array */ - public static $modules = array('menu'); + public static $modules = array('menu', 'block'); protected $profile = 'standard'; @@ -138,7 +138,6 @@ function addCustomMenuCRUD() { * Add custom menu. */ function addCustomMenu() { - // Add custom menu. // Try adding a menu using a menu_name that is too long. $this->drupalGet('admin/structure/menu/add'); @@ -176,16 +175,12 @@ function addCustomMenu() { // Enable the custom menu block. $menu_name = 'menu-' . $menu_name; // Drupal prepends the name with 'menu-'. - $default_theme = variable_get('theme_default', 'stark'); - $this->drupalGet("admin/structure/block/list/block_plugin_ui:{$default_theme}/add"); + // Confirm that the custom menu block is available. + $this->drupalGet('admin/structure/block/list/block_plugin_ui:' . variable_get('theme_default', 'stark') . '/add'); $this->assertText($title); - $block = array( - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_first', - ); - $this->drupalPost("admin/structure/block/manage/menu_menu_block:$menu_name/$default_theme", $block, t('Save block')); - $this->assertResponse(200); + // Enable the block. + $this->drupalPlaceBlock($menu_name); return menu_load($menu_name); } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeBlockFunctionalTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeBlockFunctionalTest.php index 17711aa..b5d5205 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeBlockFunctionalTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeBlockFunctionalTest.php @@ -60,22 +60,8 @@ public function testRecentNodeBlock() { 'access content' => FALSE, )); - // Enable the recent content block. - $block_id = 'node_recent_block'; - $default_theme = variable_get('theme_default', 'stark'); - $block = array( - 'title' => $this->randomName(8), - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_first', - ); - $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); - $this->assertText(t('The block configuration has been saved.'), 'Node enabled.'); - - // Set the number of recent posts to 2. - $block['config_id'] = 'plugin.core.block.' . $default_theme . '.' . $block['machine_name']; - $config = config($block['config_id']); - $config->set('block_count', 2); - $config->save(); + // Enable the recent content block with two items. + $block = $this->drupalPlaceBlock('node_recent_block', array('machine_name' => 'test_block', 'block_count' => 2)); // Test that block is not visible without nodes. $this->drupalGet(''); @@ -105,7 +91,7 @@ public function testRecentNodeBlock() { // see the block. $this->drupalLogout(); $this->drupalGet(''); - $this->assertNoText($block['title'], 'Block was not found.'); + $this->assertNoText($block['subject'], 'Block was not found.'); // Test that only the 2 latest nodes are shown. $this->drupalLogin($this->webUser); @@ -114,7 +100,7 @@ public function testRecentNodeBlock() { $this->assertText($node3->label(), 'Node found in block.'); // Check to make sure nodes are in the right order. - $this->assertTrue($this->xpath('//div[@id="block-' . strtolower($block['machine_name']) . '"]/div/table/tbody/tr[position() = 1]/td/div/a[text() = "' . $node3->label() . '"]'), 'Nodes were ordered correctly in block.'); + $this->assertTrue($this->xpath('//div[@id="block-test-block"]/div/table/tbody/tr[position() = 1]/td/div/a[text() = "' . $node3->label() . '"]'), 'Nodes were ordered correctly in block.'); $this->drupalLogout(); $this->drupalLogin($this->adminUser); @@ -137,21 +123,10 @@ public function testRecentNodeBlock() { $this->assertText($node3->label(), 'Node found in block.'); $this->assertText($node4->label(), 'Node found in block.'); - // Enable the "Powered by Drupal" block and test the visibility by node - // type functionality. - $block_name = 'system_powered_by_block'; - $block = array( - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_first', - 'title' => $this->randomName(8), + // Enable the "Powered by Drupal" block only on article nodes. + $block = $this->drupalPlaceBlock('system_powered_by_block', array( 'visibility[node_type][types][article]' => TRUE, - ); - // Set the block to be shown only on node/xx if node is an article. - $this->drupalPost('admin/structure/block/manage/' . $block_name . '/' . $default_theme, $block, t('Save block')); - $this->assertText('The block configuration has been saved.', 'Block was saved'); - - // Configure the new forum topics block to only show 2 topics. - $block['config_id'] = 'plugin.core.block.' . $default_theme . '.' . $block['machine_name']; + )); $config = config($block['config_id']); $node_type_visibility = $config->get('visibility.node_type.types.article'); $this->assertEqual($node_type_visibility, 'article', 'Visibility settings were saved to configuration'); @@ -161,12 +136,13 @@ public function testRecentNodeBlock() { // Verify visibility rules. $this->drupalGet(''); - $this->assertNoText($block['title'], 'Block was not displayed on the front page.'); + $this->assertNoText($block['subject'], 'Block was not displayed on the front page.'); $this->drupalGet('node/add/article'); - $this->assertText($block['title'], 'Block was displayed on the node/add/article page.'); + $this->assertText($block['subject'], 'Block was displayed on the node/add/article page.'); $this->drupalGet('node/' . $node1->nid); - $this->assertText($block['title'], 'Block was displayed on the node/N when node is of type article.'); + $this->assertText($block['subject'], 'Block was displayed on the node/N when node is of type article.'); $this->drupalGet('node/' . $node5->nid); - $this->assertNoText($block['title'], 'Block was not displayed on nodes of type page.'); + $this->assertNoText($block['subject'], 'Block was not displayed on nodes of type page.'); } + } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeBlockTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeBlockTest.php deleted file mode 100644 index b738129..0000000 --- a/core/modules/node/lib/Drupal/node/Tests/NodeBlockTest.php +++ /dev/null @@ -1,59 +0,0 @@ - 'Block availability', - 'description' => 'Check if the syndicate block is available.', - 'group' => 'Node', - ); - } - - function setUp() { - parent::setUp(); - - // Create a user and log in. - $admin_user = $this->drupalCreateUser(array('administer blocks')); - $this->drupalLogin($admin_user); - } - - /** - * Tests that the "Syndicate" block is shown when enabled. - */ - public function testSyndicateBlock() { - $block_id = 'node_syndicate_block'; - $default_theme = variable_get('theme_default', 'stark'); - - $block = array( - 'title' => $this->randomName(8), - 'machine_name' => $this->randomName(8), - 'region' => 'sidebar_second', - ); - - // Enable the syndicate block. - $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); - $this->assertText(t('The block configuration has been saved.'), 'Node syndicate block enabled.'); - - // Confirm that the block's xpath is available. - $xpath = $this->buildXPathQuery('//div[@id=:id]/*', array(':id' => 'block-' . strtr(strtolower($block['machine_name']), '-', '_'))); - $this->assertFieldByXPath($xpath, NULL, 'Syndicate block found.'); - } -} diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeSyndicateBlockTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeSyndicateBlockTest.php new file mode 100644 index 0000000..4e5a209 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/NodeSyndicateBlockTest.php @@ -0,0 +1,47 @@ + 'Syndicate block', + 'description' => 'Check if the syndicate block is available.', + 'group' => 'Node', + ); + } + + function setUp() { + parent::setUp(); + + // Create a user and log in. + $admin_user = $this->drupalCreateUser(array('administer blocks')); + $this->drupalLogin($admin_user); + } + + /** + * Tests that the "Syndicate" block is shown when enabled. + */ + public function testSyndicateBlock() { + // Place the "Syndicate" block and confirm that it is rendered. + $this->drupalPlaceBlock('node_syndicate_block', array('machine_name' => 'test_syndicate_block')); + $this->assertFieldByXPath('//div[@id="block-test-syndicate-block"]/*', NULL, 'Syndicate block found.'); + } + +} diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index da720e5..7c71e81 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -347,15 +347,12 @@ protected function drupalCreateContentType($settings = array()) { * * @param string $plugin_id * The plugin ID of the block type for this block instance. - * @param string $theme - * (optional) The theme for which to add a block instance. Defaults to the - * default theme. * @param array $settings * (optional) An associative array of settings for the block instance. * Override the defaults by specifying the key and value in the array, for * example: * @code - * $this->drupalPlaceBlock(array( + * $this->drupalPlaceBlock('system_powered_by_block', array( * 'title' => t('Hello, world!'), * )); * @endcode @@ -363,6 +360,9 @@ protected function drupalCreateContentType($settings = array()) { * - title: Random string. * - machine_name: Random string. * - region: 'sidebar_first'. + * @param string $theme + * (optional) The theme for which to add a block instance. Defaults to the + * default theme. * * @return array|false * The block instance configuration from BlockBase::getConfig(), or FALSE @@ -374,7 +374,7 @@ protected function drupalCreateContentType($settings = array()) { * @todo * Add support for creating custom block instances. */ - protected function drupalPlaceBlock($plugin_id, $theme = '', array $settings = array()) { + protected function drupalPlaceBlock($plugin_id, array $settings = array(), $theme = NULL) { // Confirm that the active user has permission to add the block instance. // @todo Remove this check once it is possible to do this programmatically. if (!user_access('administer blocks', $this->loggedInUser)) {