public function MenuLinkContentUpdateTest::testConversionToRevisionable in Drupal 8
Tests the conversion of custom menu links to be revisionable.
See also
menu_link_content_post_update_make_menu_link_content_revisionable()
File
- core/
modules/ menu_link_content/ tests/ src/ Functional/ Update/ MenuLinkContentUpdateTest.php, line 69
Class
- MenuLinkContentUpdateTest
- Tests the upgrade path for custom menu links.
Namespace
Drupal\Tests\menu_link_content\Functional\UpdateCode
public function testConversionToRevisionable() {
$entity_type = \Drupal::entityDefinitionUpdateManager()
->getEntityType('menu_link_content');
$this
->assertFalse($entity_type
->isRevisionable());
// Set the batch size to 1 to test multiple steps.
drupal_rewrite_settings([
'settings' => [
'update_sql_batch_size' => (object) [
'value' => 1,
'required' => TRUE,
],
],
]);
// Check that there are broken menu links in the database tables, initially.
$this
->assertMenuLinkTitle(997, '');
$this
->assertMenuLinkTitle(998, '');
$this
->assertMenuLinkTitle(999, 'menu_link_999-es');
$this
->runUpdates();
// Check that the update function returned the expected message.
$this
->assertSession()
->pageTextContains('Custom menu links have been converted to be revisionable. 2 menu links with data integrity issues were restored. More details have been logged.');
$entity_type = \Drupal::entityDefinitionUpdateManager()
->getEntityType('menu_link_content');
$this
->assertTrue($entity_type
->isRevisionable());
// Log in as user 1.
$account = User::load(1);
$account->passRaw = 'drupal';
$this
->drupalLogin($account);
// Make sure our custom menu link exists.
$assert_session = $this
->assertSession();
$this
->drupalGet('admin/structure/menu/item/1/edit');
$assert_session
->checkboxChecked('edit-enabled-value');
// Check that custom menu links can be created, saved and then loaded.
$storage = \Drupal::entityTypeManager()
->getStorage('menu_link_content');
/** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link */
$menu_link = $storage
->create([
'menu_name' => 'main',
'link' => 'route:user.page',
'title' => 'Pineapple',
]);
$menu_link
->save();
$storage
->resetCache();
$menu_link = $storage
->loadRevision($menu_link
->getRevisionId());
$this
->assertEquals('main', $menu_link
->getMenuName());
$this
->assertEquals('Pineapple', $menu_link
->label());
$this
->assertEquals('route:user.page', $menu_link->link->uri);
$this
->assertTrue($menu_link
->isPublished());
// Check that two menu links were restored and one was ignored. The latter
// cannot be manually restored, since we would end up with two data table
// records having "default_langcode" equalling 1, which would not make
// sense.
$this
->assertMenuLinkTitle(997, 'menu_link_997');
$this
->assertMenuLinkTitle(998, 'menu_link_998');
$this
->assertMenuLinkTitle(999, 'menu_link_999-es');
}