1.20.x node.test NodeTypePersistenceTestCase::testNodeTypeCustomizationPersistence()

Tests that node type customizations persist through disable and uninstall.

File

modules/node/tests/node.test, line 2024
Tests for node.module.

Class

NodeTypePersistenceTestCase
Test node type customizations persistence.

Code

function testNodeTypeCustomizationPersistence() {
  $web_user = $this->backdropCreateUser(array('bypass node access', 'administer content types', 'administer modules'));
  $this->backdropLogin($web_user);

  // Enable the test module and verify that the test node type is in the DB
  // and is not disabled.
  module_enable(array('node_test'), FALSE);
  $config = config('node.type.test');
  $this->assertFalse($config->isNew(), 'Test node type found in config.');
  $this->assertEqual($config->get('disabled'), 0, 'Test node type is not disabled');

  // Check that test node type (uncustomized) shows up.
  $this->backdropGet('node/add');
  $this->assertText('test', 'Test type is found on node/add');

  // Customize book description.
  $description = $this->randomName();
  $edit = array('description' => $description);
  $this->backdropPost('admin/structure/types/manage/test', $edit, t('Save content type'));

  // Check that Test node type customization shows up.
  $this->backdropGet('node/add');
  $this->assertText($description, 'Customized description found');

  // Disable test node module and check that the node type gets disabled.
  module_disable(array('node_test'), FALSE);
  $node_type = node_type_get_type('test');
  $this->assertEqual($node_type->disabled, 1, 'Test node type is disabled');
  $this->backdropGet('node/add');
  $this->assertNoText('book', 'Test node type is not found on node/add');

  // Reenable the test node module and check that the customization survived
  // the module disable.
  module_enable(array('node_test'), FALSE);
  $node_type = node_type_get_type('test');
  $this->assertEqual($node_type->disabled, 0, 'Test node type is not disabled');
  $this->backdropGet('node/add');
  $this->assertText($description, 'Customized description found');

  // Disable and uninstall book.
  module_disable(array('node_test'), FALSE);
  backdrop_uninstall_modules(array('node_test'));
  $node_type = node_type_get_type('test');
  $this->assertTrue($node_type->disabled, 'Test node type still exists after uninstalling, but is disabled');
  $this->backdropGet('node/add');
  $this->assertNoText('test', 'Test type is no longer found on node/add');

  // Reenable the test node module and check that the customization survived
  // the module uninstall.
  module_enable(array('node_test'), FALSE);
  $this->backdropGet('node/add');
  $this->assertText($description, 'Customized description is found even after uninstall and reenable.');
}