From 195d2c9d5d188614db084a85b905cd8db0db66cf Mon Sep 17 00:00:00 2001 From: webchick Date: Sat, 13 Oct 2012 09:31:48 -0700 Subject: [PATCH] Issue #1811804 by xjm: Provide a test page testing module. --- .../lib/Drupal/menu/Tests/MenuNodeTest.php | 10 ++++---- .../Drupal/node/Tests/NodeCreationTest.php | 14 ++++++++--- .../simpletest/Tests/SimpleTestTest.php | 19 ++++---------- .../system/Tests/Bootstrap/PageCacheTest.php | 6 ++--- .../system/Tests/Common/HttpRequestTest.php | 8 +++--- .../test_page_test/test_page_test.info | 6 +++++ .../test_page_test/test_page_test.module | 25 +++++++++++++++++++ 7 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 core/modules/system/tests/modules/test_page_test/test_page_test.info create mode 100644 core/modules/system/tests/modules/test_page_test/test_page_test.module diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php index 76574675bdc..c3450a7e2e5 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php @@ -19,7 +19,7 @@ class MenuNodeTest extends WebTestBase { * * @var array */ - public static $modules = array('menu'); + public static $modules = array('menu', 'test_page_test'); protected $profile = 'standard'; @@ -71,7 +71,7 @@ class MenuNodeTest extends WebTestBase { $this->drupalPost('node/add/page', $edit, t('Save')); $node = $this->drupalGetNodeByTitle($node_title); // Assert that there is no link for the node. - $this->drupalGet('user'); + $this->drupalGet('test-page'); $this->assertNoLink($node_title); // Edit the node, enable the menu link setting, but skip the link title. @@ -80,7 +80,7 @@ class MenuNodeTest extends WebTestBase { ); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); // Assert that there is no link for the node. - $this->drupalGet('user'); + $this->drupalGet('test-page'); $this->assertNoLink($node_title); // Edit the node and create a menu link. @@ -91,7 +91,7 @@ class MenuNodeTest extends WebTestBase { ); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); // Assert that the link exists. - $this->drupalGet('user'); + $this->drupalGet('test-page'); $this->assertLink($node_title); $this->drupalGet('node/' . $node->nid . '/edit'); @@ -103,7 +103,7 @@ class MenuNodeTest extends WebTestBase { ); $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); // Assert that there is no link for the node. - $this->drupalGet('user'); + $this->drupalGet('test-page'); $this->assertNoLink($node_title); // Add a menu link to the Management menu. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php index 241af5f0ca6..285e616dc24 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php @@ -19,7 +19,7 @@ class NodeCreationTest extends NodeTestBase { * * @var array */ - public static $modules = array('node_test_exception', 'dblog'); + public static $modules = array('node_test_exception', 'dblog', 'test_page_test'); public static function getInfo() { return array( @@ -100,10 +100,11 @@ class NodeCreationTest extends NodeTestBase { * Create an unpublished node and confirm correct redirect behavior. */ function testUnpublishedNodeCreation() { + // Set the front page to the test page. + config('system.site')->set('page.front', 'test-page')->save(); + // Set "Basic page" content type to be unpublished by default. variable_set('node_options_page', array()); - // Set the front page to the default "node" page. - config('system.site')->set('page.front', 'node')->save(); // Create a node. $edit = array(); @@ -112,6 +113,11 @@ class NodeCreationTest extends NodeTestBase { $this->drupalPost('node/add/page', $edit, t('Save')); // Check that the user was redirected to the home page. - $this->assertText(t('Welcome to Drupal'), 'The user is redirected to the home page.'); + $this->assertUrl(''); + $this->assertText(t('Test page text')); + + // Confirm that the node was created. + $this->assertRaw(t('!post %title has been created.', array('!post' => 'Basic page', '%title' => $edit["title"]))); } + } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/SimpleTestTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/SimpleTestTest.php index c7dd136b230..8abc198c725 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/Tests/SimpleTestTest.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/SimpleTestTest.php @@ -17,7 +17,7 @@ class SimpleTestTest extends WebTestBase { * * @var array */ - public static $modules = array('simpletest'); + public static $modules = array('simpletest', 'test_page_test'); /** * The results array that has been parsed by getTestResults(). @@ -30,13 +30,6 @@ class SimpleTestTest extends WebTestBase { */ protected $test_ids = array(); - /** - * The administrative user account to use during testing. - * - * @var Drupal\user\User - */ - protected $admin_user; - public static function getInfo() { return array( 'name' => 'SimpleTest functionality', @@ -49,8 +42,7 @@ class SimpleTestTest extends WebTestBase { if (!$this->inCURL()) { parent::setUp(); // Create and log in an admin user. - $this->admin_user = $this->drupalCreateUser(array('administer unit tests')); - $this->drupalLogin($this->admin_user); + $this->drupalLogin($this->drupalCreateUser(array('administer unit tests'))); } else { self::$modules = array('non_existent_module'); @@ -64,11 +56,10 @@ class SimpleTestTest extends WebTestBase { function testInternalBrowser() { global $conf; if (!$this->inCURL()) { - // Retrieve the user page and check its title and headers. - $this->drupalGet('user'); + // Retrieve the test page and check its title and headers. + $this->drupalGet('test-page'); $this->assertTrue($this->drupalGetHeader('Date'), t('An HTTP header was received.')); - $this->assertTitle(t('@user | @site-name', array( - '@user' => $this->admin_user->name, + $this->assertTitle(t('Test page | @site-name', array( '@site-name' => config('system.site')->get('name'), ))); $this->assertNoTitle('Foo'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php index 09dc690039e..92c0dce40c5 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php @@ -19,7 +19,7 @@ class PageCacheTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'system_test'); + public static $modules = array('test_page_test', 'system_test'); public static function getInfo() { return array( @@ -34,7 +34,7 @@ class PageCacheTest extends WebTestBase { config('system.site') ->set('name', 'Drupal') - ->set('page.front', 'node') + ->set('page.front', 'test-page') ->save(); } @@ -153,7 +153,7 @@ class PageCacheTest extends WebTestBase { $this->drupalGet(''); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); $this->assertFalse($this->drupalGetHeader('Content-Encoding'), 'A Content-Encoding header was not sent.'); - $this->assertTitle(t('Welcome to @site-name | @site-name', array('@site-name' => config('system.site')->get('name'))), 'Site title matches.'); + $this->assertTitle(t('Test page | @site-name', array('@site-name' => config('system.site')->get('name'))), 'Site title matches.'); $this->assertRaw('', 'Page was not compressed.'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/HttpRequestTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/HttpRequestTest.php index 5102ef263a8..d3dca9756b8 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/HttpRequestTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/HttpRequestTest.php @@ -20,7 +20,7 @@ class HttpRequestTest extends WebTestBase { * * @var array */ - public static $modules = array('system_test', 'language'); + public static $modules = array('system_test', 'language', 'test_page_test'); public static function getInfo() { return array( @@ -45,11 +45,11 @@ class HttpRequestTest extends WebTestBase { $this->assertEqual($unable_to_parse->code, -1001, 'Returned with "-1001" error code.'); $this->assertEqual($unable_to_parse->error, 'unable to parse URL', 'Returned with "unable to parse URL" error message.'); - // Fetch the user login page. - $result = drupal_http_request(url('user/login', array('absolute' => TRUE))); + // Fetch the test page. + $result = drupal_http_request(url('test-page', array('absolute' => TRUE))); $this->assertEqual($result->code, 200, 'Fetched page successfully.'); $this->drupalSetContent($result->data); - $this->assertTitle(t('Log in | @site-name', array('@site-name' => config('system.site')->get('name')))); + $this->assertTitle(t('Test page | @site-name', array('@site-name' => config('system.site')->get('name')))); // Test that code and status message is returned. $result = drupal_http_request(url('pagedoesnotexist', array('absolute' => TRUE))); diff --git a/core/modules/system/tests/modules/test_page_test/test_page_test.info b/core/modules/system/tests/modules/test_page_test/test_page_test.info new file mode 100644 index 00000000000..6ee896c7c04 --- /dev/null +++ b/core/modules/system/tests/modules/test_page_test/test_page_test.info @@ -0,0 +1,6 @@ +name = Test page +description = Provides a test page for automated tests. +package = Testing +version = VERSION +core = 8.x +hidden = TRUE diff --git a/core/modules/system/tests/modules/test_page_test/test_page_test.module b/core/modules/system/tests/modules/test_page_test/test_page_test.module new file mode 100644 index 00000000000..c5ba6873a60 --- /dev/null +++ b/core/modules/system/tests/modules/test_page_test/test_page_test.module @@ -0,0 +1,25 @@ + 'Test front page', + 'page callback' => 'test_page_test_page', + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + + return $items; +} + +/** + * Page callback: Returns a test page and sets the title. + * + * @see test_page_test_menu() + */ +function test_page_test_page() { + drupal_set_title(t('Test page')); + return t('Test page text.'); +}