Remove dashes in hashtags, and don't lowercase

References #24
This commit is contained in:
Oliver Davies 2020-09-04 19:45:30 +01:00
parent 9219d10137
commit 9b26d772a8
2 changed files with 6 additions and 10 deletions

View file

@ -75,11 +75,9 @@ class Post extends Node implements ContentEntityBundleInterface {
} }
private function convertTermToHashtag(Term $tag): string { private function convertTermToHashtag(Term $tag): string {
$tagName = strtolower($tag->label()); return '#' . (new Collection(explode(' ', $tag->label())))
$tagName = "#{$tagName}"; ->map(fn(string $word): string => ucfirst($word))
$tagName = str_replace(' ', '-', $tagName); ->implode('');
return $tagName;
} }
} }

View file

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Drupal\Tests\custom\Kernel\Entity\Node; namespace Drupal\Tests\custom\Kernel\Entity\Node;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\opdavies_blog\Entity\Node\Post;
use Drupal\opdavies_blog_test\Factory\PostFactory; use Drupal\opdavies_blog_test\Factory\PostFactory;
final class PostTest extends EntityKernelTestBase { final class PostTest extends EntityKernelTestBase {
@ -42,7 +40,7 @@ final class PostTest extends EntityKernelTestBase {
public function it_converts_a_post_to_a_tweet(): void { public function it_converts_a_post_to_a_tweet(): void {
$post = (new PostFactory()) $post = (new PostFactory())
->setTitle('Creating a custom PHPUnit command for DDEV') ->setTitle('Creating a custom PHPUnit command for DDEV')
->withTags(['Automated testing', 'DDEV', 'Drupal', 'PHP']) ->withTags(['Automated testing', 'DDEV', 'Drupal', 'Drupal 8', 'PHP'])
->create(); ->create();
$post->save(); $post->save();
@ -52,7 +50,7 @@ final class PostTest extends EntityKernelTestBase {
http://localhost/node/1 http://localhost/node/1
#automated-testing #ddev #drupal #php #AutomatedTesting #DDEV #Drupal #Drupal8 #PHP
EOF; EOF;
$this->assertSame($expected, $post->toTweet()); $this->assertSame($expected, $post->toTweet());
@ -72,7 +70,7 @@ final class PostTest extends EntityKernelTestBase {
http://localhost/node/1 http://localhost/node/1
#drupal #php #Drupal #PHP
EOF; EOF;
$this->assertSame($expected, $post->toTweet()); $this->assertSame($expected, $post->toTweet());