public function createContentLangSoftDelete($n)
 {
     $callback = function ($item) use($n) {
         for ($i = 0; $i < $n; $i++) {
             $item->ContentLangs()->create(['__lang_id__' => $i, 'title' => str_random(5), 'content' => str_random(10)])->save();
         }
     };
     ContentSoftDelete::all()->each($callback);
     return ContentSoftDelete::find(1)->ContentLangs()->getResults()->count() === $n;
 }
Beispiel #2
0
 public function testOnSoftDeleteEnebledModels()
 {
     $this->assertTrue($this->createContentSoftDelete(3));
     /* first */
     $content = ContentSoftDelete::find(1);
     $postFirst = ['__lang_id__' => 1, 'title' => 'First Title', 'content' => 'First Content'];
     $content->ContentLangs()->create($postFirst);
     /* second */
     $postSecond = ['__lang_id__' => 2, 'title' => 'Second Title', 'content' => 'Second Content'];
     $content->ContentLangs()->create($postSecond);
     /* third */
     $postThird = ['__lang_id__' => 3, 'title' => 'Third Title', 'content' => 'Third Content'];
     $content->ContentLangs()->create($postThird);
     Model\ContentLangSoftDelete::all()->each(function ($item) {
         if ((int) $item->__lang_id__ === 3) {
             $item->delete();
         }
     });
     $wrapper = $this->wrapper->createNew($content, 3, 1);
     $this->assertEquals($wrapper->wanted(1)->title, $postFirst['title']);
     $this->assertEquals($wrapper->wanted(2)->title, $postSecond['title']);
     // var_dump(\DB::getQueryLog());
     $this->assertEquals($wrapper->wanted(3)->force()->title, null);
     $this->assertEquals($wrapper->wanted(3)->title, $postFirst['title']);
     $this->assertEquals($wrapper->title, $postFirst['title']);
 }