ConfigurationTest.php in Weather 2.0.x
File
tests/src/Functional/ConfigurationTest.php
View source
<?php
namespace Drupal\Tests\weather\Functional;
use Drupal\Tests\BrowserTestBase;
class ConfigurationTest extends BrowserTestBase {
protected static $modules = [
'weather',
'block',
];
protected $defaultTheme = 'stark';
use WeatherCommonTestTrait;
public function testConfiguration() {
$admin_user = $this
->drupalCreateUser([
'access content',
'administer system-wide weather',
'administer blocks',
]);
$this
->drupalLogin($admin_user);
$config = \Drupal::configFactory()
->getEditable('weather.settings');
$config
->set('weather_time_for_testing', 1381176000)
->save();
$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
->assertSession()
->pageTextContains('You do not have any weather places in system.');
$this
->weatherFillWeatherSchema('geonames_703448.xml');
$this
->drupalGet('admin/config/user-interface/weather/system-wide/1/add');
$this
->submitForm([], 'Save');
\Drupal::cache()
->invalidateAll();
$this
->drupalGet('admin/structure/block/add/weather_system_display_block:1/stark');
$this
->submitForm([
'region' => 'sidebar_first',
], 'Save block');
$this
->drupalGet('admin/structure/block/list/stark');
$this
->assertSession()
->pageTextContains('Weather: system-wide display (#1)');
$this
->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
$this
->assertSession()
->responseContains('<div class="weather">');
$this
->assertSession()
->pageTextContains('00:00-06:00');
$this
->assertSession()
->responseContains(' °C');
$this
->assertSession()
->pageTextContains('18:00-00:00');
$this
->assertSession()
->responseContains(' °C');
$edit = [
'config[temperature]' => 'fahrenheit',
];
$this
->drupalGet('admin/config/user-interface/weather/system-wide/1/edit');
$this
->submitForm($edit, 'Save');
\Drupal::cache()
->invalidateAll();
$this
->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
$this
->assertSession()
->responseContains(' °F');
$this
->assertSession()
->responseContains(' °F');
$this
->drupalLogout();
}
}