Exemplo n.º 1
0
 public function testIfWillCompareModel()
 {
     $langs = [];
     $model = new WithEmbeddedArrayI18NModel();
     // Attach first
     $m = new ModelWithI18N();
     $m->setLang('en');
     $m->_id = new \MongoId();
     $m->setLanguages($langs);
     $m->layout = 'new';
     $m->title = 'New York';
     $m->setLang('pl');
     $m->title = 'Nowy Jork';
     $m->setLang('en');
     $model->pages[] = $m;
     // Attach second
     $m2 = new ModelWithI18N();
     $m2->setLang('en');
     $m2->_id = new \MongoId();
     $m2->setLanguages($langs);
     $m2->layout = 'new';
     $m2->title = 'Prague';
     $m2->setLang('pl');
     $m2->title = 'Praga';
     $m2->setLang('en');
     $model->pages[] = $m2;
     $comparator = new ModelComparator($this);
     $data = RawArray::fromModel($model);
     foreach ([0, 1] as $i) {
         $this->assertSame($model->pages[$i]->_id, $data['pages'][$i]['_id']);
         $this->assertSame($model->pages[$i]->title, $data['pages'][$i]['title']['en']);
         $this->assertSame($model->pages[$i]->layout, $data['pages'][$i]['layout']);
     }
     $comparator->compare($data, $model);
 }
 public function testIfWillDecorateI18NFieldsOnSecondLanguageSet()
 {
     $model = new ModelWithI18N();
     $model->setLang('en');
     $model->setLang('pl');
     $cd = new ConditionDecorator($model);
     $title = $cd->decorate('title', 'Title');
     $active = $cd->decorate('active', 1);
     $this->assertSame('title.pl', key($title));
     $this->assertSame('Title', $title['title.pl']);
     $this->assertSame('active.pl', key($active));
     $this->assertSame(true, $active['active.pl']);
 }
Exemplo n.º 3
0
 public function testIfExistsByCriteriaI18N()
 {
     $langs = ['en', 'pl'];
     $model = new ModelWithI18N();
     $model->setLanguages($langs);
     $model->title = 'foot';
     $finder = new Finder($model);
     $criteria = new Criteria();
     $criteria->title = 'foot';
     // Should not exists
     $this->assertFalse($finder->exists($criteria));
     (new EntityManager($model))->insert();
     // Should exists
     $this->assertTrue($finder->exists($criteria));
 }
 /**
  * This is use case, where model is initialized from external JSON
  * And order of elements are changed in json.
  */
 public function testIfWillProperlyStoreI18NFieldsWhenChangedOrderFromExternalSource()
 {
     $langs = ['en', 'pl'];
     $model = new WithEmbeddedArrayI18NModel();
     // Attach single
     $one = new ModelWithI18N();
     $one->setLanguages($langs);
     $one->layout = 'new';
     $one->title = 'New York';
     $one->setLang('pl');
     $one->title = 'Nowy Jork';
     $one->setLang('en');
     $model->page = $one;
     // Attach first
     $m = new ModelWithI18N();
     $m->setLanguages($langs);
     $m->layout = 'new';
     $m->title = 'New York';
     $m->setLang('pl');
     $m->title = 'Nowy Jork';
     $m->setLang('en');
     $model->pages[] = $m;
     // Attach second
     $m = new ModelWithI18NSecond();
     $m->setLanguages($langs);
     $m->layout = 'new';
     $m->title = 'Prague';
     $m->setLang('pl');
     $m->title = 'Praga';
     $m->setLang('en');
     $model->pages[] = $m;
     // This are expected values
     $expectedData = RawArray::fromModel($model);
     $expectedData['pages'] = array_reverse($expectedData['pages']);
     // Now assume that external json data arrived
     $externalData = JsonArray::fromModel($model);
     $externalData['pages'] = array_reverse($externalData['pages']);
     $expectedModel = JsonArray::toModel($externalData, $model, $model);
     $comparator = new ModelComparator($this);
     $comparator->compare($expectedData, $expectedModel);
     $raw = RawArray::fromModel($expectedModel);
 }
Exemplo n.º 5
0
 public function testIfWillStoreI18NFields()
 {
     $model = new ModelWithI18N();
     $model->setLanguages(['en', 'pl']);
     $model->_id = new MongoId();
     $model->setLang('en');
     $model->title = 'english';
     $model->active = true;
     $em = new EntityManager($model);
     $em->save();
     $finder = new Finder($model);
     $found = $finder->findByPk($model->_id);
     $this->assertNotNull($found);
     $found->setLang('en');
     $this->assertSame($model->title, $found->title);
     $this->assertSame($model->active, $found->active);
     $found->setLang('pl');
     $model->title = 'english';
     $model->active = true;
 }