Source of file EmbargoExpiryCMSMainExtensionTest.php
Size: 4,851 Bytes - Last Modified: 2021-12-23T10:27:04+00:00
/var/www/docs.ssmods.com/process/src/tests/php/Extension/EmbargoExpiryCMSMainExtensionTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 | <?php namespace Terraformers\EmbargoExpiry\Tests\Extension; use Exception; use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Config\Config; use SilverStripe\Dev\FunctionalTest; use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\Security\Member; use Symbiote\QueuedJobs\Services\QueuedJobService; use Symfony\Component\Finder\Exception\AccessDeniedException; use Terraformers\EmbargoExpiry\Extension\EmbargoExpiryCMSMainExtension; use Terraformers\EmbargoExpiry\Extension\EmbargoExpiryExtension; /** * Class EmbargoExpiryCMSMainExtensionTest * * @package Terraformers\EmbargoExpiry\Tests\Extension */ class EmbargoExpiryCMSMainExtensionTest extends FunctionalTest { /** * @var string */ protected static $fixture_file = 'EmbargoExpiryCMSMainExtensionTest.yml'; /** * @var array */ protected static $required_extensions = [ SiteTree::class => [ EmbargoExpiryExtension::class, ], CMSMain::class => [ EmbargoExpiryCMSMainExtension::class, ], ]; /** * @throws Exception */ protected function setUp(): void { parent::setUp(); DBDatetime::set_mock_now('2014-01-05 12:00:00'); // This doesn't play nicely with PHPUnit Config::modify()->set(QueuedJobService::class, 'use_shutdown_function', false); } protected function tearDown(): void { DBDatetime::clear_mock_now(); parent::tearDown(); } public function testRemoveEmbargoAction(): void { $this->logInWithPermission('ADMIN'); /** @var SiteTree|EmbargoExpiryExtension $page */ $page = $this->objFromFixture(SiteTree::class, 'home'); $id = $page->ID; // Check that we're set up correctly. $this->assertTrue($page->getIsPublishScheduled()); $this->assertTrue($page->getIsUnPublishScheduled()); // Post a request to remove the embargo date. $this->post( sprintf('admin/pages/edit/EditForm/%s', $id), [ 'ClassName' => SiteTree::class, 'ID' => $id, 'action_removeEmbargoAction' => 1, 'ajax' => 1, ] ); // Refetch object from DB. /** @var SiteTree|EmbargoExpiryExtension $page */ $page = SiteTree::get()->byID($id); $this->assertFalse($page->getIsPublishScheduled()); $this->assertTrue($page->getIsUnPublishScheduled()); } public function testRemoveExpiryAction(): void { $this->logInWithPermission('ADMIN'); /** @var SiteTree|EmbargoExpiryExtension $page */ $page = $this->objFromFixture(SiteTree::class, 'contact'); $id = $page->ID; // Check that we're set up correctly. $this->assertTrue($page->getIsPublishScheduled()); $this->assertTrue($page->getIsUnPublishScheduled()); // Post a request to remove the embargo date. $this->post( sprintf('admin/pages/edit/EditForm/%s', $id), [ 'ClassName' => SiteTree::class, 'ID' => $id, 'action_removeExpiryAction' => 1, 'ajax' => 1, ] ); // Refetch object from DB. $page = SiteTree::get()->byID($id); $this->assertTrue($page->getIsPublishScheduled()); $this->assertFalse($page->getIsUnPublishScheduled()); } public function testRemoveActionFailsRecordDoesNotExist(): void { $this->logInWithPermission('ADMIN'); // Post a request to remove the embargo date. $response = $this->post( 'admin/pages/edit/EditForm/99', [ 'ClassName' => SiteTree::class, 'ID' => 99, 'action_removeEmbargoAction' => 1, 'ajax' => 1, ] ); $this->assertEquals(404, $response->getStatusCode()); $this->assertEquals('Bad record ID #99', $response->getBody()); } public function testRemoveActionFailsPermissionDenied(): void { $this->expectException(AccessDeniedException::class); /** @var Member $member */ $member = $this->objFromFixture(Member::class, 'user1'); $this->logInAs($member); /** @var SiteTree|EmbargoExpiryExtension $page */ $page = $this->objFromFixture(SiteTree::class, 'home'); $id = $page->ID; // Post a request to remove the embargo date. $this->post( sprintf('admin/pages/edit/EditForm/%s', $id), [ 'ClassName' => SiteTree::class, 'ID' => $id, 'action_removeExpiryAction' => 1, 'ajax' => 1, ] ); } } |