diff --git a/core/modules/locale/src/StringBase.php b/core/modules/locale/src/StringBase.php index 39fe7f1d33f470298e791d4b54684524797f7543..f6cfffd20a6a2f736e382df3bbba1aa1dfd5c608 100644 --- a/core/modules/locale/src/StringBase.php +++ b/core/modules/locale/src/StringBase.php @@ -7,6 +7,8 @@ namespace Drupal\locale; +use Drupal\Component\Utility\String; + /** * Defines the locale string base class. * @@ -188,8 +190,8 @@ public function save() { $storage->save($this); } else { - throw new StringStorageException(format_string('The string cannot be saved because its not bound to a storage: @string', array( - '@string' => $string->getString(), + throw new StringStorageException(String::format('The string cannot be saved because its not bound to a storage: @string', array( + '@string' => $this->getString(), ))); } return $this; @@ -204,8 +206,8 @@ public function delete() { $storage->delete($this); } else { - throw new StringStorageException(format_string('The string cannot be deleted because its not bound to a storage: @string', array( - '@string' => $string->getString(), + throw new StringStorageException(String::format('The string cannot be deleted because its not bound to a storage: @string', array( + '@string' => $this->getString(), ))); } } diff --git a/core/modules/locale/tests/src/Unit/StringBaseTest.php b/core/modules/locale/tests/src/Unit/StringBaseTest.php new file mode 100644 index 0000000000000000000000000000000000000000..9d7bca11bb06d3b7f823bf4ea9e44d608a5534a5 --- /dev/null +++ b/core/modules/locale/tests/src/Unit/StringBaseTest.php @@ -0,0 +1,39 @@ + 'test']); + $string->save(); + } + + + /** + * @covers ::delete + * @expectedException \Drupal\locale\StringStorageException + * @expectedExceptionMessage The string cannot be deleted because its not bound to a storage: test + */ + public function testDeleteWithoutStorage() { + $string = new SourceString(['lid' => 1, 'source' => 'test']); + $string->delete(); + } + +}