PermissionsTest.php in Weather 8
File
tests/src/Functional/PermissionsTest.php
View source
<?php
namespace Drupal\Tests\weather\Functional;
use Drupal\Tests\BrowserTestBase;
class PermissionsTest extends BrowserTestBase {
public static $modules = [
'weather',
'block',
];
use WeatherCommonTestTrait;
protected $defaultTheme = 'stark';
public function testPermissions() {
$config = \Drupal::configFactory()
->getEditable('weather.settings');
$config
->set('weather_time_for_testing', 1381176000)
->save();
$this
->weatherFillWeatherSchema('geonames_703448.xml');
$normal_user = $this
->drupalCreateUser([
'access content',
]);
$weather_user_1 = $this
->drupalCreateUser([
'access content',
'administer blocks',
]);
$weather_user_2 = $this
->drupalCreateUser([
'access content',
'administer blocks',
]);
$admin_user = $this
->drupalCreateUser([
'access content',
'administer system-wide weather',
'administer blocks',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('node');
$this
->drupalGet('admin/config/user-interface/weather');
$this
->assertText('Directory for custom images');
$this
->drupalGet('admin/config/user-interface/weather/system-wide/add');
$this
->submitForm([], 'Save');
$this
->drupalGet('node');
$this
->assertNoRaw('<div class="weather">');
$this
->assertNoLink('Kyiv');
$this
->assertNoLinkByHref('weather/Ukraine/Kiev/Kyiv/1');
$this
->drupalGet('admin/config/user-interface/weather/system-wide/1/add');
$this
->submitForm([], 'Save');
$this
->drupalGet('admin/structure/block/add/weather_system_display_block:1/stark');
$this
->submitForm([
'region' => 'sidebar_first',
], 'Save block');
$this
->drupalGet('admin/config/user-interface/weather');
$this
->assertText('Directory for custom images');
$this
->assertText('Kyiv');
$this
->assertText('Add location to this display');
$this
->drupalGet('node');
$this
->assertRaw('<div class="weather">');
$this
->assertLink('Kyiv');
$this
->assertLinkByHref('weather/Ukraine/Kiev/Kyiv/1');
$this
->drupalLogout();
$this
->drupalLogin($normal_user);
$this
->drupalGet('node');
$this
->assertText('Weather');
$this
->assertRaw('<div class="weather">');
$this
->assertLink('Kyiv');
$this
->assertLinkByHref('weather/Ukraine/Kiev/Kyiv/1');
$this
->drupalGet('admin/config/user-interface/weather');
$this
->assertResponse(403);
$this
->assertText('You are not authorized to access this page');
$this
->drupalGet('weather');
$this
->assertResponse(404);
$this
->assertText('The requested page could not be found');
$this
->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
$this
->assertResponse(200);
$this
->assertText('Weather forecast');
$this
->assertText('Kyiv');
$this
->drupalLogout();
$this
->drupalLogin($weather_user_1);
$this
->drupalGet('node');
$this
->assertText('Weather');
$this
->assertRaw('<div class="weather">');
$this
->assertLink('Kyiv');
$this
->assertLinkByHref('weather/Ukraine/Kiev/Kyiv/1');
$this
->drupalGet('admin/config/user-interface/weather');
$this
->assertResponse(403);
$this
->assertText('You are not authorized to access this page');
$this
->drupalGet('weather');
$this
->assertResponse(404);
$this
->assertText('The requested page could not be found');
$this
->drupalGet('weather/zollenspieker');
$this
->assertResponse(404);
$this
->assertText('The requested page could not be found');
$this
->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
$this
->assertResponse(200);
$this
->drupalGet('weather/Germany/Hamburg/Zollenspieker');
$this
->assertResponse(404);
$this
->assertNoText('Zollenspieker');
$this
->drupalLogout();
$this
->drupalLogin($weather_user_2);
$this
->drupalGet('node');
$this
->assertText('Weather');
$this
->assertRaw('<div class="weather">');
$this
->assertLink('Kyiv');
$this
->assertLinkByHref('weather/Ukraine/Kiev/Kyiv/1');
$this
->drupalGet('admin/config/user-interface/weather');
$this
->assertResponse(403);
$this
->assertText('You are not authorized to access this page');
$this
->drupalGet('weather');
$this
->assertResponse(404);
$this
->assertText('The requested page could not be found');
$this
->drupalGet('weather/zollenspieker');
$this
->assertResponse(404);
$this
->assertText('The requested page could not be found');
$this
->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
$this
->assertResponse(200);
$this
->drupalGet('weather/Germany/Hamburg/Zollenspieker');
$this
->assertResponse(404);
$this
->assertNoText('Zollenspieker');
$this
->drupalLogout();
}
}