private function _check(WithEmbeddedArrayI18NModel $model, $data)
 {
     foreach ($data as $i => $field) {
         foreach ($field as $code => $title) {
             $msg = sprintf("When model key is `%d` and language is `%s`", $i, $code);
             $model->setLang($code);
             $this->assertSame($title, $model->pages[$i]->title, $msg);
         }
     }
 }
示例#2
0
 public function testIfEventWillPropagateAndRevokeSave()
 {
     $model = new WithEmbeddedArrayI18NModel();
     $m1 = new ModelWithI18N();
     $m2 = new ModelWithI18NSecond();
     $model->pages[] = $m1;
     $model->page = $m2;
     $triggered1 = false;
     $triggered2 = false;
     $beforeSave1 = function (ModelEvent $event) use(&$triggered1) {
         $triggered1 = true;
         $event->isValid = false;
     };
     $beforeSave2 = function (ModelEvent $event) use(&$triggered2) {
         $triggered2 = true;
         $event->isValid = false;
     };
     Event::on($m1, EntityManagerInterface::EventBeforeSave, $beforeSave1);
     Event::on($m2, EntityManagerInterface::EventBeforeSave, $beforeSave2);
     $saved = $model->save();
     $this->assertFalse($saved);
     $this->assertTrue($triggered1);
     $this->assertTrue($triggered2);
 }