X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Ffield%2Ftests%2Fsrc%2FFunctional%2FUpdate%2FFieldUpdateTest.php;fp=web%2Fcore%2Fmodules%2Ffield%2Ftests%2Fsrc%2FFunctional%2FUpdate%2FFieldUpdateTest.php;h=b9175b127794a2d229732567c0299438a7f7befe;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/field/tests/src/Functional/Update/FieldUpdateTest.php b/web/core/modules/field/tests/src/Functional/Update/FieldUpdateTest.php new file mode 100644 index 000000000..b9175b127 --- /dev/null +++ b/web/core/modules/field/tests/src/Functional/Update/FieldUpdateTest.php @@ -0,0 +1,162 @@ +configFactory = $this->container->get('config.factory'); + } + + /** + * {@inheritdoc} + */ + protected function setDatabaseDumpFiles() { + $this->databaseDumpFiles = [ + __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.bare.standard.php.gz', + __DIR__ . '/../../../fixtures/update/drupal-8.views_entity_reference_plugins-2429191.php', + __DIR__ . '/../../../fixtures/update/drupal-8.remove_handler_submit_setting-2715589.php', + ]; + } + + /** + * Tests field_update_8001(). + * + * @see field_update_8001() + */ + public function testFieldUpdate8001() { + // Load the 'node.field_image' field storage config, and check that is has + // a 'target_bundle' setting. + $config = $this->configFactory->get('field.storage.node.field_image'); + $settings = $config->get('settings'); + $this->assertTrue(array_key_exists('target_bundle', $settings)); + + // Run updates. + $this->runUpdates(); + + // Reload the config, and check that the 'target_bundle' setting has been + // removed. + $config = $this->configFactory->get('field.storage.node.field_image'); + $settings = $config->get('settings'); + $this->assertFalse(array_key_exists('target_bundle', $settings)); + } + + /** + * Tests field_update_8002(). + * + * @see field_update_8002() + */ + public function testFieldUpdate8002() { + // Check that 'entity_reference' is the provider and a dependency of the + // test field storage . + $field_storage = $this->configFactory->get('field.storage.node.field_ref_views_select_2429191'); + $this->assertIdentical($field_storage->get('module'), 'entity_reference'); + $this->assertEntityRefDependency($field_storage, TRUE); + + // Check that 'entity_reference' is a dependency of the test field. + $field = $this->configFactory->get('field.field.node.article.field_ref_views_select_2429191'); + $this->assertEntityRefDependency($field, TRUE); + + // Check that 'entity_reference' is a dependency of the test view. + $view = $this->configFactory->get('views.view.entity_reference_plugins_2429191'); + $this->assertEntityRefDependency($view, TRUE); + + // Run updates. + $this->runUpdates(); + + // Check that 'entity_reference' is no longer a dependency of the test field + // and view. + $field_storage = $this->configFactory->get('field.storage.node.field_ref_views_select_2429191'); + $this->assertIdentical($field_storage->get('module'), 'core'); + $this->assertEntityRefDependency($field_storage, FALSE); + $field = $this->configFactory->get('field.field.node.article.field_ref_views_select_2429191'); + $this->assertEntityRefDependency($field, FALSE); + $view = $this->configFactory->get('views.view.entity_reference_plugins_2429191'); + $this->assertEntityRefDependency($view, FALSE); + + // Check that field selection, based on the view, still works. It only + // selects nodes whose title contains 'foo'. + $node_1 = Node::create(['type' => 'article', 'title' => 'foobar']); + $node_1->save(); + $node_2 = Node::create(['type' => 'article', 'title' => 'barbaz']); + $node_2->save(); + $field = FieldConfig::load('node.article.field_ref_views_select_2429191'); + $selection = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($field); + $referencable = $selection->getReferenceableEntities(); + $this->assertEqual(array_keys($referencable['article']), [$node_1->id()]); + } + + /** + * Tests field_update_8003(). + * + * @see field_update_8003() + */ + public function testFieldUpdate8003() { + // Run updates. + $this->runUpdates(); + + // Check that the new 'auto_create_bundle' setting is populated correctly. + $field = $this->configFactory->get('field.field.node.article.field_ref_autocreate_2412569'); + $handler_settings = $field->get('settings.handler_settings'); + + $expected_target_bundles = ['tags' => 'tags', 'test' => 'test']; + $this->assertEqual($handler_settings['target_bundles'], $expected_target_bundles); + + $this->assertTrue($handler_settings['auto_create']); + $this->assertEqual($handler_settings['auto_create_bundle'], 'tags'); + } + + /** + * Asserts that a config depends on 'entity_reference' or not + * + * @param \Drupal\Core\Config\Config $config + * The config to test. + * @param bool $present + * TRUE to test that entity_reference is present, FALSE to test that it is + * absent. + */ + protected function assertEntityRefDependency(Config $config, $present) { + $dependencies = $config->get('dependencies'); + $dependencies += ['module' => []]; + $this->assertEqual(in_array('entity_reference', $dependencies['module']), $present); + } + + /** + * Tests field_post_update_remove_handler_submit_setting(). + * + * @see field_post_update_remove_handler_submit_setting() + */ + public function testEntityReferenceFieldConfigCleanUpdate() { + $field_config = $this->config('field.field.node.article.field_tags'); + // Check that 'handler_submit' key exists in field config settings. + $this->assertEquals('Change handler', $field_config->get('settings.handler_submit')); + + $this->runUpdates(); + + $field_config = $this->config('field.field.node.article.field_tags'); + // Check that 'handler_submit' has been removed from field config settings. + $this->assertArrayNotHasKey('handler_submit', $field_config->get('settings')); + } + +}