diff --git a/README.md b/README.md index 1b68ee4224794045a5d09a58cfb3ddde88073327..9e4e60e7ebd887e769cbbc16579dc34ba0926b51 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,8 @@ The Date Timepicker module requires the following JavaScript libraries: - [jQuery Timepicker Addon](https://github.com/trentrichardson/jQuery -Timepicker-Addon) -Follow the installation instructions below for installing the module and the libraries. +Follow the installation instructions below for installing the module and +the libraries. Installation ------------ @@ -50,7 +51,8 @@ Installation 2. Install merge plugin using `composer require wikimedia/composer-merge-plugin` -3. Edit your site's composer.json file and add the following under the "extra" section: +3. Edit your site's composer.json file and add the following under + the "extra" section: ``` "merge-plugin": { "include": [ diff --git a/tests/src/Functional/TimepickerAdminTest.php b/tests/src/Functional/TimepickerAdminTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8987368e8986255ee1ece8272a0dca4b62246023 --- /dev/null +++ b/tests/src/Functional/TimepickerAdminTest.php @@ -0,0 +1,141 @@ +<?php + +namespace Drupal\Tests\timepicker\Functional; + +use Drupal\Tests\BrowserTestBase; +use Drupal\node\Entity\Node; +use Drupal\node\Entity\NodeType; +use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem; +use Drupal\field\Entity\FieldConfig; +use Drupal\field\Entity\FieldStorageConfig; +use Drupal\Core\Field\FieldStorageDefinitionInterface; + +/** + * Tests the Timepicker module. + * + * @group timepicker + */ +class TimepickerAdminTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = ['node', 'datetime', 'text', 'timepicker']; + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + + /** + * Tests if user can load the front page among other things. + */ + public function testLoadSite() { + // Load the front page. + $this->drupalGet('<front>'); + + // Confirm that the site didn't throw a server error or something else. + $this->assertSession()->statusCodeEquals(200); + $this->drupalGet("user"); + } + + /** + * Tests if an admin user can log in. + */ + public function testAdminUser() { + // Log in an administrative user. + $this->drupalLogin($this->rootUser); + + $this->drupalGet('admin/config'); + + $session = $this->assertSession(); + $session->statusCodeEquals(200); + } + + /** + * Testing to create a node with a datetime textfield. + */ + public function testLoadSiteAfterChanges() { + // Create the article content type with a datetime and a text textfield. + $node_type = NodeType::create([ + 'type' => 'article', + ]); + $node_type->save(); + + // Add a text field. + $field_storage = FieldStorageConfig::create([ + 'field_name' => 'test_field', + 'entity_type' => 'node', + 'type' => 'text', + ]); + $field_storage->save(); + + $field = FieldConfig::create([ + 'field_name' => 'test_field', + 'entity_type' => 'node', + 'bundle' => 'article', + 'label' => 'Test field', + ]); + $field->save(); + + // Add a datetime field. + $field_datetime_storage = FieldStorageConfig::create([ + 'field_name' => 'field_datetime', + 'type' => 'datetime', + 'entity_type' => 'node', + 'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME], + 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, + ]); + + $field_datetime_storage->save(); + + $field_datetime = FieldConfig::create([ + 'field_storage' => $field_datetime_storage, + 'bundle' => 'article', + ]); + + $field_datetime->save(); + + // Creates two different articles and tests them. + $node1 = Node::create([ + 'title' => 'Test node title', + 'type' => 'article', + 'test_field' => [ + 'value' => 'foo', + ], + 'field_datetime' => [ + 'value' => "2014-08-22T00:00:00", + ], + ]); + $node1->save(); + + $node2 = Node::create([ + 'title' => 'Test node title 2', + 'type' => 'article', + 'test_field' => [ + 'value' => 'food', + ], + 'field_datetime' => [ + 'value' => "2023-02-14T00:00:00", + ], + ]); + $node2->save(); + + $this->assertNotEquals($node1, $node2, "There was an error creating the content type or the nodes"); + + } + + /** + * Tests if an admin access to pages again. + */ + public function testAdminUserAfterChanges() { + // Log in an administrative user. + $this->drupalLogin($this->rootUser); + + $this->drupalGet('admin/modules'); + + $session = $this->assertSession(); + $session->statusCodeEquals(200); + } + +}