View source
<?php
namespace Drupal\Tests\minisite\Functional;
use Drupal\node\Entity\Node;
use Drupal\Tests\pathauto\Functional\PathautoTestHelperTrait;
class UploadBrowseAliasPathautoTest extends MinisiteTestBase {
use PathautoTestHelperTrait;
protected static $modules = [
'block',
'pathauto',
'token',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('system_breadcrumb_block');
}
public function testUploadAndBrowsingAlias() {
$test_archive_assets = array_keys($this
->getTestFilesStubValid());
$node_title = $this
->randomMachineName();
$minisite_description = 'D' . $this
->randomMachineName();
$this
->createPattern('node', mb_strtolower($this
->randomMachineName()) . '/' . '[node:title]');
$edit = [
'path[0][pathauto]' => TRUE,
];
$field_name = $this
->createFieldAndNode($this->contentType, $node_title, $minisite_description, $edit);
$node = $this
->drupalGetNodeByTitle($node_title);
$nid = $node
->id();
$this
->assertEntityAliasExists($node);
$this
->assertMinisiteUploaded($node, $field_name, $test_archive_assets);
$node_alias = $node->path
->get(0)
->getValue()['alias'];
$this
->browseFixtureMinisiteAliased($node_alias, $minisite_description, $test_archive_assets);
$node_alias_updated = '/a' . $this
->randomMachineName();
$edit = [
'path[0][pathauto]' => FALSE,
'path[0][alias]' => $node_alias_updated,
];
$this
->drupalPostForm("node/{$nid}/edit", $edit, $this
->t('Save'));
$this
->browseFixtureMinisiteAliased($node_alias_updated, $minisite_description, $test_archive_assets);
$edit = [
'path[0][pathauto]' => TRUE,
];
$this
->drupalPostForm("node/{$nid}/edit", $edit, $this
->t('Save'));
$node = Node::load($nid);
$this
->assertEntityAliasExists($node);
$this
->browseFixtureMinisiteAliased($node_alias, $minisite_description, $test_archive_assets);
$this
->drupalPostForm("node/{$nid}/delete", [], $this
->t('Delete'));
$this
->assertResponse(200);
$this
->assertMinisiteRemoved($node, $field_name, $test_archive_assets);
}
}