Extract ConvertPostToTweetTest
This commit is contained in:
parent
8b040a09a2
commit
a5e2fcce63
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\opdavies_blog\Kernel\Action;
|
||||
|
||||
use Drupal\opdavies_blog\Action\ConvertPostToTweet;
|
||||
use Drupal\opdavies_blog_test\Factory\PostFactory;
|
||||
use Drupal\Tests\opdavies_blog\Kernel\PostTestBase;
|
||||
|
||||
final class ConvertPostToTweetTest extends PostTestBase {
|
||||
|
||||
private ConvertPostToTweet $convertPostToTweet;
|
||||
|
||||
public function testConvertPostToTweet(): void {
|
||||
$post = $this->postFactory
|
||||
->setTitle('Creating a custom PHPUnit command for DDEV')
|
||||
->withTags(['Automated testing', 'DDEV', 'Drupal', 'Drupal 8', 'PHP'])
|
||||
->create();
|
||||
|
||||
$post->save();
|
||||
|
||||
$expected = <<<EOF
|
||||
Creating a custom PHPUnit command for DDEV
|
||||
|
||||
http://localhost/node/1
|
||||
|
||||
#AutomatedTesting #DDEV #Drupal #Drupal8 #PHP
|
||||
EOF;
|
||||
|
||||
$this->assertSame($expected, ($this->convertPostToTweet)($post));
|
||||
}
|
||||
|
||||
public function testCertainTermsAreNotAddedAsHashtags(): void {
|
||||
$post = $this->postFactory
|
||||
->setTitle('Drupal Planet should not be added as a hashtag')
|
||||
->withTags(['Drupal', 'Drupal Planet', 'PHP'])
|
||||
->create();
|
||||
|
||||
$post->save();
|
||||
|
||||
$expected = <<<EOF
|
||||
Drupal Planet should not be added as a hashtag
|
||||
|
||||
http://localhost/node/1
|
||||
|
||||
#Drupal #PHP
|
||||
EOF;
|
||||
|
||||
$this->assertSame($expected, ($this->convertPostToTweet)($post));
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->convertPostToTweet = $this->container->get(ConvertPostToTweet::class);
|
||||
$this->postFactory = $this->container->get(PostFactory::class);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,6 @@
|
|||
namespace Drupal\Tests\opdavies_blog\Kernel\Entity\Node;
|
||||
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\opdavies_blog\Action\ConvertPostToTweet;
|
||||
use Drupal\opdavies_blog\Entity\Node\Post;
|
||||
use Drupal\opdavies_blog_test\Factory\PostFactory;
|
||||
|
||||
|
@ -27,8 +26,6 @@ final class PostTest extends EntityKernelTestBase {
|
|||
|
||||
private PostFactory $postFactory;
|
||||
|
||||
private ConvertPostToTweet $convertPostToTweet;
|
||||
|
||||
/** @test */
|
||||
public function it_can_determine_if_a_post_contains_a_tweet(): void {
|
||||
$post = $this->postFactory->create();
|
||||
|
@ -42,51 +39,10 @@ final class PostTest extends EntityKernelTestBase {
|
|||
$this->assertTrue($post->hasTweet());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_converts_a_post_to_a_tweet(): void {
|
||||
$post = $this->postFactory
|
||||
->setTitle('Creating a custom PHPUnit command for DDEV')
|
||||
->withTags(['Automated testing', 'DDEV', 'Drupal', 'Drupal 8', 'PHP'])
|
||||
->create();
|
||||
|
||||
$post->save();
|
||||
|
||||
$expected = <<<EOF
|
||||
Creating a custom PHPUnit command for DDEV
|
||||
|
||||
http://localhost/node/1
|
||||
|
||||
#AutomatedTesting #DDEV #Drupal #Drupal8 #PHP
|
||||
EOF;
|
||||
|
||||
$this->assertSame($expected, ($this->convertPostToTweet)($post));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function certain_terms_are_not_added_as_hashtags(): void {
|
||||
$post = $this->postFactory
|
||||
->setTitle('Drupal Planet should not be added as a hashtag')
|
||||
->withTags(['Drupal', 'Drupal Planet', 'PHP'])
|
||||
->create();
|
||||
|
||||
$post->save();
|
||||
|
||||
$expected = <<<EOF
|
||||
Drupal Planet should not be added as a hashtag
|
||||
|
||||
http://localhost/node/1
|
||||
|
||||
#Drupal #PHP
|
||||
EOF;
|
||||
|
||||
$this->assertSame($expected, ($this->convertPostToTweet)($post));
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->postFactory = $this->container->get(PostFactory::class);
|
||||
$this->convertPostToTweet = $this->container->get(ConvertPostToTweet::class);
|
||||
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
|
||||
|
|
Loading…
Reference in a new issue