Same name and namespace in other branches
  1. 8.x-1.x tests/src/Functional/EntityCloneDateFormatTest.php \Drupal\Tests\entity_clone\Functional\EntityCloneDateFormatTest 1 comment

Create a date format and test a clone.

@group entity_clone

Hierarchy

  • class \Drupal\Tests\entity_clone\Functional\EntityCloneDateFormatTest extends \Drupal\Tests\BrowserTestBase uses \Drupal\Core\StringTranslation\StringTranslationTrait

Expanded class hierarchy of EntityCloneDateFormatTest

File

tests/src/Functional/EntityCloneDateFormatTest.php, line 14

Namespace

Drupal\Tests\entity_clone\Functional
View source
class EntityCloneDateFormatTest extends BrowserTestBase {
    use StringTranslationTrait;
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    protected static $modules = [
        'entity_clone',
    ];
    
    /**
     * Theme to enable by default.
     *
     * @var string
     */
    protected $defaultTheme = 'claro';
    
    /**
     * Permissions to grant admin user.
     *
     * @var array
     */
    protected $permissions = [
        'clone date_format entity',
        'administer site configuration',
    ];
    
    /**
     * An administrative user with permission to configure date formats settings.
     *
     * @var \Drupal\user\UserInterface
     */
    protected $adminUser;
    
    /**
     * Sets the test up.
     */
    protected function setUp() : void {
        parent::setUp();
        $this->adminUser = $this->drupalCreateUser($this->permissions);
        $this->drupalLogin($this->adminUser);
    }
    
    /**
     * Test date format entity clone.
     */
    public function testDateFormatEntityClone() {
        $edit = [
            'label' => 'Test date format for clone',
            'id' => 'test_date_format_for_clone',
            'date_format_pattern' => 'Y m d',
        ];
        $this->drupalGet("admin/config/regional/date-time/formats/add");
        $this->submitForm($edit, $this->t('Add format'));
        $date_formats = \Drupal::entityTypeManager()->getStorage('date_format')
            ->loadByProperties([
            'id' => $edit['id'],
        ]);
        $date_format = reset($date_formats);
        $edit = [
            'id' => 'test_date_format_cloned',
            'label' => 'Test date format cloned',
        ];
        $this->drupalGet('entity_clone/date_format/' . $date_format->id());
        $this->submitForm($edit, $this->t('Clone'));
        $date_formats = \Drupal::entityTypeManager()->getStorage('date_format')
            ->loadByProperties([
            'id' => $edit['id'],
        ]);
        $date_format = reset($date_formats);
        $this->assertInstanceOf(DateFormat::class, $date_format, 'Test date format cloned found in database.');
    }

}

Members

Title Sort descending Modifiers Object type Summary
EntityCloneDateFormatTest::$adminUser protected property An administrative user with permission to configure date formats settings.
EntityCloneDateFormatTest::$defaultTheme protected property Theme to enable by default.
EntityCloneDateFormatTest::$modules protected static property Modules to enable.
EntityCloneDateFormatTest::$permissions protected property Permissions to grant admin user.
EntityCloneDateFormatTest::setUp protected function Sets the test up.
EntityCloneDateFormatTest::testDateFormatEntityClone public function Test date format entity clone.