View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\og\Kernel\Views;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\og\Og;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
class OgAdminMembersViewTest extends ViewsKernelTestBase {
use UserCreationTrait;
public static $modules = [
'system',
'user',
'field',
'node',
'og',
'options',
'views',
];
public static $testViews = [
'og_members_overview',
];
protected $configProperties = [
'disabled',
'name',
'description',
'tag',
'base_table',
'label',
'core',
'display',
];
protected $executableProperties = [
'storage',
'built',
'executed',
'args',
'build_info',
'result',
'attachment_before',
'attachment_after',
'exposed_data',
'exposed_raw_input',
'old_view',
'parent_views',
];
protected $user;
protected $group;
protected function setUpFixtures() {
$this
->installConfig([
'og',
]);
$this
->installEntitySchema('og_membership');
$this
->installEntitySchema('user');
$this
->installEntitySchema('node');
$group_bundle = mb_strtolower($this
->randomMachineName());
NodeType::create([
'type' => $group_bundle,
'name' => $this
->randomString(),
])
->save();
Og::groupTypeManager()
->addGroup('node', $group_bundle);
$this->user = $this
->createUser([
'access user profiles',
], FALSE, TRUE);
$this->group = Node::create([
'title' => $this
->randomString(),
'type' => $group_bundle,
'uid' => $this->user
->id(),
]);
$this->group
->save();
parent::setUpFixtures();
}
public function testMembersTable() {
$renderer = $this->container
->get('renderer');
$view = Views::getView('og_members_overview');
$preview = $view
->preview('default', [
'node',
$this->group
->id(),
]);
$this
->setRawContent($renderer
->renderRoot($preview));
$map = [
'Name' => '//*[@id="view-name-table-column"]/a/text()',
'Member since' => '//*[@id="view-created-table-column"]',
'State' => '//*[@id="view-state-table-column"]',
$this->user
->label() => '//*/tbody/tr/td[2]/span/text()',
'Update the member' => '//td[contains(@class, \'views-field-og-membership-bulk-form\')]/div/label',
];
foreach ($map as $value => $xpath) {
$result = $this
->xpath($xpath);
$this
->assertTrue(strpos(trim((string) $result[0]), $value) === 0);
}
}
}