Compare commits
	
		
			15 Commits
		
	
	
		
			multiplefu
			...
			737104d7bd
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 737104d7bd | |||
| 66fa591566 | |||
| c318c451dc | |||
| d81e1b3711 | |||
| eb9335b250 | |||
| 809dbfc837 | |||
| 156434fecc | |||
| 57795b6393 | |||
| 457b4ad694 | |||
| 780f144b52 | |||
| 33aec90a78 | |||
| f9654bcd78 | |||
| 4852de71c7 | |||
| c29a480401 | |||
| 56bc7b83dd | 
| @ -230,7 +230,8 @@ class OCCaseFee extends EditorialContentEntityBase implements OCCaseFeeInterface | |||||||
|       ->setLabel(t('Visible')) |       ->setLabel(t('Visible')) | ||||||
|       ->setDescription(t('A boolean indicating whether the Case Fee is published.')) |       ->setDescription(t('A boolean indicating whether the Case Fee is published.')) | ||||||
|       ->setDisplayConfigurable('form', TRUE) |       ->setDisplayConfigurable('form', TRUE) | ||||||
|       ->setDisplayConfigurable('view', TRUE); |       ->setDisplayConfigurable('view', TRUE) | ||||||
|  |       ->setDefaultValue(TRUE); | ||||||
|  |  | ||||||
|     $fields['created'] = BaseFieldDefinition::create('created') |     $fields['created'] = BaseFieldDefinition::create('created') | ||||||
|       ->setLabel(t('Created')) |       ->setLabel(t('Created')) | ||||||
| @ -268,7 +269,7 @@ class OCCaseFee extends EditorialContentEntityBase implements OCCaseFeeInterface | |||||||
|       ->setDisplayConfigurable("view", true) |       ->setDisplayConfigurable("view", true) | ||||||
|       ->setDisplayConfigurable("form", true) |       ->setDisplayConfigurable("form", true) | ||||||
|       ->setRequired(FALSE); |       ->setRequired(FALSE); | ||||||
|      |  | ||||||
|     $fields['description'] = BaseFieldDefinition::create('string_long') |     $fields['description'] = BaseFieldDefinition::create('string_long') | ||||||
|       ->setRevisionable(TRUE) |       ->setRevisionable(TRUE) | ||||||
|       ->setLabel(t('Description')) |       ->setLabel(t('Description')) | ||||||
|  | |||||||
| @ -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')); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|  | |||||||
| @ -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') | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -56,10 +56,10 @@ class OCActorRevisionRevertForm 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_actor'), |       ->get('entity_type.manager') | ||||||
|       $container->get('date.formatter') |       ->getStorage('oc_actor'), $container | ||||||
|     ); |       ->get('date.formatter')); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|  | |||||||
| @ -41,14 +41,14 @@ class OCOrganisationRevisionRevertForm extends ConfirmFormBase { | |||||||
|    */ |    */ | ||||||
|   public static function create(ContainerInterface $container) { |   public static function create(ContainerInterface $container) { | ||||||
|     $instance = parent::create($container); |     $instance = parent::create($container); | ||||||
|     $instance->oCOrganisationStorage = $container->get('entity_type.manager')->getStorage('oc_organisation'); |     $instance->OCOrganisationStorage = $container->get('entity_type.manager')->getStorage('oc_organisation'); | ||||||
|     $instance->dateFormatter = $container->get('date.formatter'); |     $instance->dateFormatter = $container->get('date.formatter'); | ||||||
|     return $instance; |     return $instance; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * {@inheritdoc} |    * {@inheritdoc} | ||||||
|    */ |    */  | ||||||
|   public function getFormId() { |   public function getFormId() { | ||||||
|     return 'oc_organisation_revision_revert_confirm'; |     return 'oc_organisation_revision_revert_confirm'; | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -2,25 +2,21 @@ | |||||||
|  |  | ||||||
| namespace Drupal\opencase; | namespace Drupal\opencase; | ||||||
| use Drupal\Core\Entity\EntityTypeManagerInterface; | use Drupal\Core\Entity\EntityTypeManagerInterface; | ||||||
| use Drupal\opencase\Utils; |  | ||||||
|  |  | ||||||
| final class TimeBasedFieldUpdater { | final class TimeBasedFieldUpdater { | ||||||
|  |  | ||||||
|     private EntityTypeManagerInterface $entityTypeManager; |     private EntityTypeManagerInterface $entityTypeManager; | ||||||
|     private string $date_field; |     private string $date_field; | ||||||
|     private Utils $utils; |  | ||||||
|     private string $entity_type; |     private string $entity_type; | ||||||
|     private string $date_format; |     private string $date_format; | ||||||
|     private string $bundle; |     private string $bundle; | ||||||
|  |  | ||||||
|     final public function __construct( |     final public function __construct( | ||||||
|         EntityTypeManagerInterface $entityTypeManager, |         EntityTypeManagerInterface $entityTypeManager, | ||||||
|         Utils $utils, |  | ||||||
|         string $entity_type, string $bundle, string $date_field, string $date_format = 'Y-m-d' |         string $entity_type, string $bundle, string $date_field, string $date_format = 'Y-m-d' | ||||||
|     ) |     ) | ||||||
|     { |     { | ||||||
|         $this->entityTypeManager = $entityTypeManager; |         $this->entityTypeManager = $entityTypeManager; | ||||||
|         $this->utils = $utils; |  | ||||||
|         $this->date_field = $date_field; |         $this->date_field = $date_field; | ||||||
|         $this->date_format = $date_format; |         $this->date_format = $date_format; | ||||||
|         $this->entity_type = $entity_type; |         $this->entity_type = $entity_type; | ||||||
|  | |||||||
							
								
								
									
										38
									
								
								tests/src/Unit/EntityTrait.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								tests/src/Unit/EntityTrait.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | |||||||
|  | <?php  | ||||||
|  | namespace Drupal\Tests\opencase\Unit; | ||||||
|  |  | ||||||
|  | use PHPUnit\Framework\MockObject\MockObject; | ||||||
|  | use Drupal\Core\DependencyInjection\ContainerBuilder; | ||||||
|  |  | ||||||
|  | trait EntityTrait { | ||||||
|  |     public function getEntityTypeManager() { | ||||||
|  |         return $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function getStorage(MockObject $entityTypeManager, string $entityTypeToExpect = ''): MockObject  { | ||||||
|  |         $storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();  | ||||||
|  |         $entityTypeManager->method('getStorage')->willReturn($storage);   | ||||||
|  |         if ($entityTypeToExpect) { | ||||||
|  |             $entityTypeManager->expects($this->any())->method('getStorage')->with($entityTypeToExpect)->willReturn($storage);   | ||||||
|  |         } | ||||||
|  |         return $storage;  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function getQuery(MockObject $storage): MockObject { | ||||||
|  |         $query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock(); | ||||||
|  |         $storage->method('getQuery')->willReturn($query); | ||||||
|  |         return $query; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function getEntity(): MockObject { | ||||||
|  |         return $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock(); | ||||||
|  |     } | ||||||
|  |     public function getContainer(array $services): ContainerBuilder { | ||||||
|  |         $container = new ContainerBuilder(); | ||||||
|  |         foreach ($services as $key => $mock) { | ||||||
|  |             $container->set($key, $mock); | ||||||
|  |         } | ||||||
|  |         \Drupal::setContainer($container); | ||||||
|  |         return $container; | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										30
									
								
								tests/src/Unit/OCActorTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								tests/src/Unit/OCActorTest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | |||||||
|  | <?php declare(strict_types = 1); | ||||||
|  |  | ||||||
|  | namespace Drupal\Tests\opencase\Unit; | ||||||
|  |  | ||||||
|  | use Drupal\Tests\UnitTestCase; | ||||||
|  |  | ||||||
|  | class OCActorTest extends UnitTestCase{ | ||||||
|  |  | ||||||
|  |     use EntityTrait; | ||||||
|  |  | ||||||
|  |     public function setUp(): void { | ||||||
|  |         $this->etm = $this->getEntityTypeManager(); | ||||||
|  |         $this->getContainer([ | ||||||
|  |             'entity_type.manager' => $this->etm | ||||||
|  |         ]); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function testGetCountOfCaseProvisions(): void{   | ||||||
|  |         $storage = $this->getStorage($this->etm, 'oc_case_provision'); | ||||||
|  |         $query = $this->getQuery($storage);  | ||||||
|  |         $actor = $this->getMockBuilder('\\Drupal\\opencase_entities\\Entity\\OCActor')->disableOriginalConstructor() | ||||||
|  |             ->onlyMethods(['id']) | ||||||
|  |             ->getMock(); | ||||||
|  |         $actor->expects($this->once())->method('id')->willReturn(5); | ||||||
|  |         $query->expects($this->once())->method('condition')->with('oc_provider', 5); | ||||||
|  |         $query->expects($this->once())->method('execute')->willReturn([1,2,3,4]); | ||||||
|  |         $count = $actor->getCountOfCaseProvisions(); | ||||||
|  |         $this->assertTrue($count == 4); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										60
									
								
								tests/src/Unit/RevisionRevertFormTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								tests/src/Unit/RevisionRevertFormTest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,60 @@ | |||||||
|  | <?php declare(strict_types = 1); | ||||||
|  |  | ||||||
|  | namespace Drupal\Tests\opencase\Unit; | ||||||
|  |  | ||||||
|  | use Drupal\Tests\UnitTestCase; | ||||||
|  | use Drupal\Core\Form\FormState; | ||||||
|  | use Drupal\Tests\opencase\Unit\EntityTrait; | ||||||
|  | use Symfony\Component\HttpFoundation\Request; | ||||||
|  | use Symfony\Component\HttpFoundation\RequestStack; | ||||||
|  | use Drupal\opencase_cases\Form\OCCaseRevisionRevertForm; | ||||||
|  | use Drupal\opencase_entities\Form\OCActorRevisionRevertForm; | ||||||
|  | use Drupal\opencase_entities\Form\OCActivityRevisionRevertForm; | ||||||
|  | use Drupal\opencase_entities\Form\OCOrganisationRevisionRevertForm; | ||||||
|  |  | ||||||
|  | class RevisionRevertFormTest extends UnitTestCase{ | ||||||
|  |  | ||||||
|  |     use EntityTrait; | ||||||
|  |  | ||||||
|  |     public function setUp(): void { | ||||||
|  |         $entityTypeManager = $this->getEntityTypeManager(); | ||||||
|  |         $storage = $this->getStorage($entityTypeManager); | ||||||
|  |         $dateFormatter = $this->getMockBuilder('\\Drupal\\Core\\Datetime\\DateFormatterInterface')->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'); | ||||||
|  |         $storage->method('loadRevision')->willReturn($revision); | ||||||
|  |         $this->container = $this->getContainer([ | ||||||
|  |             'entity_type.manager'=> $entityTypeManager, | ||||||
|  |             'date.formatter' => $dateFormatter, | ||||||
|  |             'string_translation'=> self::getStringTranslationStub(), | ||||||
|  |             'request_stack'=> $requestStack | ||||||
|  |         ]); | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function testBuildFormForRevertingActivity():void { | ||||||
|  |         $this->reverter = OCActivityRevisionRevertForm::create($this->container); | ||||||
|  |         $form = []; | ||||||
|  |         $this->assertTrue(is_array($this->reverter->buildForm($form, new FormState()))); | ||||||
|  |     } | ||||||
|  |     public function testBuildFormForRevertingActor():void { | ||||||
|  |         $this->reverter = OCActorRevisionRevertForm::create($this->container); | ||||||
|  |         $form = []; | ||||||
|  |         $this->assertTrue(is_array($this->reverter->buildForm($form, new FormState()))); | ||||||
|  |     } | ||||||
|  |     public function testBuildFormForRevertingCase():void { | ||||||
|  |         $this->reverter = OCCaseRevisionRevertForm::create($this->container); | ||||||
|  |         $form = []; | ||||||
|  |         $this->assertTrue(is_array($this->reverter->buildForm($form, new FormState()))); | ||||||
|  |     } | ||||||
|  |     public function testBuildFormForRevertingOrganisation():void { | ||||||
|  |         $this->reverter = OCOrganisationRevisionRevertForm::create($this->container); | ||||||
|  |         $form = []; | ||||||
|  |         $this->assertTrue(is_array($this->reverter->buildForm($form, new FormState()))); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -7,16 +7,13 @@ use Drupal\opencase\TimeBasedFieldUpdater; | |||||||
|  |  | ||||||
| class TimeBasedFieldUpdaterTest extends UnitTestCase{ | class TimeBasedFieldUpdaterTest extends UnitTestCase{ | ||||||
|  |  | ||||||
|  |     use EntityTrait; | ||||||
|  |  | ||||||
|     function setUp():void { |     function setUp():void { | ||||||
|         /** @var \Drupal\opencase\Utils&\PHPUnit\Framework\MockObject\MockObject $utils */ |         $this->etm = $this->getEntityTypeManager(); | ||||||
|         $this->utils = $this->getMockBuilder('\\Drupal\\opencase\\Utils')->disableOriginalConstructor()->getMock(); |         $this->storage = $this->getStorage($this->etm); | ||||||
|         /** @var \Drupal\core\Entity\EntityTypeManagerInterface&\PHPUnit\Framework\MockObject\MockObject $entityTypeManager */ |         $this->query = $this->getQuery($this->storage); | ||||||
|         $this->entityTypeManager = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock(); |         $this->updater = new TimeBasedFieldUpdater($this->etm, 'dummy_entity_type', 'dummy_bundle', 'dummy_date_field'); | ||||||
|         $this->storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->getMock(); |  | ||||||
|         $this->query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock(); |  | ||||||
|         $this->entityTypeManager->method('getStorage')->willReturn($this->storage); |  | ||||||
|         $this->storage->method('getQuery')->willReturn($this->query); |  | ||||||
|         $this->updater = new TimeBasedFieldUpdater($this->entityTypeManager, $this->utils, 'dummy_entity_type', 'dummy_bundle', 'dummy_date_field'); |  | ||||||
|  |  | ||||||
|     } |     } | ||||||
|     function testFieldIsUpdatedOnEntityReturnedByQuery():void { |     function testFieldIsUpdatedOnEntityReturnedByQuery():void { | ||||||
| @ -28,21 +25,21 @@ class TimeBasedFieldUpdaterTest extends UnitTestCase{ | |||||||
|     } |     } | ||||||
|     function testFieldIsUpdatedOnAllEntitiesReturnedByQuery():void { |     function testFieldIsUpdatedOnAllEntitiesReturnedByQuery():void { | ||||||
|         $this->query->method('execute')->willReturn([1, 2]); |         $this->query->method('execute')->willReturn([1, 2]); | ||||||
|         $this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock(); |         $entity = $this->getEntity(); | ||||||
|         $this->entity2 = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock(); |         $entity2 = $this->getEntity(); | ||||||
|         $this->storage->method('load')->willReturnMap([[1, $this->entity], [2, $this-> entity2]]); |         $this->storage->method('load')->willReturnMap([[1, $entity], [2, $entity2]]); | ||||||
|         $this->updater->update([], '3 months', ['dummy_field' => 4]); |         $this->updater->update([], '3 months', ['dummy_field' => 4]); | ||||||
|         $this->assertEquals($this->entity->dummy_field, 4); |         $this->assertEquals($entity->dummy_field, 4); | ||||||
|         $this->assertEquals($this->entity2->dummy_field, 4); |         $this->assertEquals($entity2->dummy_field, 4); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     function testMultipleFieldsAreUpdated(): void { |     function testMultipleFieldsAreUpdated(): void { | ||||||
|         $this->query->method('execute')->willReturn([1]); |         $this->query->method('execute')->willReturn([1]); | ||||||
|         $this->entity = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityBase')->disableOriginalConstructor()->getMock(); |         $entity = $this->getEntity();        | ||||||
|         $this->storage->expects($this->once())->method('load')->with(1)->willReturn($this->entity); |         $this->storage->expects($this->once())->method('load')->with(1)->willReturn($entity); | ||||||
|         $this->updater->update([], '3 months', ['dummy_field' => 4, 'dummy_field_2' => 5]); |         $this->updater->update([], '3 months', ['dummy_field' => 4, 'dummy_field_2' => 5]); | ||||||
|         $this->assertEquals($this->entity->dummy_field, 4); |         $this->assertEquals($entity->dummy_field, 4); | ||||||
|         $this->assertEquals($this->entity->dummy_field_2, 5); |         $this->assertEquals($entity->dummy_field_2, 5); | ||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	