Skip to content
Snippets Groups Projects

Issue # 3513301: Added an initial Basic Test Class file.

Files
2
+ 141
0
<?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);
}
}
Loading