本文整理汇总了PHP中Drupal\node\Entity\NodeType::load方法的典型用法代码示例。如果您正苦于以下问题:PHP NodeType::load方法的具体用法?PHP NodeType::load怎么用?PHP NodeType::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\node\Entity\NodeType
的用法示例。
在下文中一共展示了NodeType::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNodeFormSaveWithoutRevision
/**
* Checks that unchecking 'Create new revision' works when editing a node.
*/
function testNodeFormSaveWithoutRevision()
{
$this->drupalLogin($this->editor);
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Set page revision setting 'create new revision'. This will mean new
// revisions are created by default when the node is edited.
$type = NodeType::load('page');
$type->setNewRevision(TRUE);
$type->save();
// Create the node.
$node = $this->drupalCreateNode();
// Verify the checkbox is checked on the node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
// Uncheck the create new revision checkbox and save the node.
$edit = array('revision' => FALSE);
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
// Load the node again and check the revision is the same as before.
$node_storage->resetCache(array($node->id()));
$node_revision = $node_storage->load($node->id(), TRUE);
$this->assertEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' unchecked, a new revision is not created.");
// Verify the checkbox is checked on the node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
// Submit the form without changing the checkbox.
$edit = array();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
// Load the node again and check the revision is different from before.
$node_storage->resetCache(array($node->id()));
$node_revision = $node_storage->load($node->id());
$this->assertNotEqual($node_revision->getRevisionId(), $node->getRevisionId(), "After an existing node is saved with 'Create new revision' checked, a new revision is created.");
}
示例2: testScheduledNodeDelete
/**
* Tests the deletion of a scheduled node.
*
* This tests if it is possible to delete a node that does not have a
* publication date set, when scheduled publishing is required.
*
* @see https://drupal.org/node/1614880
*/
public function testScheduledNodeDelete()
{
// Log in.
$this->drupalLogin($this->adminUser);
// Create a published and an unpublished node, both without scheduling.
$published_node = $this->drupalCreateNode(['type' => 'page', 'status' => 1]);
$unpublished_node = $this->drupalCreateNode(['type' => 'page', 'status' => 0]);
// Make scheduled publishing and unpublishing required.
$node_type = NodeType::load('page');
$node_type->setThirdPartySetting('scheduler', 'publish_required', TRUE);
$node_type->setThirdPartySetting('scheduler', 'unpublish_required', TRUE);
$node_type->save();
// Check that deleting the nodes does not throw form validation errors.
### @TODO Delete was a button in 7.x but a separate link node/<nid>/delete in 8.x
### Is the previous validation (that we had to avoid on delete) still done now in D8, given that there is no form?
### Maybe this test is not actually checking anything useful? Can it be altered to do something testable?
$this->drupalGet('node/' . $published_node->id() . '/delete');
// Note that the text 'error message' is used in a header h2 html tag which
// is normally made hidden from browsers but will be in the page source.
// It is also good when testing for the absense of somthing to also test
// for the presence of text, hence the second assertion for each check.
$this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete a published node with no scheduling information.');
$this->assertRaw(t('Are you sure you want to delete the content'), 'The deletion warning message is shown immediately when trying to delete a published node with no scheduling information.');
$this->drupalGet('node/' . $unpublished_node->id() . '/delete');
$this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete an unpublished node with no scheduling information.');
$this->assertRaw(t('Are you sure you want to delete the content'), 'The deletion warning message is shown immediately when trying to delete an unpublished node with no scheduling information.');
}
示例3: testNodeType
/**
* Tests Drupal 6 node type to Drupal 8 migration.
*/
public function testNodeType()
{
$migration = entity_load('migration', 'd6_node_type');
// Test the test_page content type.
$node_type_page = NodeType::load('test_page');
$this->assertIdentical('test_page', $node_type_page->id(), 'Node type test_page loaded');
$this->assertIdentical(TRUE, $node_type_page->displaySubmitted());
$this->assertIdentical(FALSE, $node_type_page->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_page->getPreviewMode());
$this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_page')), array('test_page'));
// Test we have a body field.
$field = FieldConfig::loadByName('node', 'test_page', 'body');
$this->assertIdentical('This is the body field label', $field->getLabel(), 'Body field was found.');
// Test the test_story content type.
$node_type_story = NodeType::load('test_story');
$this->assertIdentical('test_story', $node_type_story->id(), 'Node type test_story loaded');
$this->assertIdentical(TRUE, $node_type_story->displaySubmitted());
$this->assertIdentical(FALSE, $node_type_story->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_story->getPreviewMode());
$this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_story')), array('test_story'));
// Test we don't have a body field.
$field = FieldConfig::loadByName('node', 'test_story', 'body');
$this->assertIdentical(NULL, $field, 'No body field found');
// Test the test_event content type.
$node_type_event = NodeType::load('test_event');
$this->assertIdentical('test_event', $node_type_event->id(), 'Node type test_event loaded');
$this->assertIdentical(TRUE, $node_type_event->displaySubmitted());
$this->assertIdentical(TRUE, $node_type_event->isNewRevision());
$this->assertIdentical(DRUPAL_OPTIONAL, $node_type_event->getPreviewMode());
$this->assertIdentical($migration->getIdMap()->lookupDestinationID(array('test_event')), array('test_event'));
// Test we have a body field.
$field = FieldConfig::loadByName('node', 'test_event', 'body');
$this->assertIdentical('Body', $field->getLabel(), 'Body field was found.');
}
示例4: testRecreateEntity
public function testRecreateEntity()
{
$type_name = Unicode::strtolower($this->randomMachineName(16));
$content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type one'));
$content_type->save();
node_add_body_field($content_type);
/** @var \Drupal\Core\Config\StorageInterface $active */
$active = $this->container->get('config.storage');
/** @var \Drupal\Core\Config\StorageInterface $sync */
$sync = $this->container->get('config.storage.sync');
$config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id();
$this->copyConfig($active, $sync);
// Delete the content type. This will also delete a field storage, a field,
// an entity view display and an entity form display.
$content_type->delete();
$this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
// Recreate with the same type - this will have a different UUID.
$content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type two'));
$content_type->save();
node_add_body_field($content_type);
$this->configImporter->reset();
// A node type, a field, an entity view display and an entity form display
// will be recreated.
$creates = $this->configImporter->getUnprocessedConfiguration('create');
$deletes = $this->configImporter->getUnprocessedConfiguration('delete');
$this->assertEqual(5, count($creates), 'There are 5 configuration items to create.');
$this->assertEqual(5, count($deletes), 'There are 5 configuration items to delete.');
$this->assertEqual(0, count($this->configImporter->getUnprocessedConfiguration('update')), 'There are no configuration items to update.');
$this->assertIdentical($creates, array_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');
$this->configImporter->import();
// Verify that there is nothing more to import.
$this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
$content_type = NodeType::load($type_name);
$this->assertEqual('Node type one', $content_type->label());
}
示例5: testDisplayRevisionTab
/**
* Checks that the Revision tab is displayed correctly.
*/
function testDisplayRevisionTab()
{
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalLogin($this->editor);
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Set page revision setting 'create new revision'. This will mean new
// revisions are created by default when the node is edited.
$type = NodeType::load('page');
$type->setNewRevision(TRUE);
$type->save();
// Create the node.
$node = $this->drupalCreateNode();
// Verify the checkbox is checked on the node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
// Uncheck the create new revision checkbox and save the node.
$edit = array('revision' => FALSE);
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save and keep published');
$this->assertUrl($node->toUrl());
$this->assertNoLink(t('Revisions'));
// Verify the checkbox is checked on the node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertFieldChecked('edit-revision', "'Create new revision' checkbox is checked");
// Submit the form without changing the checkbox.
$edit = array();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save and keep published');
$this->assertUrl($node->toUrl());
$this->assertLink(t('Revisions'));
}
示例6: setUp
protected function setUp()
{
parent::setUp();
node_access_test_add_field(NodeType::load('article'));
node_access_rebuild();
\Drupal::state()->set('node_access_test.private', TRUE);
}
示例7: testForumUninstallWithField
/**
* Tests if forum module uninstallation properly deletes the field.
*/
public function testForumUninstallWithField()
{
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'administer nodes', 'administer modules', 'delete any forum content', 'administer content types']));
// Ensure that the field exists before uninstallation.
$field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums');
$this->assertNotNull($field_storage, 'The taxonomy_forums field storage exists.');
// Create a taxonomy term.
$term = Term::create(['name' => t('A term'), 'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), 'description' => '', 'parent' => array(0), 'vid' => 'forums', 'forum_container' => 0]);
$term->save();
// Create a forum node.
$node = $this->drupalCreateNode(array('title' => 'A forum post', 'type' => 'forum', 'taxonomy_forums' => array(array('target_id' => $term->id()))));
// Create at least one comment against the forum node.
$comment = Comment::create(array('entity_id' => $node->nid->value, 'entity_type' => 'node', 'field_name' => 'comment_forum', 'pid' => 0, 'uid' => 0, 'status' => CommentInterface::PUBLISHED, 'subject' => $this->randomMachineName(), 'hostname' => '127.0.0.1'));
$comment->save();
// Attempt to uninstall forum.
$this->drupalGet('admin/modules/uninstall');
// Assert forum is required.
$this->assertNoFieldByName('uninstall[forum]');
$this->assertText('To uninstall Forum, first delete all Forum content');
// Delete the node.
$this->drupalPostForm('node/' . $node->id() . '/delete', array(), t('Delete'));
// Attempt to uninstall forum.
$this->drupalGet('admin/modules/uninstall');
// Assert forum is still required.
$this->assertNoFieldByName('uninstall[forum]');
$this->assertText('To uninstall Forum, first delete all Forums terms');
// Delete any forum terms.
$vid = $this->config('forum.settings')->get('vocabulary');
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vid]);
foreach ($terms as $term) {
$term->delete();
}
// Ensure that the forum node type can not be deleted.
$this->drupalGet('admin/structure/types/manage/forum');
$this->assertNoLink(t('Delete'));
// Now attempt to uninstall forum.
$this->drupalGet('admin/modules/uninstall');
// Assert forum is no longer required.
$this->assertFieldByName('uninstall[forum]');
$this->drupalPostForm('admin/modules/uninstall', array('uninstall[forum]' => 1), t('Uninstall'));
$this->drupalPostForm(NULL, [], t('Uninstall'));
// Check that the field is now deleted.
$field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums');
$this->assertNull($field_storage, 'The taxonomy_forums field storage has been deleted.');
// Check that a node type with a machine name of forum can be created after
// uninstalling the forum module and the node type is not locked.
$edit = array('name' => 'Forum', 'title_label' => 'title for forum', 'type' => 'forum');
$this->drupalPostForm('admin/structure/types/add', $edit, t('Save content type'));
$this->assertTrue((bool) NodeType::load('forum'), 'Node type with machine forum created.');
$this->drupalGet('admin/structure/types/manage/forum');
$this->clickLink(t('Delete'));
$this->drupalPostForm(NULL, array(), t('Delete'));
$this->assertResponse(200);
$this->assertFalse((bool) NodeType::load('forum'), 'Node type with machine forum deleted.');
// Double check everything by reinstalling the forum module again.
$this->drupalPostForm('admin/modules', ['modules[Core][forum][enable]' => 1], 'Install');
$this->assertText('Module Forum has been enabled.');
}
示例8: setUp
protected function setUp()
{
parent::setUp();
node_access_rebuild();
$this->drupalCreateContentType(array('type' => 'page'));
node_access_test_add_field(NodeType::load('page'));
$this->addDefaultCommentField('node', 'page', 'comment', CommentItemInterface::OPEN);
\Drupal::state()->set('node_access_test.private', TRUE);
}
示例9: testRequiredScheduling
/**
* Tests creating and editing nodes with required scheduling enabled.
*/
public function testRequiredScheduling()
{
$this->drupalLogin($this->adminUser);
// Define test scenarios with expected results.
$test_cases = [['id' => 0, 'required' => '', 'operation' => 'add', 'status' => 1, 'expected' => 'not required', 'message' => 'By default when a new node is created, the publish on and unpublish on dates are not required.'], ['id' => 1, 'required' => 'publish', 'operation' => 'add', 'status' => 0, 'expected' => 'required', 'message' => 'When scheduled publishing is required and a new unpublished node is created, entering a date in the publish on field is required.'], ['id' => 2, 'required' => 'publish', 'operation' => 'add', 'status' => 1, 'expected' => 'required', 'message' => 'When scheduled publishing is required and a new published node is created, entering a date in the publish on field is required.'], ['id' => 3, 'required' => 'publish', 'operation' => 'edit', 'scheduled' => 0, 'status' => 1, 'expected' => 'not required', 'message' => 'When scheduled publishing is required and an existing published, unscheduled node is edited, entering a date in the publish on field is not required.'], ['id' => 4, 'required' => 'publish', 'operation' => 'edit', 'scheduled' => 1, 'status' => 0, 'expected' => 'required', 'message' => 'When scheduled publishing is required and an existing unpublished, scheduled node is edited, entering a date in the publish on field is required.'], ['id' => 5, 'required' => 'publish', 'operation' => 'edit', 'scheduled' => 0, 'status' => 0, 'expected' => 'not required', 'message' => 'When scheduled publishing is required and an existing unpublished, unscheduled node is edited, entering a date in the publish on field is not required.'], ['id' => 6, 'required' => 'unpublish', 'operation' => 'add', 'status' => 0, 'expected' => 'required', 'message' => 'When scheduled unpublishing is required and a new unpublished node is created, entering a date in the unpublish on field is required.'], ['id' => 7, 'required' => 'unpublish', 'operation' => 'add', 'status' => 1, 'expected' => 'required', 'message' => 'When scheduled unpublishing is required and a new published node is created, entering a date in the unpublish on field is required.'], ['id' => 8, 'required' => 'unpublish', 'operation' => 'edit', 'scheduled' => 0, 'status' => 1, 'expected' => 'required', 'message' => 'When scheduled unpublishing is required and an existing published, unscheduled node is edited, entering a date in the unpublish on field is required.'], ['id' => 9, 'required' => 'unpublish', 'operation' => 'edit', 'scheduled' => 1, 'status' => 0, 'expected' => 'required', 'message' => 'When scheduled unpublishing is required and an existing unpublished, scheduled node is edited, entering a date in the unpublish on field is required.'], ['id' => 10, 'required' => 'unpublish', 'operation' => 'edit', 'scheduled' => 0, 'status' => 0, 'expected' => 'not required', 'message' => 'When scheduled unpublishing is required and an existing unpublished, unscheduled node is edited, entering a date in the unpublish on field is not required.']];
$node_type = NodeType::load('page');
$fields = \Drupal::entityManager()->getFieldDefinitions('node', 'page');
foreach ($test_cases as $test_case) {
// Set required (un)publishing as stipulated by the test case.
if (!empty($test_case['required'])) {
$node_type->setThirdPartySetting('scheduler', 'publish_required', $test_case['required'] == 'publish')->setThirdPartySetting('scheduler', 'unpublish_required', $test_case['required'] == 'unpublish')->save();
}
// To assist viewing and analysing the generated test result pages create
// a text string showing all the test case parameters.
$title_data = [];
foreach ($test_case as $key => $value) {
if ($key != 'message') {
$title_data[] = $key . ' = ' . $value;
}
}
$title = implode(', ', $title_data);
// If the test case requires editing a node, we need to create one first.
if ($test_case['operation'] == 'edit') {
// Note: The key names in the $options parameter for drupalCreateNode()
// are the plain field names i.e. 'title' not title[0][value]
$options = ['title' => $title, 'type' => 'page', 'status' => $test_case['status'], 'publish_on' => !empty($test_case['scheduled']) ? strtotime('+1 day') : NULL];
$node = $this->drupalCreateNode($options);
// Define the path and button to use for editing the node.
$path = 'node/' . $node->id() . '/edit';
$button_text = $node->status->value ? t('Save and keep published') : t('Save and keep unpublished');
} else {
// Set the default status, used when testing creation of the new node.
$fields['status']->getConfig('page')->setDefaultValue($test_case['status'])->save();
// Define the path and button to use for creating the node.
$path = 'node/add/page';
$button_text = t('Save and publish');
}
// Make sure that both date fields are empty so we can check if they throw
// validation errors when the fields are required.
$edit = ['title[0][value]' => $title, 'publish_on[0][value][date]' => '', 'publish_on[0][value][time]' => '', 'unpublish_on[0][value][date]' => '', 'unpublish_on[0][value][time]' => ''];
$this->drupalPostForm($path, $edit, $button_text);
// Check for the expected result.
switch ($test_case['expected']) {
case 'required':
$string = t('The %name date is required.', ['%name' => ucfirst($test_case['required']) . ' on']);
$this->assertRaw($string, $test_case['id'] . '. ' . $test_case['message']);
break;
case 'not required':
$string = '@type %title has been ' . ($test_case['operation'] == 'add' ? 'created' : 'updated') . '.';
$args = ['@type' => 'Basic page', '%title' => $title];
// @codingStandardsIgnoreStart
$this->assertRaw(t($string, $args), $test_case['id'] . '. ' . $test_case['message']);
// @codingStandardsIgnoreEnd
break;
}
}
}
示例10: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
// Create Article node type.
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
$this->accessHandler = \Drupal::entityManager()->getAccessControlHandler('node');
node_access_test_add_field(NodeType::load('article'));
// After enabling a node access module, the access table has to be rebuild.
node_access_rebuild();
// Enable the private node feature of the node_access_test module.
\Drupal::state()->set('node_access_test.private', TRUE);
}
示例11: setUp
protected function setUp()
{
parent::setUp();
node_access_test_add_field(NodeType::load('page'));
// After enabling a node access module, the access table has to be rebuild.
node_access_rebuild();
// Enable the private node feature of the node_access_test module.
\Drupal::state()->set('node_access_test.private', TRUE);
// Add Hungarian, Catalan and Croatian.
ConfigurableLanguage::createFromLangcode('hu')->save();
ConfigurableLanguage::createFromLangcode('ca')->save();
ConfigurableLanguage::createFromLangcode('hr')->save();
}
示例12: testEventType
/**
* Test event types in UI.
*/
function testEventType()
{
$web_user = $this->drupalCreateUser(['administer event types', 'access administration pages']);
$this->drupalLogin($web_user);
// Create and delete the testing event type.
$event_bundle = $this->drupalCreateContentType();
$event_type = $this->createEventType($event_bundle);
$this->drupalGet('admin/structure/rng/event_types/manage/' . $event_type->id() . '/edit');
$event_type->delete();
$event_bundle->delete();
// Event types button on admin.
$this->drupalGet('admin/structure');
$this->assertLinkByHref(Url::fromRoute('rng.event_type.overview')->toString());
$this->assertRaw('Manage which entity bundles are designated as events.', 'Button shows in administration.');
// No events.
$this->assertEqual(0, count(EventType::loadMultiple()), 'There are no event type entities.');
$this->drupalGet('admin/structure/rng/event_types');
$this->assertRaw('No event types found.', 'Event Type list is empty');
// There are no courier contexts.
$this->assertEqual(0, count(CourierContext::loadMultiple()), 'There are no courier context entities.');
// Local action.
$this->assertLinkByHref(Url::fromRoute('entity.event_type.add')->toString());
// Add.
$t_args = ['%label' => 'node.event'];
$edit = [];
$this->drupalPostForm('admin/structure/rng/event_types/add', $edit, t('Save'));
/** @var \Drupal\node\NodeTypeInterface $node_type */
$node_type = NodeType::load('event');
$this->assertEqual(1, count(EventType::loadMultiple()), 'Event type exists in database.');
$this->assertRaw(t('The content type <a href=":url">%label</a> has been added.', ['%label' => $node_type->label(), ':url' => $node_type->toUrl()->toString()]), 'Node was created for Event Type');
$this->assertRaw(t('%label event type added.', $t_args), 'Event Type created');
// Courier context created?
$this->assertTrue(CourierContext::load('rng_registration_node'), 'Courier context entity created for this event type\' entity type.');
// Event type list.
$this->assertUrl('admin/structure/rng/event_types', [], 'Browser was redirected to event type list.');
$this->assertRaw('<td>Content: event</td>', 'Event Type shows in list');
$options = ['node_type' => 'event'];
$this->assertLinkByHref(Url::fromRoute("entity.node.field_ui_fields", $options)->toString());
// Edit form.
$edit = [];
$this->drupalPostForm('admin/structure/rng/event_types/manage/node.event/edit', $edit, t('Save'));
$this->assertRaw(t('%label event type updated.', $t_args), 'Event Type edit form saved');
// Delete form.
$this->drupalGet('admin/structure/rng/event_types/manage/node.event/delete');
$this->assertRaw('Are you sure you want to delete event type node.event?', 'Event Type delete form rendered.');
$this->drupalPostForm('admin/structure/rng/event_types/manage/node.event/delete', [], t('Delete'));
$this->assertRaw(t('Event type %label was deleted.', $t_args), 'Event Type delete form saved');
$this->assertEqual(0, count(EventType::loadMultiple()), 'Event type deleted from database.');
// @todo: ensure conditional on form omits node/existing radios
// @todo create event type with custom entity
}
示例13: getDerivativeDefinitions
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition)
{
$node_types = simplenews_get_content_types();
$node_type = reset($node_types);
if (count($node_types) == 1) {
$label = NodeType::load($node_type)->label();
$this->derivatives[$node_type] = $base_plugin_definition;
$this->derivatives[$node_type]['title'] = new TranslationWrapper('Add @label', array('@label' => $label));
$this->derivatives[$node_type]['route_parameters'] = array('node_type' => $node_type);
} elseif (count($node_types) > 1) {
$base_plugin_definition['route_name'] = 'node.add_page';
$base_plugin_definition['title'] = new TranslationWrapper('Add content');
$this->derivatives[] = $base_plugin_definition;
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
示例14: assertEntity
/**
* Tests a single node type.
*
* @dataProvider testNodeTypeDataProvider
*
* @param string $id
* The node type ID.
* @param string $label
* The expected label.
* @param string $description
* The expected node type description.
* @param string $help
* The expected help text.
*/
protected function assertEntity($id, $label, $description, $help, $display_submitted, $new_revision, $body_label = NULL)
{
/** @var \Drupal\node\NodeTypeInterface $entity */
$entity = NodeType::load($id);
$this->assertTrue($entity instanceof NodeTypeInterface);
$this->assertIdentical($label, $entity->label());
$this->assertIdentical($description, $entity->getDescription());
$this->assertIdentical($help, $entity->getHelp());
$this->assertIdentical($display_submitted, $entity->displaySubmitted(), 'Submission info is displayed');
$this->assertIdentical($new_revision, $entity->isNewRevision(), 'Is a new revision');
if ($body_label) {
/** @var \Drupal\field\FieldConfigInterface $body */
$body = FieldConfig::load('node.' . $id . '.body');
$this->assertTrue($body instanceof FieldConfigInterface);
$this->assertIdentical($body_label, $body->label());
}
}
示例15: testLegacyContent
/**
* Verifies that content without prior moderation information can be moderated.
*/
public function testLegacyContent()
{
$node_type = NodeType::create(['type' => 'example']);
$node_type->save();
$node = Node::create(['type' => 'example', 'title' => 'Test title']);
$node->save();
// Enable moderation for Articles.
/** @var NodeType $node_type */
$node_type = NodeType::load('example');
$node_type->setThirdPartySetting('workbench_moderation', 'enabled', TRUE);
$node_type->setThirdPartySetting('workbench_moderation', 'allowed_moderation_states', ['draft', 'needs_review', 'published']);
$node_type->setThirdPartySetting('workbench_moderation', 'default_moderation_state', 'draft');
$node_type->save();
// Having no previous state should not break validation.
$violations = $node->validate();
$this->assertCount(0, $violations);
}