PermissionsTest.php in Weather 2.0.x
File
tests/src/Functional/PermissionsTest.php
View source
<?php
namespace Drupal\Tests\weather\Functional;
use Drupal\Tests\BrowserTestBase;
class PermissionsTest extends BrowserTestBase {
protected 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
->assertSession()
->pageTextContains('Directory for custom images');
$this
->drupalGet('admin/config/user-interface/weather/system-wide/add');
$this
->submitForm([], 'Save');
$this
->drupalGet('node');
$this
->assertSession()
->responseNotContains('<div class="weather">');
$this
->assertSession()
->linkNotExists('Kyiv');
$this
->assertSession()
->linkByHrefNotExists('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
->assertSession()
->pageTextContains('Directory for custom images');
$this
->assertSession()
->pageTextContains('Kyiv');
$this
->assertSession()
->pageTextContains('Add location to this display');
$this
->drupalGet('node');
$this
->assertSession()
->responseContains('<div class="weather">');
$this
->assertSession()
->linkExists('Kyiv');
$this
->assertSession()
->linkByHrefExists('weather/Ukraine/Kiev/Kyiv/1');
$this
->drupalLogout();
$this
->drupalLogin($normal_user);
$this
->drupalGet('node');
$this
->assertSession()
->pageTextContains('Weather');
$this
->assertSession()
->responseContains('<div class="weather">');
$this
->assertSession()
->linkExists('Kyiv');
$this
->assertSession()
->linkByHrefExists('weather/Ukraine/Kiev/Kyiv/1');
$this
->drupalGet('admin/config/user-interface/weather');
$this
->assertSession()
->statusCodeEquals(403);
$this
->assertSession()
->pageTextContains('You are not authorized to access this page');
$this
->drupalGet('weather');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->pageTextContains('The requested page could not be found');
$this
->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Weather forecast');
$this
->assertSession()
->pageTextContains('Kyiv');
$this
->drupalLogout();
$this
->drupalLogin($weather_user_1);
$this
->drupalGet('node');
$this
->assertSession()
->pageTextContains('Weather');
$this
->assertSession()
->responseContains('<div class="weather">');
$this
->assertSession()
->linkExists('Kyiv');
$this
->assertSession()
->linkByHrefExists('weather/Ukraine/Kiev/Kyiv/1');
$this
->drupalGet('admin/config/user-interface/weather');
$this
->assertSession()
->statusCodeEquals(403);
$this
->assertSession()
->pageTextContains('You are not authorized to access this page');
$this
->drupalGet('weather');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->pageTextContains('The requested page could not be found');
$this
->drupalGet('weather/zollenspieker');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->pageTextContains('The requested page could not be found');
$this
->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('weather/Germany/Hamburg/Zollenspieker');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->pageTextNotContains('Zollenspieker');
$this
->drupalLogout();
$this
->drupalLogin($weather_user_2);
$this
->drupalGet('node');
$this
->assertSession()
->pageTextContains('Weather');
$this
->assertSession()
->responseContains('<div class="weather">');
$this
->assertSession()
->linkExists('Kyiv');
$this
->assertSession()
->linkByHrefExists('weather/Ukraine/Kiev/Kyiv/1');
$this
->drupalGet('admin/config/user-interface/weather');
$this
->assertSession()
->statusCodeEquals(403);
$this
->assertSession()
->pageTextContains('You are not authorized to access this page');
$this
->drupalGet('weather');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->pageTextContains('The requested page could not be found');
$this
->drupalGet('weather/zollenspieker');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->pageTextContains('The requested page could not be found');
$this
->drupalGet('weather/Ukraine/Kiev/Kyiv/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('weather/Germany/Hamburg/Zollenspieker');
$this
->assertSession()
->statusCodeEquals(404);
$this
->assertSession()
->pageTextNotContains('Zollenspieker');
$this
->drupalLogout();
}
}