diff --git a/web/modules/custom/my_module/tests/src/Unit/Wrapper/ArticleWrapperTest.php b/web/modules/custom/my_module/tests/src/Unit/Wrapper/ArticleWrapperTest.php index d1a8be8..64b2b24 100644 --- a/web/modules/custom/my_module/tests/src/Unit/Wrapper/ArticleWrapperTest.php +++ b/web/modules/custom/my_module/tests/src/Unit/Wrapper/ArticleWrapperTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\my_module\Unit\Wrapper; +use Drupal\Component\Datetime\TimeInterface; use Drupal\my_module\Wrapper\ArticleWrapper; use Drupal\node\NodeInterface; use Drupal\Tests\UnitTestCase; @@ -14,7 +15,8 @@ class ArticleWrapperTest extends UnitTestCase { $article->method('id')->willReturn(5); $article->method('bundle')->willReturn('article'); - $articleWrapper = new ArticleWrapper($article); + $time = $this->createMock(TimeInterface::class); + $articleWrapper = new ArticleWrapper($time, $article); $this->assertInstanceOf(NodeInterface::class, $articleWrapper->getOriginal()); $this->assertSame(5, $articleWrapper->getOriginal()->id()); @@ -28,7 +30,43 @@ class ArticleWrapperTest extends UnitTestCase { $page = $this->createMock(NodeInterface::class); $page->method('bundle')->willReturn('page'); - new ArticleWrapper($page); + $time = $this->createMock(TimeInterface::class); + new ArticleWrapper($time, $page); + } + + /** + * @test + * @dataProvider articleCreatedDateProvider + */ + public function articles_created_less_than_3_days_ago_are_not_publishable( + string $offset, + bool $expected + ) { + $time = $this->createMock(TimeInterface::class); + + $time->method('getRequestTime')->willReturn( + (new \DateTime())->getTimestamp() + ); + + $article = $this->createMock(NodeInterface::class); + $article->method('bundle')->willReturn('article'); + + $article->method('getCreatedTime')->willReturn( + (new \DateTime())->modify($offset)->getTimestamp() + ); + + $articleWrapper = new ArticleWrapper($time, $article); + + $this->assertSame($expected, $articleWrapper->isPublishable()); + } + + public function articleCreatedDateProvider() { + return [ + ['-1 day', FALSE], + ['-2 days 59 minutes', FALSE], + ['-3 days', TRUE], + ['-1 week', TRUE], + ]; } }