You are here

ConfigurationTest.php in Weather 8

Same filename and directory in other branches
  1. 2.0.x tests/src/Functional/ConfigurationTest.php

File

tests/src/Functional/ConfigurationTest.php
View source
<?php

namespace Drupal\Tests\weather\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Tests configuration of weather displays.
 *
 * @group Weather
 */
class ConfigurationTest extends BrowserTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = [
    'weather',
    'block',
  ];

  /**
   * The tests don't need markup, so use 'stark' as theme.
   *
   * @var string
   */
  protected $defaultTheme = 'stark';
  use WeatherCommonTestTrait;

  /**
   * Tests configuration of weather block.
   *
   * @throws \ReflectionException
   */
  public function testConfiguration() {

    // This user may setup a system-wide weather block.
    $admin_user = $this
      ->drupalCreateUser([
      'access content',
      'administer system-wide weather',
      'administer blocks',
    ]);

    // Test with admin user.
    $this
      ->drupalLogin($admin_user);

    // First case.
    // Set a fixed time for testing to 2013-10-07 20:00:00 UTC.
    $config = \Drupal::configFactory()
      ->getEditable('weather.settings');
    $config
      ->set('weather_time_for_testing', 1381176000)
      ->save();

    // Second case.
    // Enable a system-wide weather block.
    $this
      ->drupalGet('admin/config/user-interface/weather/system-wide/add');
    $this
      ->submitForm([], 'Save');
    $this
      ->drupalGet('admin/config/user-interface/weather/system-wide/1/add');
    $this
      ->assertText('You do not have any weather places in system.');

    // Third case.
    // Configure the default place.
    $this
      ->weatherFillWeatherSchema('geonames_703448.xml');
    $this
      ->drupalGet('admin/config/user-interface/weather/system-wide/1/add');
    $this
      ->submitForm([], 'Save');

    // Clear site cache to add block.
    \Drupal::cache()
      ->invalidateAll();

    // Fourth case - enable & place block.
    $this
      ->drupalGet('admin/structure/block/add/weather_system_display_block:1/stark');
    $this
      ->submitForm([
      'region' => 'sidebar_first',
    ], 'Save block');

    // Check block existing in blocks list.
    $this
      ->drupalGet('admin/structure/block/list/stark');
    $this
      ->assertText('Weather: system-wide display (#1)');

    // Make sure that the weather block is displayed
    // with correct forecast data.
    $this
      ->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
    $this
      ->assertRaw('<div class="weather">');
    $this
      ->assertText('00:00-06:00');
    $this
      ->assertRaw('&thinsp;°C');
    $this
      ->assertText('18:00-00:00');
    $this
      ->assertRaw('&thinsp;°C');

    // Change temperature units to Fahrenheit.
    $edit = [
      'config[temperature]' => 'fahrenheit',
    ];
    $this
      ->drupalGet('admin/config/user-interface/weather/system-wide/1/edit');
    $this
      ->submitForm($edit, 'Save');

    // Clear site cache to add block.
    \Drupal::cache()
      ->invalidateAll();

    // Make sure that the weather block now shows different temperatures.
    $this
      ->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
    $this
      ->assertRaw('&thinsp;°F');
    $this
      ->assertRaw('&thinsp;°F');

    // Logout current user.
    $this
      ->drupalLogout();
  }

}

Classes

Namesort descending Description
ConfigurationTest Tests configuration of weather displays.