Commit 9adbfe32 authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch
Browse files

Fixed camelize and added tests.

parent dc356c96
......@@ -7,6 +7,7 @@
namespace Drupal\typed_entity_example\Tests;
use Drupal\typed_entity\TypedEntity\TypedEntityManager;
use Drupal\typed_entity_example\TypedEntity\Tests\TypedNodeArticleUnitTest;
class TypedEntityExampleUnitTestCase extends \DrupalUnitTestCase {
......@@ -46,4 +47,13 @@ class TypedEntityExampleUnitTestCase extends \DrupalUnitTestCase {
$this->assertEqual($typed_article->getLoggingMessage(), 'User with id 1. Node with title Foo. Status 1.', 'Logging message is successful.');
}
/**
* Test camelize method.
*/
public function testCamelize() {
$this->assertEqual(TypedEntityManager::camelize('abc_def-ghi'), 'AbcDefGhi');
$this->assertEqual(TypedEntityManager::camelize('1234'), '1234');
$this->assertEqual(TypedEntityManager::camelize('1-a>234'), '1A>234');
$this->assertEqual(TypedEntityManager::camelize(''), '');
}
}
......@@ -155,15 +155,9 @@ class TypedEntityManager implements TypedEntityManagerInterface {
}
/**
* Turns a string into camel case. From search_api_index to SearchApiIndex.
*
* @param string $input
* The input string.
*
* @return string
* The camelized string.
* {@inheritdoc}
*/
protected static function camelize($input) {
public static function camelize($input) {
$input = preg_replace('/[-_]/', ' ', $input);
$input = ucwords($input);
$parts = explode(' ', $input);
......
......@@ -22,4 +22,15 @@ interface TypedEntityManagerInterface {
*/
public static function create($entity_type, $entity);
/**
* Turns a string into camel case. From search_api_index to SearchApiIndex.
*
* @param string $input
* The input string.
*
* @return string
* The camelized string.
*/
public static function camelize($input);
}
Supports Markdown
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