BookSettingsFormTest.php

Same filename in other branches
  1. 10 core/modules/book/tests/src/Kernel/BookSettingsFormTest.php

Namespace

Drupal\Tests\book\Kernel

File

core/modules/book/tests/src/Kernel/BookSettingsFormTest.php

View source
<?php

namespace Drupal\Tests\book\Kernel;

use Drupal\book\Form\BookSettingsForm;
use Drupal\Core\Form\FormState;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;

/**
 * @covers \Drupal\book\Form\BookSettingsForm
 * @group book
 */
class BookSettingsFormTest extends KernelTestBase {
    use ContentTypeCreationTrait;
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'book',
        'field',
        'node',
        'system',
        'text',
        'user',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->installConfig([
            'book',
            'node',
        ]);
        $this->createContentType([
            'type' => 'chapter',
        ]);
        $this->createContentType([
            'type' => 'page',
        ]);
    }
    
    /**
     * Tests that submitted values are processed and saved correctly.
     */
    public function testConfigValuesSavedCorrectly() : void {
        $form_state = new FormState();
        $form_state->setValues([
            'book_allowed_types' => [
                'page',
                'chapter',
                '',
            ],
            'book_child_type' => 'page',
        ]);
        $this->container
            ->get('form_builder')
            ->submitForm(BookSettingsForm::class, $form_state);
        $config = $this->config('book.settings');
        $this->assertSame([
            'chapter',
            'page',
        ], $config->get('allowed_types'));
        $this->assertSame('page', $config->get('child_type'));
    }

}

Classes

Title Deprecated Summary
BookSettingsFormTest @covers \Drupal\book\Form\BookSettingsForm @group book

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.