createUser('test-1'); $user2 = $this->createUser('test-2'); $this->auth('test-1'); $app = $this->createApplication(); /** @var EntityManager $em */ $em = $app->getContainer()->getByClass(EntityManager::class); $account = $em->createEntity(Account::ENTITY_TYPE, ['name' => '1']); $this->assertEquals($user1->getId(), $account->get('createdById')); $this->auth('test-2'); $app = $this->createApplication(); /** @var EntityManager $em */ $em = $app->getContainer()->getByClass(EntityManager::class); $account = $em->getEntityById(Account::ENTITY_TYPE, $account->getId()); $account->set('name', '2'); $em->saveEntity($account); $this->assertEquals($user2->getId(), $account->get('modifiedById')); $this->auth('test-1'); $app = $this->createApplication(); /** @var EntityManager $em */ $em = $app->getContainer()->getByClass(EntityManager::class); $account = $em->getEntityById(Account::ENTITY_TYPE, $account->getId()); $account->set('name', '2'); $em->saveEntity($account); $this->assertEquals($user2->getId(), $account->get('modifiedById')); } public function testIsRelated(): void { $em = $this->getEntityManager(); $acc1 = $em->createEntity(Account::ENTITY_TYPE, []); $acc2 = $em->createEntity(Account::ENTITY_TYPE, []); $opp1 = $em->createEntity(Opportunity::ENTITY_TYPE, []); $contact1 = $em->createEntity(Contact::ENTITY_TYPE, []); $contact2 = $em->createEntity(Contact::ENTITY_TYPE, []); $oppRepo = $em->getRDBRepositoryByClass(Opportunity::class); $oppRepo->getRelation($opp1, 'account')->relate($acc1); $oppRepo->getRelation($opp1, 'contacts')->relate($contact1); $this->assertTrue( $oppRepo->getRelation($opp1, 'account')->isRelatedById($acc1->getId()) ); $this->assertTrue( $oppRepo->getRelation($opp1, 'account')->isRelated($acc1) ); $this->assertFalse( $oppRepo->getRelation($opp1, 'account')->isRelatedById($acc2->getId()) ); $this->assertFalse( $oppRepo->getRelation($opp1, 'account')->isRelated($acc2) ); $this->assertTrue( $oppRepo->getRelation($opp1, 'contacts')->isRelatedById($contact1->getId()) ); $this->assertTrue( $oppRepo->getRelation($opp1, 'contacts')->isRelated($contact1) ); $this->assertFalse( $oppRepo->getRelation($opp1, 'contacts')->isRelatedById($contact2->getId()) ); $this->assertFalse( $oppRepo->getRelation($opp1, 'contacts')->isRelated($contact2) ); } }