View source
<?php
namespace Drupal\Tests\subpathauto\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\user\Entity\User;
use Symfony\Component\HttpFoundation\Request;
class SubPathautoKernelTest extends KernelTestBase {
use UserCreationTrait;
public static $modules = [
'system',
'path_alias',
'subpathauto',
'node',
'user',
];
protected $pathProcessor;
protected function setUp() {
parent::setUp();
$this
->installSchema('system', 'sequences');
$this
->installEntitySchema('user');
$this
->installEntitySchema('node');
$this
->installEntitySchema('path_alias');
$this
->installConfig('subpathauto');
$type = NodeType::create([
'type' => 'page',
'name' => 'page',
]);
$type
->save();
$this->pathProcessor = $this->container
->get('path_processor_subpathauto');
$aliasWhiteList = $this->container
->get('path_alias.whitelist');
Node::create([
'type' => 'page',
'title' => 'test',
])
->save();
$aliasStorage = \Drupal::entityTypeManager()
->getStorage('path_alias');
$path_alias = $aliasStorage
->create([
'path' => '/node/1',
'alias' => '/kittens',
]);
$path_alias
->save();
$aliasWhiteList
->set('node', TRUE);
User::create([
'uid' => 0,
'name' => 'anonymous user',
])
->save();
}
public function testProcessInbound() {
$processed = $this->pathProcessor
->processInbound('/kittens/are-fake', Request::create('/kittens/are-fake'));
$this
->assertEquals('/kittens/are-fake', $processed);
$processed = $this->pathProcessor
->processInbound('/kittens/edit', Request::create('/en/kittens/edit'));
$this
->assertEquals('/node/1/edit', $processed);
$processed = $this->pathProcessor
->processInbound('/kittens/edit', Request::create('/kittens/edit'));
$this
->assertEquals('/node/1/edit', $processed);
$admin_user = $this
->createUser();
\Drupal::currentUser()
->setAccount($admin_user);
$processed = $this->pathProcessor
->processInbound('/kittens/edit', Request::create('/kittens/edit'));
$this
->assertEquals('/node/1/edit', $processed);
}
public function testProcessOutbound() {
$processed = $this->pathProcessor
->processOutbound('/kittens/are-fake');
$this
->assertEquals('/kittens/are-fake', $processed);
$processed = $this->pathProcessor
->processOutbound('/node/1/edit');
$this
->assertEquals('/kittens/edit', $processed);
$admin_user = $this
->createUser();
\Drupal::currentUser()
->setAccount($admin_user);
$processed = $this->pathProcessor
->processOutbound('/node/1/edit');
$this
->assertEquals('/kittens/edit', $processed);
$options = [
'absolute' => TRUE,
];
$processed = $this->pathProcessor
->processOutbound('/node/1/edit', $options);
$this
->assertEquals('/kittens/edit', $processed);
}
}