TypeStyleTest.php in Type Style 8
File
tests/src/Functional/TypeStyleTest.php
View source
<?php
namespace Drupal\Tests\type_style\Functional;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
class TypeStyleTest extends BrowserTestBase {
public static $modules = [
'type_style',
'node',
];
protected $defaultTheme = 'stark';
public function testTypeStyle() {
$user = $this
->createUser([
'administer content types',
'access content',
]);
$this
->drupalLogin($user);
$node_type = NodeType::create([
'type' => 'article',
'name' => 'Article',
]);
$node_type
->save();
$edit = [
'type_style[color]' => '#ffffff',
'type_style[icon]' => 'my-icon',
];
$this
->drupalPostForm('/admin/structure/types/manage/article', $edit, t('Save content type'));
$this
->drupalGet('/admin/structure/types/manage/article');
$this
->assertSession()
->pageTextContains('Style settings');
$this
->assertSession()
->responseContains('#ffffff');
$this
->assertSession()
->responseContains('my-icon');
$node = Node::create([
'type' => 'article',
'title' => 'Test',
]);
$node
->save();
$this
->assertEquals(type_style_get_style($node, 'color'), '#ffffff');
$this
->assertEquals(type_style_get_style($node, 'icon'), 'my-icon');
$tests = [
'[node:type-style-icon]' => 'my-icon',
'[node:type-style-color]' => '#ffffff',
'[node:type-style-bogus]' => '[node:type-style-bogus]',
];
foreach ($tests as $input => $output) {
$replaced = \Drupal::token()
->replace($input, [
'node' => $node,
]);
$this
->assertEquals($replaced, $output);
}
}
}