annotate core/modules/system/src/Tests/System/FrontPageTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\system\Tests\System;
Chris@0 4
Chris@0 5 use Drupal\Component\Utility\SafeMarkup;
Chris@0 6 use Drupal\simpletest\WebTestBase;
Chris@0 7
Chris@0 8 /**
Chris@0 9 * Tests front page functionality and administration.
Chris@0 10 *
Chris@0 11 * @group system
Chris@0 12 */
Chris@0 13 class FrontPageTest extends WebTestBase {
Chris@0 14
Chris@0 15 /**
Chris@0 16 * Modules to enable.
Chris@0 17 *
Chris@0 18 * @var array
Chris@0 19 */
Chris@0 20 public static $modules = ['node', 'system_test', 'views'];
Chris@0 21
Chris@0 22 /**
Chris@0 23 * The path to a node that is created for testing.
Chris@0 24 *
Chris@0 25 * @var string
Chris@0 26 */
Chris@0 27 protected $nodePath;
Chris@0 28
Chris@0 29 protected function setUp() {
Chris@0 30 parent::setUp();
Chris@0 31
Chris@0 32 // Create admin user, log in admin user, and create one node.
Chris@0 33 $this->drupalLogin($this->drupalCreateUser([
Chris@0 34 'access content',
Chris@0 35 'administer site configuration',
Chris@0 36 ]));
Chris@0 37 $this->drupalCreateContentType(['type' => 'page']);
Chris@0 38 $this->nodePath = "node/" . $this->drupalCreateNode(['promote' => 1])->id();
Chris@0 39
Chris@0 40 // Configure 'node' as front page.
Chris@0 41 $this->config('system.site')->set('page.front', '/node')->save();
Chris@0 42 // Enable front page logging in system_test.module.
Chris@0 43 \Drupal::state()->set('system_test.front_page_output', 1);
Chris@0 44 }
Chris@0 45
Chris@0 46 /**
Chris@0 47 * Test front page functionality.
Chris@0 48 */
Chris@0 49 public function testDrupalFrontPage() {
Chris@0 50 // Create a promoted node to test the <title> tag on the front page view.
Chris@0 51 $settings = [
Chris@0 52 'title' => $this->randomMachineName(8),
Chris@0 53 'promote' => 1,
Chris@0 54 ];
Chris@0 55 $this->drupalCreateNode($settings);
Chris@0 56 $this->drupalGet('');
Chris@0 57 $this->assertTitle('Home | Drupal');
Chris@0 58
Chris@0 59 $this->assertText(t('On front page.'), 'Path is the front page.');
Chris@0 60 $this->drupalGet('node');
Chris@0 61 $this->assertText(t('On front page.'), 'Path is the front page.');
Chris@0 62 $this->drupalGet($this->nodePath);
Chris@0 63 $this->assertNoText(t('On front page.'), 'Path is not the front page.');
Chris@0 64
Chris@0 65 // Change the front page to an invalid path.
Chris@0 66 $edit = ['site_frontpage' => '/kittens'];
Chris@0 67 $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
Chris@0 68 $this->assertText(t("The path '@path' is either invalid or you do not have access to it.", ['@path' => $edit['site_frontpage']]));
Chris@0 69
Chris@0 70 // Change the front page to a path without a starting slash.
Chris@0 71 $edit = ['site_frontpage' => $this->nodePath];
Chris@0 72 $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
Chris@0 73 $this->assertRaw(SafeMarkup::format("The path '%path' has to start with a slash.", ['%path' => $edit['site_frontpage']]));
Chris@0 74
Chris@0 75 // Change the front page to a valid path.
Chris@0 76 $edit['site_frontpage'] = '/' . $this->nodePath;
Chris@0 77 $this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
Chris@0 78 $this->assertText(t('The configuration options have been saved.'), 'The front page path has been saved.');
Chris@0 79
Chris@0 80 $this->drupalGet('');
Chris@0 81 $this->assertText(t('On front page.'), 'Path is the front page.');
Chris@0 82 $this->drupalGet('node');
Chris@0 83 $this->assertNoText(t('On front page.'), 'Path is not the front page.');
Chris@0 84 $this->drupalGet($this->nodePath);
Chris@0 85 $this->assertText(t('On front page.'), 'Path is the front page.');
Chris@0 86 }
Chris@0 87
Chris@0 88 }