Index: core/modules/language/tests/Drupal/language/Tests/EntityDefaultLanguageTest.php =================================================================== --- core/modules/language/tests/Drupal/language/Tests/EntityDefaultLanguageTest.php (date 1386743677000) +++ core/modules/language/lib/Drupal/language/Tests/EntityDefaultLanguageTest.php (date 1386775423000) @@ -8,26 +8,19 @@ namespace Drupal\language\Tests; use Drupal\Core\Language\Language; -use Drupal\simpletest\WebTestBase; +use Drupal\simpletest\DrupalUnitTestBase; /** * Tests default language code is properly generated for entities. */ -class EntityDefaultLanguageTest extends WebTestBase { +class EntityDefaultLanguageTest extends DrupalUnitTestBase { /** - * The module handler. - * - * @var Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** * Modules to enable. * * @var array */ - public static $modules = array('language'); + public static $modules = array('language', 'node', 'field', 'text'); public static function getInfo() { return array( @@ -40,28 +33,16 @@ public function setUp() { parent::setUp(); - // Create a new administrator user for the test. - $admin = $this->drupalCreateUser( - array( - 'administer content types', - 'administer languages', - 'bypass node access', - ) - ); - $this->drupalLogin($admin); - // Activate Spanish language, so there are two languages activated. - $edit = array( - 'predefined_langcode' => 'es', - ); - $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + $language_entity = entity_create('language_entity', array( + 'id' => 'es', + )); + $language_entity->save(); // Create a new content type which has Undefined language by default. $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'); } /** @@ -71,48 +52,48 @@ // 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)); + $node = $this->createNode('ctund'); $this->assertEqual($node->langcode->value, Language::LANGCODE_NOT_SPECIFIED); // 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')); + $node = $this->createNode('ctund', 'es'); $this->assertEqual($node->langcode->value, 'es'); // 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)); + $node = $this->createNode('ctes'); $this->assertEqual($node->langcode->value, 'es'); // 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')); + $node = $this->createNode('ctes', 'en'); $this->assertEqual($node->langcode->value, 'en'); // Disable language module. - $this->moduleHandler->uninstall(array('language'), FALSE); + $this->disableModules(array('language')); // 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)); + $node = $this->createNode('ctund'); $this->assertEqual($node->langcode->value, Language::LANGCODE_NOT_SPECIFIED); // 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')); + $node = $this->createNode('ctund', 'es'); $this->assertEqual($node->langcode->value, 'es'); // 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->drupalCreateNode(array('type' => 'ctes', 'langcode' => NULL)); + $node = $this->createNode('ctes'); $this->assertEqual($node->langcode->value, Language::LANGCODE_NOT_SPECIFIED); // 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->drupalCreateNode(array('type' => 'ctes', 'langcode' => 'en')); + $node = $this->createNode('ctes', 'en'); $this->assertEqual($node->langcode->value, 'en'); } @@ -125,13 +106,40 @@ * Default language code of the nodes of this type. */ protected function createContentType($name, $langcode) { - $edit = array( + $content_type = entity_create('node_type', array( 'name' => 'Test ' . $name, 'title_label' => 'Title', 'type' => $name, - 'language_configuration[langcode]' => $langcode, + 'create_body' => FALSE, + )); + $content_type->save(); + language_save_default_configuration('node', $name, array( + 'langcode' => $langcode, + 'language_show' => FALSE, + )); + } + + /** + * Creates a new node of given type and language using Entity API. + * + * @param $type + * The node content type. + * @param $langcode + * (optional) Language code to pass to entity_create(). + * + * @return \Drupal\node\NodeInterface + * The node created. + */ + protected function createNode($type, $langcode = NULL) { + $values = array( + 'type' => $type, + 'title' => $this->randomName(), ); - $this->drupalPostForm('admin/structure/types/add', $edit, t('Save content type')); + if (!empty($langcode)) { + $values['langcode'] = $langcode; + } + $node = entity_create('node', $values); + return $node; } }