Пример #1
0
 public function testGetContentData()
 {
     $categoryEntity1 = new CategoryEntity();
     $categoryTranslation1 = new CategoryTranslationEntity();
     $categoryTranslation1->setLocale('en');
     $categoryTranslation1->setTranslation('Category 1');
     $categoryEntity1->addTranslation($categoryTranslation1);
     $categoryEntity2 = new CategoryEntity();
     $categoryTranslation2 = new CategoryTranslationEntity();
     $categoryTranslation2->setLocale('en');
     $categoryTranslation2->setTranslation('Category 2');
     $categoryEntity2->addTranslation($categoryTranslation2);
     $category1 = new Category($categoryEntity1, 'en');
     $category2 = new Category($categoryEntity2, 'en');
     $categoryManager = $this->prophesize(CategoryManagerInterface::class);
     $categoryManager->findByIds([1, 2])->willReturn([$categoryEntity1, $categoryEntity2]);
     $categoryManager->getApiObjects([$categoryEntity1, $categoryEntity2], 'de')->willReturn([$category1, $category2]);
     $categoryList = new CategoryList($categoryManager->reveal(), '');
     $structure = $this->prophesize(StructureInterface::class);
     $structure->getLanguageCode()->willReturn('de');
     $property = $this->prophesize(Property::class);
     $property->getValue()->willReturn([1, 2]);
     $property->getStructure()->willReturn($structure->reveal());
     $result = $categoryList->getContentData($property->reveal());
     $this->assertEquals([$category1->toArray(), $category2->toArray()], $result);
     $categoryManager->findByIds([1, 2])->shouldBeCalled();
     $categoryManager->getApiObjects([$categoryEntity1, $categoryEntity2], 'de')->shouldBeCalled();
 }
Пример #2
0
 public function testRead()
 {
     $categoryEntity1 = new CategoryEntity();
     $categoryTranslation1 = new CategoryTranslationEntity();
     $categoryTranslation1->setLocale('en');
     $categoryTranslation1->setTranslation('Category 1');
     $categoryEntity1->addTranslation($categoryTranslation1);
     $categoryEntity2 = new CategoryEntity();
     $categoryTranslation2 = new CategoryTranslationEntity();
     $categoryTranslation2->setLocale('en');
     $categoryTranslation2->setTranslation('Category 2');
     $categoryEntity2->addTranslation($categoryTranslation2);
     $category1 = new Category($categoryEntity1, 'en');
     $category2 = new Category($categoryEntity2, 'en');
     $this->categoryManager->expects($this->any())->method('findByIds')->will($this->returnValueMap([[[1, 2], [$categoryEntity1, $categoryEntity2]]]));
     $this->categoryManager->expects($this->any())->method('getApiObjects')->will($this->returnValueMap([[[$categoryEntity1, $categoryEntity2], 'en', [$category1, $category2]]]));
     $node = $this->getMockBuilder('PHPCR\\NodeInterface')->getMock();
     $node->expects($this->any())->method('getPropertyValueWithDefault')->will($this->returnValueMap([['property', [], [1, 2]]]));
     $property = $this->getMockBuilder('Sulu\\Component\\Content\\Compat\\PropertyInterface')->getMock();
     $property->expects($this->any())->method('getName')->willReturn('property');
     $property->expects($this->any())->method('setValue')->with([$category1->toArray(), $category2->toArray()]);
     $this->categoryManager->expects($this->once())->method('findByIds');
     $this->categoryList->read($node, $property, null, 'en', null);
 }
Пример #3
0
 public function testGetFallbacks()
 {
     $category = new Category();
     $category->setDefaultLocale('en');
     $categoryTrans = new CategoryTranslation();
     $categoryTrans->setLocale('en');
     $categoryTrans->setTranslation('EN');
     $categoryTrans->setCategory($category);
     $category->addTranslation($categoryTrans);
     $categoryTrans = new CategoryTranslation();
     $categoryTrans->setLocale('en_us');
     $categoryTrans->setTranslation('EN-US');
     $categoryTrans->setCategory($category);
     $category->addTranslation($categoryTrans);
     $this->em->persist($category);
     $this->em->flush();
     $client = $this->createAuthenticatedClient();
     $client->request('GET', '/api/categories/' . $category->getId() . '?locale=de');
     $response = json_decode($client->getResponse()->getContent());
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $this->assertEquals('en', $response->locale);
     $this->assertEquals('en', $response->defaultLocale);
     $this->assertEquals('EN', $response->name);
     $client->request('GET', '/api/categories/' . $category->getId() . '?locale=en_us');
     $response = json_decode($client->getResponse()->getContent());
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $this->assertEquals('en_us', $response->locale);
     $this->assertEquals('en', $response->defaultLocale);
     $this->assertEquals('EN-US', $response->name);
 }
Пример #4
0
 /**
  * Creates a new Translation for category.
  *
  * @return CategoryTranslation
  */
 private function createTranslation()
 {
     $translation = new CategoryTranslation();
     $translation->setLocale($this->locale);
     $translation->setCategory($this->entity);
     $this->entity->addTranslation($translation);
     if ($this->getId() === null && $this->getDefaultLocale() === null) {
         // new entity and new translation
         // save first locale as default
         $this->entity->setDefaultLocale($this->locale);
     }
     return $translation;
 }
Пример #5
0
 /**
  * Returns the translation with the given locale.
  *
  * @param string $locale The locale to return
  *
  * @return MappingAttributeTranslation
  */
 public function getTranslation()
 {
     foreach ($this->entity->getTranslations() as $translation) {
         if ($translation->getLocale() == $this->locale) {
             return $translation;
         }
     }
     $translation = new CategoryTranslation();
     $translation->setLocale($this->locale);
     $translation->setCategory($this->entity);
     $this->entity->addTranslation($translation);
     return $translation;
 }
Пример #6
0
 public function initOrm()
 {
     $this->db('ORM')->purgeDatabase();
     /* First Category
        -------------------------------------*/
     $category = new Category();
     $category->setKey('first-category-key');
     // name for first category
     $categoryTrans = new CategoryTranslation();
     $categoryTrans->setLocale('en');
     $categoryTrans->setTranslation('First Category');
     $categoryTrans->setCategory($category);
     $category->addTranslation($categoryTrans);
     $this->category1 = $category;
     // meta for first category
     $categoryMeta = new CategoryMeta();
     $categoryMeta->setLocale('en');
     $categoryMeta->setKey('description');
     $categoryMeta->setValue('Description of Category');
     $categoryMeta->setCategory($category);
     $category->addMeta($categoryMeta);
     $this->meta1 = $categoryMeta;
     $this->em->persist($category);
     /* Second Category
        -------------------------------------*/
     $category2 = new Category();
     $category2->setKey('second-category-key');
     $this->category2 = $category2;
     // name for second category
     $categoryTrans2 = new CategoryTranslation();
     $categoryTrans2->setLocale('de');
     $categoryTrans2->setTranslation('Second Category');
     $categoryTrans2->setCategory($category2);
     $category2->addTranslation($categoryTrans2);
     // meta for second category
     $categoryMeta2 = new CategoryMeta();
     $categoryMeta2->setLocale('de');
     $categoryMeta2->setKey('description');
     $categoryMeta2->setValue('Description of second Category');
     $categoryMeta2->setCategory($category2);
     $category2->addMeta($categoryMeta2);
     // meta without locale for second category
     $categoryMeta3 = new CategoryMeta();
     $categoryMeta3->setKey('noLocaleKey');
     $categoryMeta3->setValue('noLocaleValue');
     $categoryMeta3->setCategory($category2);
     $category2->addMeta($categoryMeta3);
     $this->em->persist($category2);
     /* Third Category (child of first)
        -------------------------------------*/
     $category3 = new Category();
     $category3->setParent($category);
     $this->category3 = $category3;
     // name for third category
     $categoryTrans3 = new CategoryTranslation();
     $categoryTrans3->setLocale('en');
     $categoryTrans3->setTranslation('Third Category');
     $categoryTrans3->setCategory($category3);
     $category3->addTranslation($categoryTrans3);
     // meta for third category
     $categoryMeta4 = new CategoryMeta();
     $categoryMeta4->setLocale('de');
     $categoryMeta4->setKey('another');
     $categoryMeta4->setValue('Description of third Category');
     $categoryMeta4->setCategory($category3);
     $category3->addMeta($categoryMeta4);
     $this->em->persist($category3);
     /* Fourth Category (child of third)
        -------------------------------------*/
     $category4 = new Category();
     $category4->setParent($category3);
     $this->category4 = $category4;
     // name for fourth category
     $categoryTrans4 = new CategoryTranslation();
     $categoryTrans4->setLocale('en');
     $categoryTrans4->setTranslation('Fourth Category');
     $categoryTrans4->setCategory($category4);
     $category4->addTranslation($categoryTrans4);
     // meta for fourth category
     $categoryMeta5 = new CategoryMeta();
     $categoryMeta5->setLocale('de');
     $categoryMeta5->setKey('anotherkey');
     $categoryMeta5->setValue('Description of fourth Category');
     $categoryMeta5->setCategory($category4);
     $category4->addMeta($categoryMeta5);
     $this->em->persist($category4);
     $this->em->flush();
 }
Пример #7
0
 private function initOrm()
 {
     $this->purgeDatabase();
     $contact = new Contact();
     $contact->setFirstName('Max');
     $contact->setLastName('Mustermann');
     $contact->setPosition('CEO');
     $contact->setFormOfAddress(1);
     $contact->setSalutation('Sehr geehrter Herr Dr Mustermann');
     $contact->setDisabled(0);
     $this->contact = $contact;
     $title = new ContactTitle();
     $title->setTitle('MSc');
     $contact->setTitle($title);
     $position = new Position();
     $position->setPosition('Manager');
     $account = new Account();
     $account->setLft(0);
     $account->setRgt(1);
     $account->setDepth(0);
     $account->setName('Musterfirma');
     $this->account = $account;
     $account1 = new Account();
     $account1->setLft(0);
     $account1->setRgt(1);
     $account1->setDepth(0);
     $account1->setName('Musterfirma');
     $this->account1 = $account1;
     $phoneType = new PhoneType();
     $phoneType->setName('Private');
     $this->phoneType = $phoneType;
     $phone = new Phone();
     $phone->setPhone('123456789');
     $phone->setPhoneType($phoneType);
     $contact->addPhone($phone);
     $this->phone = $phone;
     $emailType = new EmailType();
     $emailType->setName('Private');
     $this->emailType = $emailType;
     $email = new Email();
     $email->setEmail('*****@*****.**');
     $email->setEmailType($emailType);
     $contact->addEmail($email);
     $this->email = $email;
     $faxType = new FaxType();
     $faxType->setName('Private');
     $this->faxType = $faxType;
     $fax = new Fax();
     $fax->setFax('123654789');
     $fax->setFaxType($faxType);
     $contact->addFax($fax);
     $this->fax = $fax;
     $country1 = new Country();
     $country1->setName('Musterland');
     $country1->setCode('ML');
     $this->country = $country1;
     $country2 = new Country();
     $country2->setName('United States');
     $country2->setCode('US');
     $this->country2 = $country2;
     $addressType = new AddressType();
     $addressType->setName('Private');
     $this->addressType = $addressType;
     $address = new Address();
     $address->setStreet('Musterstraße');
     $address->setNumber('1');
     $address->setZip('0000');
     $address->setCity('Musterstadt');
     $address->setState('Musterland');
     $address->setCountry($country1);
     $address->setAddressType($addressType);
     $address->setBillingAddress(true);
     $address->setPrimaryAddress(true);
     $address->setDeliveryAddress(false);
     $address->setPostboxCity('Dornbirn');
     $address->setPostboxPostcode('6850');
     $address->setPostboxNumber('4711');
     $address->setNote('Note');
     $this->address = $address;
     $contactAddress = new ContactAddress();
     $contactAddress->setAddress($address);
     $contactAddress->setContact($contact);
     $contactAddress->setMain(true);
     $this->contactAddress = $contactAddress;
     $contact->addContactAddress($contactAddress);
     $address->addContactAddress($contactAddress);
     $note = new Note();
     $note->setValue('Note');
     $this->note = $note;
     $contact->addNote($note);
     $this->em->persist($contact);
     $this->em->persist($title);
     $this->em->persist($position);
     $this->em->persist($account);
     $this->em->persist($account1);
     $this->em->persist($phoneType);
     $this->em->persist($phone);
     $this->em->persist($faxType);
     $this->em->persist($fax);
     $this->em->persist($emailType);
     $this->em->persist($email);
     $this->em->persist($country1);
     $this->em->persist($country2);
     $this->em->persist($addressType);
     $this->em->persist($contactAddress);
     $this->em->persist($address);
     $this->em->persist($note);
     /* First Category
        -------------------------------------*/
     $category = new Category();
     $category->setKey('first-category-key');
     $this->category = $category;
     // name for first category
     $categoryTrans = new CategoryTranslation();
     $categoryTrans->setLocale('en');
     $categoryTrans->setTranslation('First Category');
     $categoryTrans->setCategory($category);
     $category->addTranslation($categoryTrans);
     // meta for first category
     $categoryMeta = new CategoryMeta();
     $categoryMeta->setLocale('en');
     $categoryMeta->setKey('description');
     $categoryMeta->setValue('Description of Category');
     $categoryMeta->setCategory($category);
     $category->addMeta($categoryMeta);
     $this->em->persist($category);
     /* Second Category
        -------------------------------------*/
     $category2 = new Category();
     $category2->setKey('second-category-key');
     $this->category2 = $category2;
     // name for second category
     $categoryTrans2 = new CategoryTranslation();
     $categoryTrans2->setLocale('de');
     $categoryTrans2->setTranslation('Second Category');
     $categoryTrans2->setCategory($category2);
     $category2->addTranslation($categoryTrans2);
     // meta for second category
     $categoryMeta2 = new CategoryMeta();
     $categoryMeta2->setLocale('de');
     $categoryMeta2->setKey('description');
     $categoryMeta2->setValue('Description of second Category');
     $categoryMeta2->setCategory($category2);
     $category2->addMeta($categoryMeta2);
     $this->em->persist($category2);
     $this->em->flush();
     $this->contactTitle = $title;
     $this->contactPosition = $position;
 }