How to use Composite class

Best Phake code snippet using Composite

EntityReferenceRevisionsCompositeTest.php

Source:EntityReferenceRevisionsCompositeTest.php Github

copy

Full Screen

1<?php2namespace Drupal\Tests\entity_reference_revisions\Kernel;3use Drupal\entity_composite_relationship_test\Entity\EntityTestCompositeRelationship;4use Drupal\field\Entity\FieldConfig;5use Drupal\field\Entity\FieldStorageConfig;6use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;7use Drupal\language\Entity\ConfigurableLanguage;8use Drupal\node\Entity\Node;9use Drupal\node\Entity\NodeType;10use Drupal\Tests\node\Traits\ContentTypeCreationTrait;11use Drupal\Tests\node\Traits\NodeCreationTrait;12/**13 * Tests the entity_reference_revisions composite relationship.14 *15 * @group entity_reference_revisions16 */17class EntityReferenceRevisionsCompositeTest extends EntityKernelTestBase {18 use ContentTypeCreationTrait;19 use NodeCreationTrait;20 /**21 * Modules to enable.22 *23 * @var array24 */25 public static $modules = array(26 'node',27 'field',28 'entity_reference_revisions',29 'entity_composite_relationship_test',30 'language'31 );32 /**33 * The current database connection.34 *35 * @var \Drupal\Core\Database\Connection36 */37 protected $database;38 /**39 * The entity type manager.40 *41 * @var \Drupal\Core\Entity\EntityTypeManagerInterface42 *43 */44 protected $entityTypeManager;45 /**46 * The cron service.47 *48 * @var \Drupal\Core\Cron49 */50 protected $cron;51 /**52 * {@inheritdoc}53 */54 protected function setUp() {55 parent::setUp();56 $this->installEntitySchema('entity_test_composite');57 $this->installSchema('node', ['node_access']);58 // Create article content type.59 NodeType::create(['type' => 'article', 'name' => 'Article'])->save();60 // Create the reference to the composite entity test.61 $field_storage = FieldStorageConfig::create(array(62 'field_name' => 'composite_reference',63 'entity_type' => 'node',64 'type' => 'entity_reference_revisions',65 'settings' => array(66 'target_type' => 'entity_test_composite'67 ),68 ));69 $field_storage->save();70 $field = FieldConfig::create(array(71 'field_storage' => $field_storage,72 'bundle' => 'article',73 'translatable' => FALSE,74 ));75 $field->save();76 // Inject database connection, entity type manager and cron for the tests.77 $this->database = \Drupal::database();78 $this->entityTypeManager = \Drupal::entityTypeManager();79 $this->cron = \Drupal::service('cron');80 }81 /**82 * Test for maintaining composite relationship.83 *84 * Tests that the referenced entity saves the parent type and id when saving.85 */86 public function testEntityReferenceRevisionsCompositeRelationship() {87 // Create the test composite entity.88 $composite = EntityTestCompositeRelationship::create(array(89 'uuid' => $this->randomMachineName(),90 'name' => $this->randomMachineName(),91 ));92 $composite->save();93 // Assert that there is only 1 revision of the composite entity.94 $composite_revisions_count = \Drupal::entityQuery('entity_test_composite')->condition('uuid', $composite->uuid())->allRevisions()->count()->execute();95 $this->assertEquals(1, $composite_revisions_count);96 // Create a node with a reference to the test composite entity.97 /** @var \Drupal\node\NodeInterface $node */98 $node = Node::create(array(99 'title' => $this->randomMachineName(),100 'type' => 'article',101 ));102 $node->save();103 $node->set('composite_reference', $composite);104 $this->assertTrue($node->hasTranslationChanges());105 $node->save();106 // Assert that there is only 1 revision when creating a node.107 $node_revisions_count = \Drupal::entityQuery('node')->condition('nid', $node->id())->allRevisions()->count()->execute();108 $this->assertEquals(1, $node_revisions_count);109 // Assert there is no new composite revision after creating a host entity.110 $composite_revisions_count = \Drupal::entityQuery('entity_test_composite')->condition('uuid', $composite->uuid())->allRevisions()->count()->execute();111 $this->assertEquals(1, $composite_revisions_count);112 // Verify the value of parent type and id after create a node.113 $composite = EntityTestCompositeRelationship::load($composite->id());114 $this->assertEquals($node->getEntityTypeId(), $composite->parent_type->value);115 $this->assertEquals($node->id(), $composite->parent_id->value);116 $this->assertEquals('composite_reference', $composite->parent_field_name->value);117 // Create second revision of the node.118 $original_composite_revision = $node->composite_reference[0]->target_revision_id;119 $original_node_revision = $node->getRevisionId();120 $node->setTitle('2nd revision');121 $node->setNewRevision();122 $node->save();123 $node = Node::load($node->id());124 // Check the revision of the node.125 $this->assertEquals('2nd revision', $node->getTitle(), 'New node revision has changed data.');126 $this->assertNotEquals($original_composite_revision, $node->composite_reference[0]->target_revision_id, 'Composite entity got new revision when its host did.');127 // Make sure that there are only 2 revisions.128 $node_revisions_count = \Drupal::entityQuery('node')->condition('nid', $node->id())->allRevisions()->count()->execute();129 $this->assertEquals(2,$node_revisions_count);130 // Revert to first revision of the node.131 $node = $this->entityTypeManager->getStorage('node')->loadRevision($original_node_revision);132 $node->setNewRevision();133 $node->isDefaultRevision(TRUE);134 $node->save();135 $node = Node::load($node->id());136 // Check the revision of the node.137 $this->assertNotEquals('2nd revision', $node->getTitle(), 'Node did not keep changed title after reversion.');138 $this->assertNotEquals($original_composite_revision, $node->composite_reference[0]->target_revision_id, 'Composite entity got new revision when its host reverted to an old revision.');139 $node_storage = $this->entityTypeManager->getStorage('node');140 // Test that removing composite references results in translation changes.141 $node->set('composite_reference', []);142 $this->assertTrue($node->hasTranslationChanges());143 // Test that changing composite reference results in translation changes.144 $changed_composite_reference = $composite;145 $changed_composite_reference->set('name', 'Changing composite reference');146 $this->assertTrue($changed_composite_reference->isRevisionTranslationAffected());147 $node->set('composite_reference', $changed_composite_reference);148 $node->setNewRevision();149 $this->assertTrue($node->hasTranslationChanges());150 $node->save();151 $nid = $node->id();152 $node_storage->resetCache([$nid]);153 /** @var \Drupal\node\NodeInterface $node */154 $node = $node_storage->load($nid);155 // Check the composite has changed.156 $this->assertEquals('Changing composite reference', $node->get('composite_reference')->entity->getName());157 // Make sure the node has 4 revisions.158 $node_revisions_count = $node_storage->getQuery()->condition('nid', $nid)->allRevisions()->count()->execute();159 $this->assertEqual($node_revisions_count, 4);160 // Make sure the node has no revision with revision translation affected161 // flag set to NULL.162 $node_revisions_count = $node_storage->getQuery()->condition('nid', $nid)->allRevisions()->condition('revision_translation_affected', NULL, 'IS NULL')->count()->execute();163 $this->assertEqual($node_revisions_count, 0, 'Node has a revision with revision translation affected set to NULL');164 // Revert the changes to avoid interfering with the delete test.165 $node->set('composite_reference', $composite);166 // Test that the composite entity is deleted when its parent is deleted.167 $node->delete();168 $this->assertNotNull(EntityTestCompositeRelationship::load($composite->id()));169 $this->cron->run();170 $this->assertNull(EntityTestCompositeRelationship::load($composite->id()));171 // Test that the deleting composite entity does not break the parent entity172 // when creating a new revision.173 $composite = EntityTestCompositeRelationship::create([174 'name' => $this->randomMachineName(),175 ]);176 $composite->save();177 // Create a node with a reference to the test composite entity.178 /** @var \Drupal\node\NodeInterface $node */179 $node = Node::create([180 'title' => $this->randomMachineName(),181 'type' => 'article',182 'composite_reference' => $composite,183 ]);184 $node->save();185 // Delete the composite entity.186 $composite->delete();187 // Re-apply the field item values to unset the computed "entity" property.188 $field_item = $node->get('composite_reference')->get(0);189 $field_item->setValue($field_item->getValue(), FALSE);190 $new_revision = $this->entityTypeManager->getStorage('node')->createRevision($node);191 $this->assertTrue($new_revision->get('composite_reference')->isEmpty());192 }193 /**194 * Tests composite relationship with translations and an untranslatable field.195 */196 function testCompositeRelationshipWithTranslationNonTranslatableField() {197 ConfigurableLanguage::createFromLangcode('de')->save();198 // Create the test composite entity with a translation.199 $composite = EntityTestCompositeRelationship::create(array(200 'uuid' => $this->randomMachineName(),201 'name' => $this->randomMachineName(),202 ));203 $composite->addTranslation('de', $composite->toArray());204 $composite->save();205 // Create a node with a reference to the test composite entity.206 $node = Node::create(array(207 'title' => $this->randomMachineName(),208 'type' => 'article',209 'composite_reference' => $composite,210 ));211 $node->addTranslation('de', $node->toArray());212 $node->save();213 // Verify the value of parent type and id after create a node.214 $composite = EntityTestCompositeRelationship::load($composite->id());215 $this->assertEquals($node->getEntityTypeId(), $composite->parent_type->value);216 $this->assertEquals($node->id(), $composite->parent_id->value);217 $this->assertEquals('composite_reference', $composite->parent_field_name->value);218 $this->assertTrue($composite->hasTranslation('de'));219 // Test that the composite entity is not deleted when the german translation220 // of the parent is deleted.221 $node->removeTranslation('de');222 $node->save();223 $composite = EntityTestCompositeRelationship::load($composite->id());224 $this->assertNotNull($composite);225 $this->assertFalse($composite->hasTranslation('de'));226 // Change the language of the entity, ensure that doesn't try to delete227 // the default translation.228 $node->set('langcode', 'de');229 $node->save();230 $composite = EntityTestCompositeRelationship::load($composite->id());231 $this->assertNotNull($composite);232 // Test that the composite entity is deleted when its parent is deleted.233 $node->delete();234 $this->cron->run();235 $composite = EntityTestCompositeRelationship::load($composite->id());236 $this->assertNull($composite);237 }238 /**239 * Tests composite relationship with translations and a translatable field.240 */241 function testCompositeRelationshipWithTranslationTranslatableField() {242 $field_config = FieldConfig::loadByName('node', 'article', 'composite_reference');243 $field_config->setTranslatable(TRUE);244 $field_config->save();245 ConfigurableLanguage::createFromLangcode('de')->save();246 // Create the test composite entity with a translation.247 $composite = EntityTestCompositeRelationship::create(array(248 'uuid' => $this->randomMachineName(),249 'name' => $this->randomMachineName(),250 ));251 $composite->addTranslation('de', $composite->toArray());252 $composite->save();253 // Create a node with a reference to the test composite entity.254 $node = Node::create(array(255 'title' => $this->randomMachineName(),256 'type' => 'article',257 'composite_reference' => $composite,258 ));259 $node->addTranslation('de', $node->toArray());260 $node->save();261 // Verify the value of parent type and id after create a node.262 $composite = EntityTestCompositeRelationship::load($composite->id());263 $this->assertEquals($node->getEntityTypeId(), $composite->parent_type->value);264 $this->assertEquals($node->id(), $composite->parent_id->value);265 $this->assertEquals('composite_reference', $composite->parent_field_name->value);266 // Test that the composite entity is not deleted when the German parent267 // translation is removed.268 $node->removeTranslation('de');269 $node->save();270 $this->cron->run();271 $composite = EntityTestCompositeRelationship::load($composite->id());272 $this->assertNotNull($composite);273 // Test that the composite entity is deleted when its parent is deleted.274 $node->delete();275 $this->cron->run();276 $composite = EntityTestCompositeRelationship::load($composite->id());277 $this->assertNull($composite);278 }279 /**280 * Tests composite relationship with revisions.281 */282 function testCompositeRelationshipWithRevisions() {283 // Create the test composite entity with a translation.284 $composite = EntityTestCompositeRelationship::create(array(285 'uuid' => $this->randomMachineName(),286 'name' => $this->randomMachineName(),287 ));288 $composite->save();289 // Create a node with a reference to the test composite entity.290 $node = Node::create(array(291 'title' => $this->randomMachineName(),292 'type' => 'article',293 'composite_reference' => $composite,294 ));295 $node->save();296 // Verify the value of parent type and id after create a node.297 $composite = EntityTestCompositeRelationship::load($composite->id());298 $composite_original_revision_id = $composite->getRevisionId();299 $node_original_revision_id = $node->getRevisionId();300 $this->assertEquals($node->getEntityTypeId(), $composite->parent_type->value);301 $this->assertEquals($node->id(), $composite->parent_id->value);302 $this->assertEquals('composite_reference', $composite->parent_field_name->value);303 $node->setNewRevision(TRUE);304 $node->save();305 // Ensure that we saved a new revision ID.306 $composite = EntityTestCompositeRelationship::load($composite->id());307 $this->assertNotEquals($composite_original_revision_id, $composite->getRevisionId());308 // Test that deleting the first revision does not delete the composite.309 $this->entityTypeManager->getStorage('node')->deleteRevision($node_original_revision_id);310 $composite = EntityTestCompositeRelationship::load($composite->id());311 $this->assertNotNull($composite);312 // Ensure that the composite revision was deleted as well.313 $composite_revision = $this->entityTypeManager->getStorage('entity_test_composite')->loadRevision($composite_original_revision_id);314 $this->assertNull($composite_revision);315 // Test that the composite entity is deleted when its parent is deleted.316 $node->delete();317 $this->cron->run();318 $composite = EntityTestCompositeRelationship::load($composite->id());319 $this->assertNull($composite);320 }321 /**322 * Tests that the composite revision is not deleted if it is the default one.323 */324 function testCompositeRelationshipDefaultRevision() {325 // Create a node with a reference to a test composite entity.326 $composite = EntityTestCompositeRelationship::create([327 'uuid' => $this->randomMachineName(),328 'name' => $this->randomMachineName(),329 ]);330 $composite->save();331 $node = Node::create([332 'title' => $this->randomMachineName(),333 'type' => 'article',334 'composite_reference' => $composite,335 ]);336 $node->save();337 $composite = EntityTestCompositeRelationship::load($composite->id());338 $composite_original_revision_id = $composite->getRevisionId();339 $node_original_revision_id = $node->getRevisionId();340 // Set a new revision, composite entity should have a new revision as well.341 $node->setNewRevision(TRUE);342 $node->save();343 // Ensure that we saved a new revision ID.344 $composite2 = EntityTestCompositeRelationship::load($composite->id());345 $composite2_rev_id = $composite2->getRevisionId();346 $this->assertNotEquals($composite2_rev_id, $composite_original_revision_id);347 // Revert default composite entity revision to the original revision.348 $composite_original = $this->entityTypeManager->getStorage('entity_test_composite')->loadRevision($composite_original_revision_id);349 $composite_original->isDefaultRevision(TRUE);350 $composite_original->save();351 // Check the default composite revision is the original composite revision.352 $this->assertEquals($composite_original_revision_id, $composite_original->getrevisionId());353 // Test deleting the first node revision, referencing to the default354 // composite revision, does not delete the default composite revision.355 $this->entityTypeManager->getStorage('node')->deleteRevision($node_original_revision_id);356 $composite_default = EntityTestCompositeRelationship::load($composite_original->id());357 $this->assertNotNull($composite_default);358 $composite_default_revision = $this->entityTypeManager->getStorage('entity_test_composite')->loadRevision($composite_original->getrevisionId());359 $this->assertNotNull($composite_default_revision);360 // Ensure the second revision still exists.361 $composite2_revision = $this->entityTypeManager->getStorage('entity_test_composite')->loadRevision($composite2_rev_id);362 $this->assertNotNull($composite2_revision);363 }364 /**365 * Tests that the composite revision is not deleted if it is still in use.366 */367 function testCompositeRelationshipDuplicatedRevisions() {368 // Create a node with a reference to a test composite entity.369 $composite = EntityTestCompositeRelationship::create([370 'uuid' => $this->randomMachineName(),371 'name' => $this->randomMachineName(),372 ]);373 $composite->save();374 $node = Node::create([375 'title' => $this->randomMachineName(),376 'type' => 'article',377 'composite_reference' => $composite,378 ]);379 $node->save();380 $composite = EntityTestCompositeRelationship::load($composite->id());381 $composite_original_revision_id = $composite->getRevisionId();382 $node_original_revision_id = $node->getRevisionId();383 // Set a new revision, composite entity should have a new revision as well.384 $node->setNewRevision(TRUE);385 $node->save();386 // Ensure that we saved a new revision ID.387 $composite2 = EntityTestCompositeRelationship::load($composite->id());388 $composite2_rev_id = $composite2->getRevisionId();389 $this->assertNotEquals($composite2_rev_id, $composite_original_revision_id);390 // Set the new node revision to reference to the original composite391 // revision as well to test this composite revision will not be deleted.392 $this->database->update('node__composite_reference')393 ->fields(['composite_reference_target_revision_id' => $composite_original_revision_id])394 ->condition('revision_id', $node->getRevisionId())395 ->execute();396 $this->database->update('node_revision__composite_reference')397 ->fields(['composite_reference_target_revision_id' => $composite_original_revision_id])398 ->condition('revision_id', $node->getRevisionId())399 ->execute();400 // Test deleting the first revision does not delete the composite.401 $this->entityTypeManager->getStorage('node')->deleteRevision($node_original_revision_id);402 $composite2 = EntityTestCompositeRelationship::load($composite2->id());403 $this->assertNotNull($composite2);404 // Ensure the original composite revision is not deleted because it is405 // still referenced by the second node revision.406 $composite_original_revision = $this->entityTypeManager->getStorage('entity_test_composite')->loadRevision($composite_original_revision_id);407 $this->assertNotNull($composite_original_revision);408 // Ensure the second revision still exists.409 $composite2_revision = $this->entityTypeManager->getStorage('entity_test_composite')->loadRevision($composite2_rev_id);410 $this->assertNotNull($composite2_revision);411 // Test that the composite entity is deleted when its parent is deleted.412 $node->delete();413 $this->cron->run();414 $composite = EntityTestCompositeRelationship::load($composite2->id());415 $this->assertNull($composite);416 }417 /**418 * Tests the composite entity is deleted after removing its reference.419 */420 public function testCompositeDeleteAfterRemovingReference() {421 list($composite, $node) = $this->assignCompositeToNode();422 // Remove reference to the composite entity from the node.423 $node->set('composite_reference', NULL);424 $node->save();425 // Verify that the composite entity is not yet removed after deleting the426 // parent.427 $node->delete();428 $composite = EntityTestCompositeRelationship::load($composite->id());429 $this->assertNotNull($composite);430 // Verify that the composite entity is removed after running cron.431 $this->cron->run();432 $composite = EntityTestCompositeRelationship::load($composite->id());433 $this->assertNull($composite);434 }435 /**436 * Tests the composite entity is deleted after removing its reference.437 *438 * Includes revisions on the host entity.439 */440 public function testCompositeDeleteAfterRemovingReferenceWithRevisions() {441 list($composite, $node) = $this->assignCompositeToNode();442 // Remove reference to the composite entity from the node in a new revision.443 $node->set('composite_reference', NULL);444 $node->setNewRevision();445 $node->save();446 $composite = EntityTestCompositeRelationship::load($composite->id());447 // Verify the composite entity is not removed on nodes with revisions.448 $this->assertNotNull($composite);449 // Verify that the composite entity is not yet removed after deleting the450 // parent.451 $node->delete();452 $composite = EntityTestCompositeRelationship::load($composite->id());453 $this->assertNotNull($composite);454 // Verify that the composite entity is removed after running cron.455 $this->cron->run();456 $composite = EntityTestCompositeRelationship::load($composite->id());457 $this->assertNull($composite);458 }459 /**460 * Tests the composite entity is not deleted when changing parents.461 *462 * Includes revisions on the host entity.463 */464 public function testCompositeDeleteAfterChangingParent() {465 list($composite, $node) = $this->assignCompositeToNode();466 // Remove reference to the composite entity from the node.467 $node->set('composite_reference', NULL);468 $node->setNewRevision();469 $node->save();470 // Setting a new revision of the composite entity in the second node.471 $composite = EntityTestCompositeRelationship::load($composite->id());472 $composite->setNewRevision(TRUE);473 $composite->save();474 $second_node = Node::create([475 'title' => 'Second node',476 'type' => 'article',477 'composite_reference' => $composite,478 ]);479 $second_node->save();480 // Remove reference to the composite entity from the node.481 $second_node->set('composite_reference', NULL);482 $second_node->setNewRevision(TRUE);483 $second_node->save();484 // Verify the composite entity is not removed on nodes with revisions.485 $composite = EntityTestCompositeRelationship::load($composite->id());486 $this->assertNotNull($composite);487 // Verify the amount of revisions of each entity.488 $this->assertRevisionCount(2, 'entity_test_composite', $composite->id());489 $this->assertRevisionCount(2, 'node', $node->id());490 $this->assertRevisionCount(2, 'node', $second_node->id());491 // Test that the composite entity is not deleted when its new parent is492 // deleted, since it is still being used in a previous revision with a493 // different parent.494 $second_node->delete();495 $this->cron->run();496 $composite = EntityTestCompositeRelationship::load($composite->id());497 $this->assertNotNull($composite);498 // Delete the parent of the previous revision.499 $node->delete();500 // Verify that the composite entity is removed after running cron.501 $this->cron->run();502 $composite = EntityTestCompositeRelationship::load($composite->id());503 $this->assertNull($composite);504 }505 /**506 * Composite entity with revisions isn't deleted when changing parents.507 *508 * Includes revisions on the host entity.509 */510 public function testCompositeDeleteRevisionAfterChangingParent() {511 list($composite, $node) = $this->assignCompositeToNode();512 // Remove reference to the composite entity from the node.513 $node->set('composite_reference', NULL);514 $node->setNewRevision();515 $node->save();516 // Setting a new revision of the composite entity in the second node.517 $composite = EntityTestCompositeRelationship::load($composite->id());518 $composite->setNewRevision(TRUE);519 $composite->save();520 $composite = EntityTestCompositeRelationship::load($composite->id());521 $second_node = Node::create([522 'title' => 'Second node',523 'type' => 'article',524 'composite_reference' => $composite,525 ]);526 $second_node->save();527 // Remove reference to the composite entity from the node.528 $second_node->set('composite_reference', NULL);529 $second_node->setNewRevision(TRUE);530 $second_node->save();531 // Verify the composite entity is not removed on nodes with revisions.532 $composite = EntityTestCompositeRelationship::load($composite->id());533 $this->assertNotNull($composite);534 // Verify the amount of revisions of each entity.535 $this->assertRevisionCount(2, 'entity_test_composite', $composite->id());536 $this->assertRevisionCount(2, 'node', $node->id());537 $this->assertRevisionCount(2, 'node', $second_node->id());538 // Test that the composite entity is not deleted when its old parent is539 // deleted.540 $node->delete();541 $composite = EntityTestCompositeRelationship::load($composite->id());542 $this->assertNotNull($composite);543 // Verify that the composite entity is not removed after running cron but544 // the previous unused revision is deleted.545 $this->cron->run();546 $composite = EntityTestCompositeRelationship::load($composite->id());547 $this->assertNotNull($composite);548 $this->assertRevisionCount(1, 'entity_test_composite', $composite->id());549 }550 /**551 * Tests the composite entity is not deleted when duplicating host entity.552 *553 * Includes revisions on the host entity.554 */555 public function testCompositeDeleteAfterDuplicatingParent() {556 list($composite, $node) = $this->assignCompositeToNode();557 $node->setNewRevision(TRUE);558 $node->save();559 // Create a duplicate of the node.560 $duplicate_node = $node->createDuplicate();561 $duplicate_node->save();562 $duplicate_node->setNewRevision(TRUE);563 $duplicate_node->save();564 // Verify the amount of revisions of each entity.565 $this->assertRevisionCount(3, 'entity_test_composite', $composite->id());566 $this->assertRevisionCount(2, 'node', $node->id());567 $this->assertRevisionCount(2, 'node', $duplicate_node->id());568 // Test that the composite entity is not deleted when the duplicate is569 // deleted.570 $duplicate_node->delete();571 $composite = EntityTestCompositeRelationship::load($composite->id());572 $this->assertNotNull($composite);573 $this->cron->run();574 $composite = EntityTestCompositeRelationship::load($composite->id());575 $this->assertNotNull($composite);576 }577 /**578 * Asserts the revision count of a certain entity.579 *580 * @param int $expected581 * The expected count.582 * @param string $entity_type_id583 * The entity type ID, e.g. node.584 * @param int $entity_id585 * The entity ID.586 */587 protected function assertRevisionCount($expected, $entity_type_id, $entity_id) {588 $id_field = \Drupal::entityTypeManager()589 ->getDefinition($entity_type_id)590 ->getKey('id');591 $revision_count = \Drupal::entityQuery($entity_type_id)592 ->condition($id_field, $entity_id)593 ->allRevisions()594 ->count()595 ->execute();596 $this->assertEquals($expected, $revision_count);597 }598 /**599 * Creates and assigns the composite entity to a node.600 *601 * @param string $node_type602 * The node type.603 *604 * @return array605 * An array containing a composite and a node entity.606 */607 protected function assignCompositeToNode($node_type = 'article') {608 $composite = EntityTestCompositeRelationship::create([609 'uuid' => $this->randomMachineName(),610 'name' => $this->randomMachineName(),611 ]);612 $composite->save();613 $node = Node::create([614 'title' => $this->randomMachineName(),615 'type' => $node_type,616 'composite_reference' => $composite,617 ]);618 $node->save();619 return [$composite, $node];620 }621}...

Full Screen

Full Screen

class.socomposite.inc.php

Source:class.socomposite.inc.php Github

copy

Full Screen

...85 }86 switch ($filters['has_contract'])87 {88 case "has_contract":89 $filter_clauses[] = "NOT rental_contract_composite.contract_id IS NULL"; // Composite must have a contract90 $filter_clauses[] = "NOT rental_contract.date_start IS NULL"; // The contract must have start date91 /* The contract's start date not after the end of the period if there is no end date */92 $filter_clauses[] = "93 (94 (95 ((NOT rental_contract.date_start > $availability_date_to AND rental_contract.date_end IS NULL)96 OR97 (NOT rental_contract.date_start > $availability_date_to AND NOT rental_contract.date_end IS NULL AND NOT rental_contract.date_end < $availability_date_from))98 )99 OR100 (101 ((NOT rental_application.date_start > $availability_date_to AND rental_application.date_end IS NULL)102 OR103 (NOT rental_application.date_start > $availability_date_to AND NOT rental_application.date_end IS NULL AND NOT rental_application.date_end < $availability_date_from))...

Full Screen

Full Screen

EntityReferenceRevisionsOrphanRemovalTest.php

Source:EntityReferenceRevisionsOrphanRemovalTest.php Github

copy

Full Screen

1<?php2namespace Drupal\Tests\entity_reference_revisions\Functional;3use Drupal\Core\Site\Settings;4use Drupal\entity_composite_relationship_test\Entity\EntityTestCompositeRelationship;5use Drupal\field\Entity\FieldConfig;6use Drupal\field\Entity\FieldStorageConfig;7use Drupal\node\Entity\NodeType;8use Drupal\Tests\BrowserTestBase;9/**10 * Tests orphan composite revisions are properly removed.11 *12 * @group entity_reference_revisions13 */14class EntityReferenceRevisionsOrphanRemovalTest extends BrowserTestBase {15 /**16 * A user with administration access.17 *18 * @var \Drupal\user\UserInterface19 */20 protected $adminUser;21 /**22 * Modules to enable.23 *24 * @var array25 */26 public static $modules = [27 'node',28 'field',29 'entity_reference_revisions',30 'entity_composite_relationship_test'31 ];32 /**33 * {@inheritdoc}34 */35 public function setUp() {36 parent::setUp();37 $this->adminUser = $this->drupalCreateUser([38 'delete orphan revisions',39 ]);40 $this->drupalLogin($this->adminUser);41 $this->insertRevisionableData();42 $this->insertNonRevisionableData();43 }44 /**45 * Tests that revisions that are no longer used are properly deleted.46 */47 public function testNotUsedRevisionDeletion() {48 $entity_test_composite_storage = \Drupal::entityTypeManager()->getStorage('entity_test_composite');49 $composite_entity_first = $entity_test_composite_storage->loadByProperties(['name' => 'first not used, second used']);50 $composite_entity_first = reset($composite_entity_first);51 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_first->id());52 $composite_entity_second = $entity_test_composite_storage->loadByProperties(['name' => 'first used, second not used']);53 $composite_entity_second = reset($composite_entity_second);54 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_second->id());55 $composite_entity_third = $entity_test_composite_storage->loadByProperties(['name' => 'first not used, second not used']);56 $composite_entity_third = reset($composite_entity_third);57 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_third->id());58 $composite_entity_fourth = $entity_test_composite_storage->loadByProperties(['name' => '1st filled not, 2nd filled not']);59 $composite_entity_fourth = reset($composite_entity_fourth);60 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_fourth->id());61 $composite_entity_fifth = $entity_test_composite_storage->loadByProperties(['name' => '1st not, 2nd used, 3rd not, 4th']);62 $composite_entity_fifth = reset($composite_entity_fifth);63 $this->assertRevisionCount(4, 'entity_test_composite', $composite_entity_fifth->id());64 $composite_entity_sixth = $entity_test_composite_storage->loadByProperties(['name' => 'wrong parent fields']);65 $composite_entity_sixth = reset($composite_entity_sixth);66 $this->assertRevisionCount(1, 'entity_test_composite', $composite_entity_sixth->id());67 // Test non revisionable parent entities.68 $composite_entity_seventh = $entity_test_composite_storage->loadByProperties(['name' => 'NR first not used, second used']);69 $composite_entity_seventh = reset($composite_entity_seventh);70 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_seventh->id());71 $composite_entity_eighth = $entity_test_composite_storage->loadByProperties(['name' => 'NR first used, second not used']);72 $composite_entity_eighth = reset($composite_entity_eighth);73 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_eighth->id());74 $composite_entity_ninth = $entity_test_composite_storage->loadByProperties(['name' => 'NR 1st not, 2nd, 3rd not, 4th']);75 $composite_entity_ninth = reset($composite_entity_ninth);76 $this->assertRevisionCount(3, 'entity_test_composite', $composite_entity_ninth->id());77 // Set the batch size to 1.78 $settings = Settings::getInstance() ? Settings::getAll() : [];79 $settings['entity_update_batch_size'] = 1;80 new Settings($settings);81 // Run the delete process through the form.82 $this->runDeleteForm();83 $this->assertSession()->pageTextContains('Test entity - composite relationship: Deleted 8 revisions (1 entities)');84 $this->assertRevisionCount(1, 'entity_test_composite', $composite_entity_first->id());85 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_second->id());86 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_third->id());87 $this->assertRevisionCount(0, 'entity_test_composite', $composite_entity_fourth->id());88 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_fifth->id());89 $this->assertRevisionCount(1, 'entity_test_composite', $composite_entity_sixth->id());90 $this->assertRevisionCount(1, 'entity_test_composite', $composite_entity_seventh->id());91 $this->assertRevisionCount(2, 'entity_test_composite', $composite_entity_eighth->id());92 $this->assertRevisionCount(1, 'entity_test_composite', $composite_entity_ninth->id());93 }94 /**95 * Programmatically runs the 'Delete orphaned composite entities' form.96 */97 public function runDeleteForm() {98 $this->drupalGet('admin/config/system/delete-orphans');99 $this->submitForm([], t('Delete orphaned composite revisions'));100 $this->checkForMetaRefresh();101 }102 /**103 * Asserts the revision count of a certain entity.104 *105 * @param int $expected106 * The expected count.107 * @param string $entity_type_id108 * The entity type ID, e.g. node.109 * @param int $entity_id110 * The entity ID.111 */112 protected function assertRevisionCount($expected, $entity_type_id, $entity_id) {113 $id_field = \Drupal::entityTypeManager()->getDefinition($entity_type_id)->getKey('id');114 $revision_count = \Drupal::entityQuery($entity_type_id)115 ->condition($id_field, $entity_id)116 ->allRevisions()117 ->count()118 ->execute();119 $this->assertEquals($expected, $revision_count);120 }121 /**122 * Inserts revisionable entities needed for testing.123 */124 public function insertRevisionableData() {125 /** @var \Drupal\node\NodeStorageInterface $node_storage */126 $node_storage = \Drupal::entityTypeManager()->getStorage('node');127 NodeType::create(['type' => 'revisionable', 'new_revision' => TRUE])->save();128 // Add a translatable field and a not translatable field to both content129 // types.130 $field_storage = FieldStorageConfig::create([131 'field_name' => 'field_composite_entity',132 'entity_type' => 'node',133 'type' => 'entity_reference_revisions',134 'settings' => [135 'target_type' => 'entity_test_composite'136 ],137 ]);138 $field_storage->save();139 $field = FieldConfig::create([140 'field_storage' => $field_storage,141 'bundle' => 'revisionable',142 'translatable' => FALSE,143 ]);144 $field->save();145 // Scenario 1: A composite with a default revision that is referenced and an146 // old revision that is not. Result: Only the old revision is deleted.147 $composite_entity_first = EntityTestCompositeRelationship::create([148 'name' => 'first not used, second used',149 'parent_id' => 1000,150 'parent_type' => 'node',151 'parent_field_name' => 'field_composite_entity',152 ]);153 $composite_entity_first->save();154 $composite_entity_first = EntityTestCompositeRelationship::load($composite_entity_first->id());155 $composite_entity_first->setNewRevision(TRUE);156 $composite_entity_first->save();157 $node = $this->drupalCreateNode([158 'type' => 'revisionable',159 'title' => 'First composite',160 'field_composite_entity' => $composite_entity_first,161 ]);162 $node->save();163 // Scenario 2: A composite with an old revision that is used and a default164 // revision that is not. Result: Nothing should be deleted.165 $composite_entity_second = EntityTestCompositeRelationship::create([166 'name' => 'first used, second not used',167 ]);168 $composite_entity_second->save();169 $node = $this->drupalCreateNode([170 'type' => 'revisionable',171 'title' => 'Second composite',172 'field_composite_entity' => $composite_entity_second,173 ]);174 $node->save();175 $node = $this->getNodeByTitle('Second composite');176 $node = $node_storage->createRevision($node);177 $node->set('field_composite_entity', NULL);178 $node->save();179 $composite_entity_second = EntityTestCompositeRelationship::load($composite_entity_second->id());180 $composite_entity_second->setNewRevision(TRUE);181 $composite_entity_second->save();182 // Scenario 3: A composite with an old revision and a default revision both183 // that are not used with empty parent fields. Result: Nothing should be184 // deleted since we do not know if it is still used.185 $composite_entity_third = EntityTestCompositeRelationship::create([186 'name' => 'first not used, second not used',187 ]);188 $composite_entity_third->save();189 $composite_entity_third = EntityTestCompositeRelationship::load($composite_entity_third->id());190 $composite_entity_third->setNewRevision(TRUE);191 $composite_entity_third->save();192 // Scenario 4: A composite with an old revision and a default revision both193 // that are not used with filled parent fields. Result: Should first delete194 // the old revision and then the default revision. Delete the entity too.195 $composite_entity_fourth = EntityTestCompositeRelationship::create([196 'name' => '1st filled not, 2nd filled not',197 'parent_id' => 1001,198 'parent_type' => 'node',199 'parent_field_name' => 'field_composite_entity',200 ]);201 $composite_entity_fourth->save();202 $composite_entity_fourth = EntityTestCompositeRelationship::load($composite_entity_fourth->id());203 $composite_entity_fourth->setNewRevision(TRUE);204 $composite_entity_fourth->set('parent_id', 1001);205 $composite_entity_fourth->save();206 // Scenario 5: A composite with many revisions and 2 at least used. Result:207 // Delete all unused revisions.208 $composite_entity_fifth = EntityTestCompositeRelationship::create([209 'name' => '1st not, 2nd used, 3rd not, 4th',210 'parent_id' => 1001,211 'parent_type' => 'node',212 'parent_field_name' => 'field_composite_entity',213 ]);214 $composite_entity_fifth->save();215 $composite_entity_fifth = EntityTestCompositeRelationship::load($composite_entity_fifth->id());216 $composite_entity_fifth->setNewRevision(TRUE);217 $composite_entity_fifth->save();218 $node = $this->drupalCreateNode([219 'type' => 'revisionable',220 'title' => 'Third composite',221 'field_composite_entity' => $composite_entity_fifth,222 ]);223 $node->save();224 $node = $this->getNodeByTitle('Third composite');225 $node = $node_storage->createRevision($node);226 $node->set('field_composite_entity', NULL);227 $node->save();228 $composite_entity_fifth = EntityTestCompositeRelationship::load($composite_entity_fifth->id());229 $composite_entity_fifth->setNewRevision(TRUE);230 $composite_entity_fifth->save();231 $node = $this->getNodeByTitle('Third composite');232 $node = $node_storage->createRevision($node);233 $node->set('field_composite_entity', $composite_entity_fifth);234 $node->save();235 // Scenario 6: A composite with wrong parent fields filled pointing to a non236 // existent parent (Parent 1). However, Parent 2 references it. Result: Must237 // not be deleted.238 $node = $this->drupalCreateNode([239 'type' => 'revisionable',240 'title' => 'DELETED composite',241 ]);242 $node->save();243 $composite_entity_sixth = EntityTestCompositeRelationship::create([244 'name' => 'wrong parent fields',245 'parent_id' => $node->id(),246 'parent_type' => 'node',247 'parent_field_name' => 'field_composite_entity',248 ]);249 $composite_entity_sixth->save();250 $node->delete();251 $node = $this->drupalCreateNode([252 'type' => 'revisionable',253 'title' => 'Fourth composite',254 'field_composite_entity' => $composite_entity_sixth,255 ]);256 $node->save();257 }258 /**259 * Inserts non revisionable entities needed for testing.260 */261 public function insertNonRevisionableData() {262 /** @var \Drupal\node\NodeStorageInterface $node_storage */263 NodeType::create(['type' => 'non_revisionable', 'new_revision' => FALSE])->save();264 // Add a translatable field and a not translatable field to both content265 // types.266 $field_storage = FieldStorageConfig::loadByName('node', 'field_composite_entity');267 $field = FieldConfig::create([268 'field_storage' => $field_storage,269 'bundle' => 'non_revisionable',270 'translatable' => FALSE,271 ]);272 $field->save();273 // Scenario 1: A composite with a default revision that is referenced and an274 // old revision that is not. Result: Only the old revision is deleted.275 $composite_entity_first = EntityTestCompositeRelationship::create([276 'name' => 'NR first not used, second used',277 'parent_id' => 1001,278 'parent_type' => 'node',279 'parent_field_name' => 'field_composite_entity',280 ]);281 $composite_entity_first->save();282 $composite_entity_first = EntityTestCompositeRelationship::load($composite_entity_first->id());283 $composite_entity_first->setNewRevision(TRUE);284 $composite_entity_first->save();285 $node = $this->drupalCreateNode([286 'type' => 'non_revisionable',287 'title' => 'First composite',288 'field_composite_entity' => $composite_entity_first,289 ]);290 $node->save();291 // Scenario 2: A composite with an old revision that is used and a default292 // revision that is not. Result: Nothing should be deleted.293 $composite_entity_second = EntityTestCompositeRelationship::create([294 'name' => 'NR first used, second not used',295 ]);296 $composite_entity_second->save();297 $node = $this->drupalCreateNode([298 'type' => 'non_revisionable',299 'title' => 'Second composite',300 'field_composite_entity' => $composite_entity_second,301 ]);302 $node->save();303 $composite_entity_second = EntityTestCompositeRelationship::load($composite_entity_second->id());304 $composite_entity_second->setNewRevision(TRUE);305 $composite_entity_second->save();306 // Scenario 3: A composite with many revisions and 2 at least used. Result:307 // Delete all unused revisions.308 $composite_entity_third = EntityTestCompositeRelationship::create([309 'name' => 'NR 1st not, 2nd, 3rd not, 4th',310 'parent_id' => 1001,311 'parent_type' => 'node',312 'parent_field_name' => 'field_composite_entity',313 ]);314 $composite_entity_third->save();315 $composite_entity_third = EntityTestCompositeRelationship::load($composite_entity_third->id());316 $composite_entity_third->setNewRevision(TRUE);317 $composite_entity_third->save();318 $node = $this->drupalCreateNode([319 'type' => 'non_revisionable',320 'title' => 'Third composite',321 'field_composite_entity' => $composite_entity_third,322 ]);323 $node->save();324 $node = $this->getNodeByTitle('Third composite');325 $node->set('field_composite_entity', NULL);326 $node->save();327 $composite_entity_third = EntityTestCompositeRelationship::load($composite_entity_third->id());328 $composite_entity_third->setNewRevision(TRUE);329 $composite_entity_third->save();330 $node = $this->getNodeByTitle('Third composite');331 $node->set('field_composite_entity', $composite_entity_third);332 $node->save();333 }334}...

Full Screen

Full Screen

Composite

Using AI Code Generation

copy

Full Screen

1$composite = Phake::mock('Composite');2$leaf = Phake::mock('Leaf');3Phake::when($composite)->add($leaf)->thenReturn($leaf);4Phake::when($composite)->remove($leaf)->thenReturn($leaf);5Phake::when($composite)->getChildren()->thenReturn($leaf);6Phake::when($composite)->operation()->thenReturn($leaf);7$composite = Phake::mock('Composite');8$leaf = Phake::mock('Leaf');9Phake::when($composite)->add($leaf)->thenReturn($leaf);10Phake::when($composite)->remove($leaf)->thenReturn($leaf);11Phake::when($composite)->getChildren()->thenReturn($leaf);12Phake::when($composite)->operation()->thenReturn($leaf);13$composite = Phake::mock('Composite');14$leaf = Phake::mock('Leaf');15Phake::when($composite)->add($leaf)->thenReturn($leaf);16Phake::when($composite)->remove($leaf)->thenReturn($leaf);17Phake::when($composite)->getChildren()->thenReturn($leaf);18Phake::when($composite)->operation()->thenReturn($leaf);19$composite = Phake::mock('Composite');20$leaf = Phake::mock('Leaf');21Phake::when($composite)->add($leaf)->thenReturn($leaf);22Phake::when($composite)->remove($leaf)->thenReturn($leaf);23Phake::when($composite)->getChildren()->thenReturn($leaf);24Phake::when($composite)->operation()->thenReturn($leaf);25$composite = Phake::mock('Composite');26$leaf = Phake::mock('Leaf');27Phake::when($composite)->add($leaf)->thenReturn($leaf);28Phake::when($composite)->remove($leaf)->thenReturn($leaf);29Phake::when($composite)->getChildren()->thenReturn($leaf);30Phake::when($composite)->operation

Full Screen

Full Screen

Composite

Using AI Code Generation

copy

Full Screen

1$mock = Phake::mock('Composite');2Phake::when($mock)->getPrice()->thenReturn(100);3Phake::when($mock)->getDescription()->thenReturn('This is a composite');4Phake::when($mock)->getComposite()->thenReturn($mock);5Phake::when($mock)->getComponent()->thenReturn($mock);6Phake::when($mock)->add($mock)->thenReturn(1);7Phake::when($mock)->remove($mock)->thenReturn(1);8Phake::when($mock)->getChildren()->thenReturn(array($mock));9Phake::when($mock)->getChild($mock)->thenReturn($mock);10Phake::when($mock)->isComposite()->thenReturn(true);11$mock = Phake::mock('Composite');12Phake::when($mock)->getPrice()->thenReturn(100);13Phake::when($mock)->getDescription()->thenReturn('This is a composite');14Phake::when($mock)->getComposite()->thenReturn($mock);15Phake::when($mock)->getComponent()->thenReturn($mock);16Phake::when($mock)->add($mock)->thenReturn(1);17Phake::when($mock)->remove($mock)->thenReturn(1);18Phake::when($mock)->getChildren()->thenReturn(array($mock));19Phake::when($mock)->getChild($mock)->thenReturn($mock);20Phake::when($mock)->isComposite()->thenReturn(true);21$mock = Phake::mock('Composite');22Phake::when($mock)->getPrice()->thenReturn(100);23Phake::when($mock)->getDescription()->thenReturn('This is a composite');24Phake::when($mock)->getComposite()->thenReturn($mock);25Phake::when($mock)->getComponent()->thenReturn($mock);26Phake::when($mock)->add($mock)->thenReturn(1);27Phake::when($mock)->remove($mock)->thenReturn(1);28Phake::when($mock)->getChildren()->thenReturn(array($mock));29Phake::when($mock)->getChild($mock)->thenReturn($mock);30Phake::when($mock)->isComposite()->thenReturn(true);31$mock = Phake::mock('Composite');32Phake::when($mock)->getPrice()->thenReturn(100);

Full Screen

Full Screen

Composite

Using AI Code Generation

copy

Full Screen

1require_once 'Phake.php';2$composite = new Phake_Composite();3$composite->add(new Phake_Person('John'));4$composite->add(new Phake_Person('Doe'));5$composite->add(new Phake_Person('Jane'));6$composite->add(new Phake_Person('Doe'));7$composite->add(new Phake_Person('John'));8$composite->add(new Phake_Person('Doe'));9$composite->add(new Phake_Person('Jane'));10$composite->add(new Phake_Person('Doe'));11$composite->add(new Phake_Person('John'));12$composite->add(new Phake_Person('Doe'));13$composite->add(new Phake_Person('Jane'));14$composite->add(new Phake_Person('Doe'));15$composite->add(new Phake_Person('John'));16$composite->add(new Phake_Person('Doe'));17$composite->add(new Phake_Person('Jane'));18$composite->add(new Phake_Person('Doe'));19$composite->add(new Phake_Person('John'));20$composite->add(new Phake_Person('Doe'));21$composite->add(new Phake_Person('Jane'));22$composite->add(new Phake_Person('Doe'));23$composite->add(new Phake_Person('John'));24$composite->add(new Phake_Person('Doe'));25$composite->add(new Phake_Person('Jane'));26$composite->add(new Phake_Person('Doe'));27$composite->add(new Phake_Person('John'));28$composite->add(new Phake_Person('Doe'));29$composite->add(new Phake_Person('Jane'));30$composite->add(new Phake_Person('Doe'));31$composite->add(new Phake_Person('John'));32$composite->add(new Phake_Person('Doe'));33$composite->add(new Phake_Person('Jane'));34$composite->add(new Phake_Person('Doe'));35$composite->add(new Phake_Person('John'));36$composite->add(new Phake_Person('Doe'));37$composite->add(new Phake_Person('Jane'));38$composite->add(new Phake_Person('Doe'));39$composite->add(new Phake_Person('John'));40$composite->add(new Phake_Person('Doe'));41$composite->add(new Phake

Full Screen

Full Screen

Composite

Using AI Code Generation

copy

Full Screen

1$phake = new Phake\Phake();2$composite = new Phake\Composite($phake);3$composite->add(new Phake\Composite\ClassComposite($phake));4$composite->add(new Phake\Composite\MethodComposite($phake));5$composite->add(new Phake\Composite\PropertyComposite($phake));6$composite->add(new Phake\Composite\ConstantComposite($phake));7$composite->add(new Phake\Composite\ArgumentComposite($phake));8$composite->add(new Phake\Composite\CallComposite($phake));9$composite->add(new Phake\Composite\CallArgumentComposite($phake));10$composite->add(new Phake\Composite\CallStaticComposite($phake));11$composite->add(new Phake\Composite\CallStaticArgumentComposite($phake));12$composite->add(new Phake\Composite\CallStaticPropertyComposite($phake));13$composite->add(new Phake\Composite\CallStaticPropertyArgumentComposite($phake));14$composite->add(new Phake\Composite\CallStaticPropertyCallArgumentComposite($phake));15$composite->add(new Phake\Composite\CallStaticPropertyCallStaticArgumentComposite($phake));16$composite->add(new Phake\Composite\CallStaticPropertyCallStaticArgumentCallArgumentComposite($phake));17$composite->add(new Phake\Composite\CallStaticPropertyCallStaticArgumentCallStaticArgumentComposite($phake));18$composite->add(new Phake\Composite\CallStaticPropertyCallStaticArgumentCallStaticArgumentCallArgumentComposite($phake));19$composite->add(new Phake\Composite\CallStaticPropertyCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentComposite($phake));20$composite->add(new Phake\Composite\CallStaticPropertyCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallArgumentComposite($phake));21$composite->add(new Phake\Composite\CallStaticPropertyCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentComposite($phake));22$composite->add(new Phake\Composite\CallStaticPropertyCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallArgumentComposite($phake));23$composite->add(new Phake\Composite\CallStaticPropertyCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentCallStaticArgumentComposite($ph

Full Screen

Full Screen

Composite

Using AI Code Generation

copy

Full Screen

1$composite = new Phake_Composite();2$composite->add(new Phake_MockReader());3$composite->add(new Phake_MockWriter());4$mock = $composite->getMock('MyClass');5$mock->doSomething();6$mock->doSomethingElse();7$mock = Phake::mock('MyClass');8$mock->doSomething();9$mock->doSomethingElse();

Full Screen

Full Screen

Composite

Using AI Code Generation

copy

Full Screen

1$composite = Phake::mock('Composite');2$composite = Phake::stub('Composite');3$composite = Phake::partialMock('Composite');4$composite = Phake::partialStub('Composite');5$composite = Phake::mock('Component');6$composite = Phake::stub('Component');7$composite = Phake::partialMock('Component');8$composite = Phake::partialStub('Component');9$composite = Phake::mock('CompositeTrait');10$composite = Phake::stub('CompositeTrait');11$composite = Phake::partialMock('CompositeTrait');12$composite = Phake::partialStub('CompositeTrait');13How to get the contents of a directory in PHP using glob()?14How to get the contents of a directory in PHP using scandir()?15How to get the contents of a directory in PHP using opendir()?16How to get the contents of a directory in PHP using readdir()?17How to delete a directory and its contents in PHP using rmdir()?18How to delete a directory and its contents in PHP using unlink()?19How to delete a directory and its contents in PHP using glob()?

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Phake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Composite

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful