Commit 1bf3b8dc authored by catch's avatar catch
Browse files

Issue #2334763 by alexpott: Tidy up of LanguageInterface - removal of setters...

Issue #2334763 by alexpott: Tidy up of LanguageInterface - removal of setters and other unnecessary methods.
parent d96020c0
......@@ -7,8 +7,6 @@
namespace Drupal\Core\Language;
use Drupal\Component\Utility\SortArray;
/**
* An object containing the information for an interface language.
*
......@@ -123,15 +121,6 @@ public function getName() {
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this->name = $name;
return $this;
}
/**
* {@inheritdoc}
*/
......@@ -146,15 +135,6 @@ public function getDirection() {
return $this->direction;
}
/**
* {@inheritdoc}
*/
public function setDirection($direction) {
$this->direction = $direction;
return $this;
}
/**
* {@inheritdoc}
*/
......@@ -162,15 +142,6 @@ public function getWeight() {
return $this->weight;
}
/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this->weight = $weight;
return $this;
}
/**
* {@inheritdoc}
*/
......@@ -178,31 +149,6 @@ public function isDefault() {
return $this->default;
}
/**
* {@inheritdoc}
*/
public function setDefault($default) {
$this->default = $default;
return $this;
}
/**
* {@inheritdoc}
*/
public function getNegotiationMethodId() {
return $this->method_id;
}
/**
* {@inheritdoc}
*/
public function setNegotiationMethodId($method_id) {
$this->method_id = $method_id;
return $this;
}
/**
* Sort language objects.
*
......
......@@ -104,16 +104,6 @@ interface LanguageInterface {
*/
public function getName();
/**
* Sets the name of the language.
*
* @param string $name
* The human-readable English name of the language.
*
* @return $this
*/
public function setName($name);
/**
* Gets the ID (language code).
*
......@@ -130,16 +120,6 @@ public function getId();
*/
public function getDirection();
/**
* Sets the direction of the language.
*
* @param int $direction
* Either self::DIRECTION_LTR or self::DIRECTION_RTL.
*
* @return $this
*/
public function setDirection($direction);
/**
* Gets the weight of the language.
*
......@@ -149,17 +129,6 @@ public function setDirection($direction);
*/
public function getWeight();
/**
* Sets the weight of the language.
*
* @param int $weight
* The weight, used to order languages with larger positive weights sinking
* items toward the bottom of lists.
*
* @return $this
*/
public function setWeight($weight);
/**
* Returns whether this language is the default language.
*
......@@ -168,34 +137,4 @@ public function setWeight($weight);
*/
public function isDefault();
/**
* Sets whether this language is the default language.
*
* @param bool $default
* TRUE if it is the default language.
*
* @return $this
*/
public function setDefault($default);
/**
* Gets the language negotiation method ID for this language.
*
* @return string
* The method ID, for example
* \Drupal\language\LanguageNegotiatorInterface::METHOD_ID.
*/
public function getNegotiationMethodId();
/**
* Sets the language negotiation method ID for this language.
*
* @param string $method_id
* The method ID, for example
* \Drupal\language\LanguageNegotiatorInterface::METHOD_ID.
*
* @return $this
*/
public function setNegotiationMethodId($method_id);
}
......@@ -8,6 +8,7 @@
namespace Drupal\language;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
/**
......
......@@ -12,6 +12,7 @@
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\language\ConfigurableLanguageManager;
use Drupal\Core\Language\Language;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\language\Exception\DeleteDefaultLanguageException;
use Drupal\language\ConfigurableLanguageInterface;
......@@ -91,7 +92,6 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu
*
* @see \Drupal\language\Entity\ConfigurableLanguage::postSave()
* @see \Drupal\language\Entity\ConfigurableLanguage::isDefault()
* @see \Drupal\language\Entity\ConfigurableLanguage::setDefault()
*
* @var bool
*/
......@@ -118,17 +118,7 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu
*
* @var string
*/
public $methodId;
/**
* Sets the default flag on the language entity.
*
* @param bool $default
* TRUE if the language entity is the site default language, FALSE if not.
*/
public function setDefault($default) {
$this->default = $default;
}
public $method_id;
/**
* Checks if the language entity is the site default language.
......@@ -278,15 +268,6 @@ public function getName() {
return $this->label();
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this->label = $name;
return $this;
}
/**
* {@inheritdoc}
*/
......@@ -301,15 +282,6 @@ public function getDirection() {
return $this->direction;
}
/**
* {@inheritdoc}
*/
public function setDirection($direction) {
$this->direction = $direction;
return $this;
}
/**
* {@inheritdoc}
*/
......@@ -317,31 +289,6 @@ public function getWeight() {
return $this->weight;
}
/**
* {@inheritdoc}
*/
public function setWeight($weight) {
$this->weight = $weight;
return $this;
}
/**
* {@inheritdoc}
*/
public function getNegotiationMethodId() {
return $this->methodId;
}
/**
* {@inheritdoc}
*/
public function setNegotiationMethodId($method_id) {
$this->methodId = $method_id;
return $this;
}
/**
* Creates a configurable language object from a langcode.
*
......
......@@ -6,6 +6,9 @@
namespace Drupal\Tests\language\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityType;
use Drupal\Core\Language\Language;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\UnitTestCase;
......@@ -19,62 +22,29 @@
class ConfigurableLanguageUnitTest extends UnitTestCase {
/**
* The Entity under test.
*
* @var \Drupal\language\Entity\ConfigurableLanguage;
*/
protected $configurableLanguage;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->configurableLanguage = new ConfigurableLanguage(array(), 'configurable_language');
}
/**
* @covers ::setDirection
* @covers ::getDirection
*/
public function testDirection() {
// Direction of language writing, an integer. Usually either
// ConfigurableLanguage::DIRECTION_LTR or
// ConfigurableLanguage::DIRECTION_RTL.
$set_direction_ltr = ConfigurableLanguage::DIRECTION_LTR;
$this->configurableLanguage->setDirection($set_direction_ltr);
$this->assertEquals($this->configurableLanguage->getDirection(), $set_direction_ltr, 'LTR direction written and read correctly.');
$configurableLanguage = new ConfigurableLanguage(array('direction' => ConfigurableLanguage::DIRECTION_LTR), 'configurable_language');
$this->assertEquals(ConfigurableLanguage::DIRECTION_LTR, $configurableLanguage->getDirection());
// Test direction again, setting direction to RTL.
$set_direction_rtl = ConfigurableLanguage::DIRECTION_RTL;
$this->configurableLanguage->setDirection($set_direction_rtl);
$this->assertEquals($this->configurableLanguage->getDirection(), $set_direction_rtl, 'RTL direction written and read correctly.');
$configurableLanguage = new ConfigurableLanguage(array('direction' => ConfigurableLanguage::DIRECTION_RTL), 'configurable_language');
$this->assertEquals(ConfigurableLanguage::DIRECTION_RTL, $configurableLanguage->getDirection());
}
/**
* @covers ::setWeight
* @covers ::getWeight
*/
public function testWeight() {
// The weight, an integer. Used to order languages with larger positive
// weights sinking items toward the bottom of lists.
$set_weight = -5;
$this->configurableLanguage->setWeight($set_weight);
$this->assertEquals($this->configurableLanguage->getWeight(), $set_weight, 'Weight written and read correctly.');
}
/**
* @covers::setNegotiationMethodId
* @covers::setNegotiationMethodId
*/
public function testNegotiationMethodId(){
// Language's negotiation method ID, a string. E.g.
// \Drupal\language\LanguageNegotiatorInterface::METHOD_ID.
$set_method_id = 'language-foomethod';
$this->configurableLanguage->setNegotiationMethodId($set_method_id);
$this->assertEquals($this->configurableLanguage->getNegotiationMethodId(), $set_method_id, 'Negotiation Method Identifier written and read correctly.');
$weight = -5;
$configurableLanguage = new ConfigurableLanguage(array('weight' => $weight), 'configurable_language');
$this->assertEquals($configurableLanguage->getWeight(), $weight);
}
}
......@@ -7,7 +7,6 @@
namespace Drupal\locale\Tests;
use Drupal\Core\Language\Language;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
......
......@@ -37,7 +37,7 @@ protected function renderLink($data, ResultRow $values) {
$lang = $lang[$data];
}
return $this->sanitizeValue($lang->name);
return $this->sanitizeValue($lang->getName());
}
/**
......
......@@ -18,34 +18,16 @@
class LanguageUnitTest extends UnitTestCase {
/**
* The language under test.
*
* @var \Drupal\Core\Language\Language
*/
protected $language;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->language = new Language();
}
/**
* Tests name getter and setter methods.
*
* @covers ::getName()
* @covers ::setName()
*/
public function testGetName() {
$name = $this->randomMachineName();
$this->assertSame($this->language, $this->language->setName($name));
$this->assertSame($name, $this->language->getName());
$language_code = $this->randomMachineName(2);
$language = new Language(array('id' => $language_code, 'name' => $name));
$this->assertSame($name, $language->getName());
}
/**
* Tests langcode ID getter and setter methods.
*
* @covers ::getId()
*/
public function testGetLangcode() {
......@@ -55,39 +37,21 @@ public function testGetLangcode() {
}
/**
* Tests direction getter and setter methods.
*
* @covers ::getDirection()
* @covers ::setDirection()
*/
public function testGetDirection() {
$direction = LanguageInterface::DIRECTION_RTL;
$this->assertSame($this->language, $this->language->setDirection($direction));
$this->assertSame($direction, $this->language->getDirection());
$language_code = $this->randomMachineName(2);
$language = new Language(array('id' => $language_code, 'direction' => LanguageInterface::DIRECTION_RTL));
$this->assertSame(LanguageInterface::DIRECTION_RTL, $language->getDirection());
}
/**
* Tests isDefault() and default setter.
*
* @covers ::isDefault()
* @covers ::setDefault()
*/
public function testIsDefault() {
$default = TRUE;
$this->assertSame($this->language, $this->language->setDefault($default));
$this->assertSame($default, $this->language->isDefault());
}
/**
* Tests negotiationMethodId getter and setter methods.
*
* @covers ::getNegotiationMethodId()
* @covers ::setNegotiationMethodId()
*/
public function testGetNegotiationMethodId() {
$method_id = $this->randomMachineName();
$this->assertSame($this->language, $this->language->setNegotiationMethodId($method_id));
$this->assertSame($method_id, $this->language->getNegotiationMethodId());
$language_code = $this->randomMachineName(2);
$language = new Language(array('id' => $language_code, 'default' => TRUE));
$this->assertTrue($language->isDefault());
}
/**
......@@ -114,17 +78,9 @@ public function testSortArrayOfLanguages(array $languages, array $expected) {
* An array of test data.
*/
public function providerTestSortArrayOfLanguages() {
$language9A = new Language(array('id' => 'dd'));
$language9A->setName('A');
$language9A->setWeight(9);
$language10A = new Language(array('id' => 'ee'));
$language10A->setName('A');
$language10A->setWeight(10);
$language10B = new Language(array('id' => 'ff'));
$language10B->setName('B');
$language10B->setWeight(10);
$language9A = new Language(array('id' => 'dd', 'name' => 'A', 'weight' => 9));
$language10A = new Language(array('id' => 'ee', 'name' => 'A', 'weight' => 10));
$language10B = new Language(array('id' => 'ff', 'name' => 'B', 'weight' => 10));
return array(
// Set up data set #0, already ordered by weight.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment