public function testUserBlame() { $context = $this->getContainer()->get('security.context'); $token = new UsernamePasswordToken('test', 'test', 'test_provider', []); $user = new User(); $user->setUsername('dantleech'); $user->setPassword('foo'); $user->setLocale('fr'); $user->setSalt('saltz'); $this->db('ORM')->getOm()->persist($user); $this->db('ORM')->getOm()->flush(); $token->setUser($user); $context->setToken($token); $contact = new Contact(); $contact->setFirstName('Max'); $contact->setLastName('Mustermann'); $contact->setPosition('CEO'); $contact->setSalutation('Sehr geehrter Herr Dr Mustermann'); $this->db('ORM')->getOm()->persist($contact); $this->db('ORM')->getOm()->flush(); $changer = $contact->getChanger(); $creator = $contact->getCreator(); $this->assertSame($changer, $user); $this->assertSame($creator, $user); }
protected function initOrm() { $this->purgeDatabase(); $contact = new Contact(); $contact->setFirstName('Max'); $contact->setLastName('Mustermann'); $this->em->persist($contact); $this->em->flush(); $emailType = new EmailType(); $emailType->setName('Private'); $this->em->persist($emailType); $this->em->flush(); $email = new Email(); $email->setEmail('*****@*****.**'); $email->setEmailType($emailType); $this->em->persist($email); $this->em->flush(); $role1 = new Role(); $role1->setName('Role1'); $role1->setSystem('Sulu'); $this->em->persist($role1); $this->em->flush(); $user = new User(); $user->setUsername('admin'); $user->setPassword('securepassword'); $user->setSalt('salt'); $user->setLocale('de'); $user->setContact($contact); $this->em->persist($user); $this->em->flush(); $userRole1 = new UserRole(); $userRole1->setRole($role1); $userRole1->setUser($user); $userRole1->setLocale(json_encode(['de', 'en'])); $this->em->persist($userRole1); $this->em->flush(); $permission1 = new Permission(); $permission1->setPermissions(122); $permission1->setRole($role1); $permission1->setContext('Context 1'); $this->em->persist($permission1); $this->em->flush(); $tag1 = new Tag(); $tag1->setName('tag1'); $this->em->persist($tag1); $this->em->flush(); $tag2 = new Tag(); $tag2->setName('tag2'); $this->em->persist($tag2); $this->em->flush(); $tag3 = new Tag(); $tag3->setName('tag3'); $this->em->persist($tag3); $this->em->flush(); $tag4 = new Tag(); $tag4->setName('tag4'); $this->em->persist($tag4); $this->em->flush(); }
private function createUser() { $user = new User(); $user->setUsername('dantleech'); $user->setPassword('mypassword'); $user->setLocale('en'); $user->setSalt('12345'); $this->entityManager->persist($user); $this->entityManager->flush(); $this->user = $user; }
public function setUp() { $this->em = $this->db('ORM')->getOm(); $this->purgeDatabase(); // User 1 $user1 = new User(); $user1->setUsername('user1'); $user1->setEmail('*****@*****.**'); $user1->setPassword('securepassword'); $user1->setSalt('salt'); $user1->setLocale('en'); $this->user1 = $user1; $this->em->persist($this->user1); // User 2 $user2 = new User(); $user2->setUsername('user2'); $user2->setEmail(null); $user2->setPassword('securepassword'); $user2->setSalt('salt'); $user2->setLocale('en'); $this->user2 = $user2; $this->em->persist($this->user2); // User 3 $user3 = new User(); $user3->setUsername('user3'); $user3->setEmail('*****@*****.**'); $user3->setPassword('securepassword'); $user3->setSalt('salt'); $user3->setLocale('en'); $user3->setPasswordResetToken('thisisasupersecrettoken'); $user3->setPasswordResetTokenExpiresAt((new \DateTime())->add(new \DateInterval('PT24H'))); $user3->setPasswordResetTokenEmailsSent(1); $this->user3 = $user3; $this->em->persist($this->user3); $this->em->flush(); }
public function setUp() { $this->em = $this->db('ORM')->getOm(); $this->purgeDatabase(); $emailType = new EmailType(); $emailType->setName('Private'); $this->em->persist($emailType); $email1 = new Email(); $email1->setEmail('*****@*****.**'); $email1->setEmailType($emailType); $this->em->persist($email1); // Contact $contact1 = new Contact(); $contact1->setFirstName('Max'); $contact1->setLastName('Mustermann'); $contact1->addEmail($email1); $this->em->persist($contact1); $this->contact1 = $contact1; $email = new Email(); $email->setEmail('*****@*****.**'); $email->setEmailType($emailType); $this->em->persist($email); $contact2 = new Contact(); $contact2->setFirstName('Max'); $contact2->setLastName('Muster'); $contact2->addEmail($email); $this->em->persist($contact2); $this->contact2 = $contact2; $contact3 = new Contact(); $contact3->setFirstName('Disabled'); $contact3->setLastName('User'); $contact3->addEmail($email); $this->em->persist($contact3); $this->contact3 = $contact3; $this->em->flush(); $role1 = new Role(); $role1->setName('Role1'); $role1->setSystem('Sulu'); $this->em->persist($role1); $this->role1 = $role1; $role2 = new Role(); $role2->setName('Role2'); $role2->setSystem('Sulu'); $this->em->persist($role2); $this->role2 = $role2; // User 1 $user = new User(); $user->setUsername('admin'); $user->setEmail('*****@*****.**'); $user->setPassword('securepassword'); $user->setSalt('salt'); $user->setLocale('de'); $user->setContact($contact2); $this->em->persist($user); $this->user1 = $user; // User 2 $user1 = new User(); $user1->setUsername('disabled'); $user1->setEmail('*****@*****.**'); $user1->setPassword('securepassword'); $user1->setSalt('salt'); $user1->setLocale('de'); $user1->setContact($contact3); $user1->setEnabled(false); $this->em->persist($user1); $this->user2 = $user1; $this->em->flush(); $userRole1 = new UserRole(); $userRole1->setRole($role1); $userRole1->setUser($user); $userRole1->setLocale(json_encode(['de', 'en'])); $this->em->persist($userRole1); $userRole2 = new UserRole(); $userRole2->setRole($role2); $userRole2->setUser($user); $userRole2->setLocale(json_encode(['de', 'en'])); $this->em->persist($userRole2); $userRole3 = new UserRole(); $userRole3->setRole($role2); $userRole3->setUser($user); $userRole3->setLocale(json_encode(['de', 'en'])); $this->em->persist($userRole3); $permission1 = new Permission(); $permission1->setPermissions(122); $permission1->setRole($role1); $permission1->setContext('Context 1'); $this->em->persist($permission1); $permission2 = new Permission(); $permission2->setPermissions(122); $permission2->setRole($role2); $permission2->setContext('Context 2'); $this->em->persist($permission2); // user groups $group1 = new Group(); $group1->setName('Group1'); $group1->setLft(0); $group1->setRgt(0); $group1->setDepth(0); $this->em->persist($group1); $this->group1 = $group1; $group2 = new Group(); $group2->setName('Group2'); $group2->setLft(0); $group2->setRgt(0); $group2->setDepth(0); $this->em->persist($group2); $this->group2 = $group2; $this->em->flush(); }
/** * Setup test data. */ protected function setUpTestData() { // Account $this->account = new Account(); $this->account->setName('Company'); $this->account->setType(Account::TYPE_BASIC); $this->account->setUid('uid-123'); $this->account->setMainEmail('*****@*****.**'); $this->account2 = clone $this->account; // Country $country = new Country(); $country->setName('Country'); $country->setCode('co'); // Address type $addressType = new AddressType(); $addressType->setName('Business'); // Address $this->address = new Address(); $this->address->setStreet('Sample-Street'); $this->address->setNumber('12'); $this->address->setAddition('Entrance 2'); $this->address->setCity('Sample-City'); $this->address->setState('State'); $this->address->setZip('12345'); $this->address->setCountry($country); $this->address->setPostboxNumber('postboxNumber'); $this->address->setPostboxPostcode('postboxPostcode'); $this->address->setPostboxCity('postboxCity'); $this->address->setAddressType($addressType); // Address $this->address2 = new Address(); $this->address2->setStreet('Street'); $this->address2->setNumber('2'); $this->address2->setCity('Utopia'); $this->address2->setZip('1'); $this->address2->setCountry($country); $this->address2->setAddressType($addressType); // Add address to entities. $accountAddress = new AccountAddress(); $accountAddress->setAccount($this->account); $accountAddress->setAddress($this->address); $accountAddress->setMain(true); $this->account->addAccountAddress($accountAddress); // Phone $phoneType = new PhoneType(); $phoneType->setName('Business'); $this->phone = new Phone(); $this->phone->setPhone('+43 123 / 456 789'); $this->phone->setPhoneType($phoneType); // Contact Title $title = new ContactTitle(); $title->setTitle('Dr'); // Contact $this->contact = $this->contactRepository->createNew(); $this->contact->setFirstName('John'); $this->contact->setLastName('Doe'); $this->contact->setTitle($title); $this->contact->setMainEmail('*****@*****.**'); // Second Contact $this->contact2 = $this->contactRepository->createNew(); $this->contact2->setFirstName('Johanna'); $this->contact2->setLastName('Dole'); $this->contact2->setMainEmail('*****@*****.**'); $contact = $this->contactRepository->createNew(); $contact->setFirstName('Max'); $contact->setLastName('Mustermann'); $this->em->persist($contact); $this->accountContact = $this->createAccountContact($this->account, $this->contact, true); $this->accountContact2 = $this->createAccountContact($this->account, $this->contact2, true); $user = new User(); $user->setUsername('test'); $user->setPassword('test'); $user->setSalt(''); $user->setLocale('en'); $user->setContact($this->contact); $this->user = $user; $this->orderStatus = $this->em->getRepository(self::$orderStatusEntityName)->find(OrderStatus::STATUS_CREATED); // Order address $this->orderAddressDelivery = new OrderAddress(); $this->orderAddressDelivery->setFirstName($this->contact->getFirstName()); $this->orderAddressDelivery->setLastName($this->contact->getLastName()); $this->orderAddressDelivery->setTitle($title->getTitle()); $this->orderAddressDelivery->setStreet($this->address->getStreet()); $this->orderAddressDelivery->setNumber($this->address->getNumber()); $this->orderAddressDelivery->setAddition($this->address->getAddition()); $this->orderAddressDelivery->setCity($this->address->getCity()); $this->orderAddressDelivery->setZip($this->address->getZip()); $this->orderAddressDelivery->setState($this->address->getState()); $this->orderAddressDelivery->setCountry($this->address->getCountry()->getName()); $this->orderAddressDelivery->setPostboxNumber($this->address->getPostboxNumber()); $this->orderAddressDelivery->setPostboxPostcode($this->address->getPostboxPostcode()); $this->orderAddressDelivery->setPostboxCity($this->address->getPostboxCity()); $this->orderAddressDelivery->setAccountName($this->account->getName()); $this->orderAddressDelivery->setUid($this->account->getUid()); $this->orderAddressDelivery->setPhone($this->phone->getPhone()); $this->orderAddressDelivery->setPhoneMobile('+43 123 / 456'); $this->orderAddressDelivery->setContactAddress($this->address); // Clone address for invoice. $this->orderAddressInvoice = clone $this->orderAddressDelivery; $this->termsOfDelivery = new TermsOfDelivery(); $this->termsOfDelivery->setTerms('10kg minimum'); $this->termsOfPayment = new TermsOfPayment(); $this->termsOfPayment->setTerms('10% off'); // Order $this->order = $this->createNewTestOrder(); $order2 = $this->createNewTestOrder(); $order2->setNumber('12345'); $order2->setDeliveryAddress(null); $order2->setInvoiceAddress(null); // Product order unit $orderUnit = new Unit(); $orderUnit->setId(1); $orderUnitTranslation = new UnitTranslation(); $orderUnitTranslation->setUnit($orderUnit); $orderUnitTranslation->setName('pc'); $orderUnitTranslation->setLocale('en'); $orderUnit->addTranslation($orderUnitTranslation); $this->em->persist($orderUnit); $this->em->persist($orderUnitTranslation); // Product type $productType = new Type(); $productType->setTranslationKey('product-type'); // Product status $productStatus = new Status(); $productStatus->setId(Status::ACTIVE); $metadata = $this->em->getClassMetadata(Status::class); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $productStatusTranslation = new StatusTranslation(); $productStatusTranslation->setLocale($this->locale); $productStatusTranslation->setName('EnglishProductStatus-1'); $productStatusTranslation->setStatus($productStatus); // Product $this->product = new $this->productEntity(); $this->product->setNumber('ProductNumber-1'); $this->product->setManufacturer('EnglishManufacturer-1'); $this->product->setType($productType); $this->product->setStatus($productStatus); $this->product->setCreated(new DateTime()); $this->product->setChanged(new DateTime()); $this->product->setSupplier($this->account); $this->product->setOrderUnit($orderUnit); // Product translation $this->productTranslation = new ProductTranslation(); $this->productTranslation->setProduct($this->product); $this->productTranslation->setLocale($this->locale); $this->productTranslation->setName('EnglishProductTranslationName-1'); $this->productTranslation->setShortDescription('EnglishProductShortDescription-1'); $this->productTranslation->setLongDescription('EnglishProductLongDescription-1'); $this->product->addTranslation($this->productTranslation); // Product $this->product2 = clone $this->product; $this->product2->setSupplier($this->account); $translation2 = clone $this->productTranslation; $translation2->setProduct($this->product2); $this->product2->addTranslation($translation2); $this->em->persist($translation2); $this->currency = new Currency(); $this->currency->setCode($this->defaultCurrencyCode); $this->currency->setNumber('1'); $this->currency->setId('1'); $this->currency->setName('Euro'); $this->productPrice = new ProductPrice(); $this->productPrice->setCurrency($this->currency); $this->productPrice->setMinimumQuantity(0); $this->productPrice->setPrice(14.5); $this->productPrice->setProduct($this->product); $this->product->addPrice($this->productPrice); $price2 = clone $this->productPrice; $price2->setProduct($this->product2); $price2->setPrice(15.5); $this->em->persist($price2); $this->product2->addPrice($price2); // Item $this->item = $this->createNewTestItem(); $this->item2 = $this->createNewTestItem(); $this->item2->setSupplier($this->account2); $orderTypeTranslationManual = new OrderTypeTranslation(); $orderTypeTranslationManual->setLocale('en'); $orderTypeTranslationManual->setName('order type translation manual'); $orderTypeTranslationShop = new OrderTypeTranslation(); $orderTypeTranslationShop->setLocale('en'); $orderTypeTranslationShop->setName('order type translation shop'); $orderTypeTranslationAnon = new OrderTypeTranslation(); $orderTypeTranslationAnon->setLocale('en'); $orderTypeTranslationAnon->setName('order type translation anon'); $this->orderTypeManual = new OrderType(); $metadata = $this->em->getClassMetadata(get_class($this->orderTypeManual)); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $this->orderTypeManual->setId(OrderType::MANUAL); $this->orderTypeManual->addTranslation($orderTypeTranslationManual); $orderTypeTranslationManual->setType($this->orderTypeManual); $this->orderTypeShop = new OrderType(); $metadata = $this->em->getClassMetadata(get_class($this->orderTypeShop)); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $this->orderTypeShop->setId(OrderType::SHOP); $this->orderTypeShop->addTranslation($orderTypeTranslationShop); $orderTypeTranslationShop->setType($this->orderTypeShop); $this->orderTypeAnon = new OrderType(); $metadata = $this->em->getClassMetadata(get_class($this->orderTypeAnon)); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $this->orderTypeAnon->setId(OrderType::ANONYMOUS); $this->orderTypeAnon->addTranslation($orderTypeTranslationAnon); $orderTypeTranslationAnon->setType($this->orderTypeAnon); $this->order->addItem($this->item); $this->order->addItem($this->item2); $this->order->setType($this->orderTypeManual); $order2->setType($this->orderTypeManual); $item = $this->createNewTestItem(); $item2 = $this->createNewTestItem(); $order2->addItem($item); $order2->addItem($item2); $this->addonPrice = new AddonPrice(); $this->addonPrice->setPrice(123.56); $this->addonPrice->setCurrency($this->currency); $this->addon = new Addon(); $this->addon->setProduct($this->product); $this->addon->setAddon($this->product2); $this->addonPrice->setAddon($this->addon); $this->addon->addAddonPrice($this->addonPrice); $this->em->persist($this->addon); $this->em->persist($this->addonPrice); $this->em->persist($item); $this->em->persist($item2); $this->em->persist($accountAddress); $this->em->persist($this->currency); $this->em->persist($this->productPrice); $this->em->persist($user); $this->em->persist($this->orderTypeManual); $this->em->persist($this->orderTypeShop); $this->em->persist($this->orderTypeAnon); $this->em->persist($orderTypeTranslationManual); $this->em->persist($orderTypeTranslationShop); $this->em->persist($orderTypeTranslationAnon); $this->em->persist($this->account); $this->em->persist($this->account2); $this->em->persist($title); $this->em->persist($country); $this->em->persist($this->termsOfPayment); $this->em->persist($this->termsOfDelivery); $this->em->persist($country); $this->em->persist($addressType); $this->em->persist($this->address); $this->em->persist($this->address2); $this->em->persist($phoneType); $this->em->persist($this->phone); $this->em->persist($this->contact); $this->em->persist($this->contact2); $this->em->persist($this->orderAddressDelivery); $this->em->persist($this->orderAddressInvoice); $this->em->persist($this->item); $this->em->persist($this->item2); $this->em->persist($this->product); $this->em->persist($this->product2); $this->em->persist($this->productTranslation); $this->em->persist($productType); $this->em->persist($productStatus); $this->em->persist($productStatusTranslation); $this->em->flush(); }
private function prepareUser($username, $password, $enabled = true, $locked = false) { $emailType = new EmailType(); $emailType->setName('Private'); $this->em->persist($emailType); $email = new Email(); $email->setEmail('*****@*****.**'); $email->setEmailType($emailType); $this->em->persist($email); $contact1 = new Contact(); $contact1->setFirstName('Max'); $contact1->setLastName('Muster'); $contact1->addEmail($email); $this->em->persist($contact1); $user = new User(); $user->setUsername($username); $user->setPassword($password); $user->setSalt('salt'); $user->setLocale('de'); $user->setContact($contact1); $user->setEnabled($enabled); $user->setLocked($locked); $this->em->persist($user); $role = new Role(); $role->setName('Sulu'); $role->setSystem('Sulu'); $this->em->persist($role); $userRole = new UserRole(); $userRole->setRole($role); $userRole->setUser($user); $userRole->setLocale(''); $this->em->persist($userRole); $this->em->flush(); return $user; }