diff --git a/core/modules/views/lib/Drupal/views/Tests/Entity/EntityDefaultLanguageTest.php b/core/modules/views/lib/Drupal/views/Tests/Entity/EntityDefaultLanguageTest.php index 6854f46..34ae7ea 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Entity/EntityDefaultLanguageTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Entity/EntityDefaultLanguageTest.php @@ -2,7 +2,7 @@ /** * @file - * Tests for checking that default entity language is properly generated. + * Contains \Drupal\system\Tests\Entity\EntityDefaultLanguageTest. */ namespace Drupal\system\Tests\Entity; @@ -13,7 +13,14 @@ /** * Tests default language code is properly generated for entities. */ -class EntityTranslationDefaultLanguageTest extends WebTestBase { +class EntityDefaultLanguageTest extends WebTestBase { + + /** + * The module handler. + * + * @var Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; /** * Modules to enable. @@ -24,7 +31,7 @@ class EntityTranslationDefaultLanguageTest extends WebTestBase { public static function getInfo() { return array( - 'name' => 'Entity Translation default language', + 'name' => 'Entity default language', 'description' => 'Test that entities are created with correct language code.', 'group' => 'Entity API', ); @@ -53,57 +60,59 @@ public function setUp() { $this->createContentType('ctund', Language::LANGCODE_NOT_SPECIFIED); // Create a new content type which has Spanish language by default. $this->createContentType('ctes', 'es'); + + $this->moduleHandler = $this->container->get('module_handler'); } /** * Tests that default language code is properly set for new nodes. */ public function testEntityTranslationDefaultLanguageViaCode() { - // With language module activated, and content type that is configured to - // have language "und" by default, a new node of this type will have "und" - // language code when language is not specified. - $node = $this->createNodeViaCode('ctund'); + // With language module activated, and a content type that is configured to + // have no language by default, a new node of this content type will have + // "und" language code when language is not specified. + $node = $this->drupalCreateNode(array('type' => 'ctund', 'langcode' => NULL)); $this->assertEqual($node->langcode->value, Language::LANGCODE_NOT_SPECIFIED); - // With language module activated, and content type that is configured to - // have language "und" by default, a new node of this type will have "es" - // language code when language "es" is specified. - $node = $this->createNodeViaCode('ctund', 'es'); + // With language module activated, and a content type that is configured to + // have no language by default, a new node of this content type will have + // "es" language code when language is specified as "es". + $node = $this->drupalCreateNode(array('type' => 'ctund', 'langcode' => 'es')); $this->assertEqual($node->langcode->value, 'es'); - // With language module activated, and content type that is configured to - // have language "es" by default, a new node of this type will have "es" - // language code when language is not specified. - $node = $this->createNodeViaCode('ctes'); + // With language module activated, and a content type that is configured to + // have language "es" by default, a new node of this content type will have + // "es" language code when language is not specified. + $node = $this->drupalCreateNode(array('type' => 'ctes', 'langcode' => NULL)); $this->assertEqual($node->langcode->value, 'es'); - // With language module activated, and content type that is configured to - // have language "es" by default, a new node of this type will have "en" - // language code when language "en" is specified. - $node = $this->createNodeViaCode('ctes', 'en'); + // With language module activated, and a content type that is configured to + // have language "es" by default, a new node of this content type will have + // "en" language code when language "en" is specified. + $node = $this->drupalCreateNode(array('type' => 'ctes', 'langcode' => 'en')); $this->assertEqual($node->langcode->value, 'en'); // Disable language module. - $this->container->get('module_handler')->uninstall(array('language'), FALSE); + $this->moduleHandler->uninstall(array('language'), FALSE); - // With language module disabled, and content type that is configured to - // have language "und" by default, a new node of this type will have "und" - // language code when language is not specified. - $node = $this->createNodeViaCode('ctund'); + // With language module disabled, and a content type that is configured to + // have no language specified by default, a new node of this content type + // will have "und" language code when language is not specified. + $node = $this->drupalCreateNode(array('type' => 'ctund', 'langcode' => NULL)); $this->assertEqual($node->langcode->value, Language::LANGCODE_NOT_SPECIFIED); - // With language module disabled, and content type that is configured to - // have language "und" by default, a new node of this type will have "es" - // language code when language "es" is specified. - $node = $this->createNodeViaCode('ctund', 'es'); + // With language module disabled, and a content type that is configured to + // have no language specified by default, a new node of this type will have + // "es" language code when language "es" is specified. + $node = $this->drupalCreateNode(array('type' => 'ctund', 'langcode' => 'es')); $this->assertEqual($node->langcode->value, 'es'); - // With language module disabled, and content type that is configured to + // With language module disabled, and a content type that is configured to // have language "es" by default, a new node of this type will have "und" // language code when language is not specified. - $node = $this->createNodeViaCode('ctes'); + $node = $this->drupalCreateNode(array('type' => 'ctes', 'langcode' => NULL)); $this->assertEqual($node->langcode->value, Language::LANGCODE_NOT_SPECIFIED); - // With language module disabled, and content type that is configured to + // With language module disabled, and a content type that is configured to // have language "es" by default, a new node of this type will have "en" // language code when language "en" is specified. - $node = $this->createNodeViaCode('ctes', 'en'); + $node = $this->drupalCreateNode(array('type' => 'ctes', 'langcode' => 'en')); $this->assertEqual($node->langcode->value, 'en'); } @@ -125,31 +134,4 @@ protected function createContentType($name, $langcode) { $this->drupalPostForm('admin/structure/types/add', $edit, t('Save content type')); } - /** - * Creates a new node of given type and language using Entity API. - * - * @param $type - * The node content type. - * @param $langcode - * (optional) Language code of the node to create. - * If blank, it will be determined by the content type configuration. - * - * @return \Drupal\node\Entity - * The node created. - */ - protected function createNodeViaCode($type, $langcode = NULL) { - $data = array( - 'type' => $type, - 'title' => $this->randomName(), - ); - if (!empty($langcode)) { - $data['langcode'] = $langcode; - } - $node = entity_create( - 'node', - $data - ); - return $node; - } - }