LanguageAccessTestBase.php in Language access 8        
                          
                  
                        
  
  
  
  
  
File
  tests/src/Functional/LanguageAccessTestBase.php
  
    View source  
  <?php
namespace Drupal\Tests\language_access\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\BrowserTestBase;
abstract class LanguageAccessTestBase extends BrowserTestBase {
  
  protected static $modules = [
    'content_translation',
    'language_access',
    'node',
    'path',
    'image',
  ];
  
  protected $defaultTheme = 'stark';
  
  protected $roleStorage;
  
  protected $userEn;
  
  protected $userNl;
  
  protected function setUp() : void {
    parent::setUp();
    $this
      ->drupalCreateContentType([
      'type' => 'page',
    ]);
    $this
      ->config('system.site')
      ->set('page.front', '/node')
      ->save();
    
    ConfigurableLanguage::createFromLangcode('nl')
      ->save();
    
    $this
      ->config('language.negotiation')
      ->set('url', [
      'source' => 'path_prefix',
      'prefixes' => [
        'en' => 'en',
        'nl' => 'nl',
      ],
    ])
      ->save();
    
    $config = ContentLanguageSettings::loadByEntityTypeBundle('node', 'page');
    $config
      ->setDefaultLangcode('en')
      ->setLanguageAlterable(TRUE)
      ->save();
    $node = $this
      ->drupalCreateNode([
      'type' => 'page',
      'path' => '/test-en',
    ]);
    $node
      ->addTranslation('nl', [
      'title' => $this
        ->randomMachineName(),
      'path' => '/test-nl',
    ])
      ->save();
    
    $this->roleStorage = $this->container
      ->get('entity_type.manager')
      ->getStorage('user_role');
    $authenticated_role = $this->roleStorage
      ->load('authenticated');
    $authenticated_role
      ->revokePermission('access language en');
    $authenticated_role
      ->save();
    $this->userEn = $this
      ->createUser([
      'access language en',
    ]);
    $this->userNl = $this
      ->createUser([
      'access language nl',
    ]);
  }
}