Merge branch 'master' of ssh://git.autonomic.zone:2222/autonomic-cooperative/opencase

This commit is contained in:
Nick 2022-06-03 11:51:45 +02:00
commit 156434fecc
4 changed files with 85 additions and 5 deletions

View File

@ -56,10 +56,10 @@ class OCCaseRevisionRevertForm extends ConfirmFormBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static($container
$container->get('entity.manager')->getStorage('oc_case'), ->get('entity_type.manager')
$container->get('date.formatter') ->getStorage('oc_case'), $container
); ->get('date.formatter'));
} }
/** /**

View File

@ -57,7 +57,7 @@ class OCActivityRevisionRevertForm extends ConfirmFormBase {
*/ */
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('entity.manager')->getStorage('oc_activity'), $container->get('entity_type.manager')->getStorage('oc_activity'),
$container->get('date.formatter') $container->get('date.formatter')
); );
} }

View File

@ -0,0 +1,40 @@
<?php declare(strict_types = 1);
namespace Drupal\Tests\opencase\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Form\FormState;
use Drupal\opencase_entities\Form\OCActivityRevisionRevertForm;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
class OCActivityRevisionRevertFormTest extends UnitTestCase{
public function setUp(): void {
$container = new ContainerBuilder();
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
$revision = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\OCActivity')->disableOriginalConstructor()->getMock();
$request = new Request([], [], [], [], [], [], [], json_encode([
'foo' => 'bar'
]));
$requestStack = new RequestStack();
$requestStack->push($request);
$dateFormatter->method('format');
$container->set('entity_type.manager', $entityTypeManager);
$container->set('date.formatter', $dateFormatter);
$entityTypeManager->method('getStorage')->willReturn($storage);
$storage->method('loadRevision')->willReturn($revision);
$container->set('string_translation', self::getStringTranslationStub());
$container->set('request_stack', $requestStack);
\Drupal::setContainer($container);
$this->reverter = OCActivityRevisionRevertForm::create($container);
}
public function testBuildForm():void {
$form = [];
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
}
}

View File

@ -0,0 +1,40 @@
<?php declare(strict_types = 1);
namespace Drupal\Tests\opencase\Unit;
use Drupal\opencase_cases\Form\OCCaseRevisionRevertForm;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Form\FormState;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\DependencyInjection\ContainerBuilder;
class OCCaseRevisionRevertFormTest extends UnitTestCase{
public function setUp(): void {
$container = new ContainerBuilder();
$entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
$dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->disableOriginalConstructor()->getMock();
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
$revision = $this->getMockBuilder('\\Drupal\\opencase_cases\\Entity\OCCase')->disableOriginalConstructor()->getMock();
$request = new Request([], [], [], [], [], [], [], json_encode([
'foo' => 'bar'
]));
$requestStack = new RequestStack();
$requestStack->push($request);
$dateFormatter->method('format');
$container->set('entity_type.manager', $entityTypeManager);
$container->set('date.formatter', $dateFormatter);
$entityTypeManager->method('getStorage')->willReturn($storage);
$storage->method('loadRevision')->willReturn($revision);
$container->set('string_translation', self::getStringTranslationStub());
$container->set('request_stack', $requestStack);
\Drupal::setContainer($container);
$this->reverter = OCCaseRevisionRevertForm::create($container);
}
public function testBuildForm():void {
$form = [];
$this->assertTrue(is_array($this->reverter->buildForm($form, new FormState())));
}
}