public function createContentLang($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();
         }
     };
     Content::all()->each($callback);
     return Content::find(1)->ContentLangs()->getResults()->count() === $n;
 }
Exemplo n.º 2
0
 public function testDetectsBugWhenUpdate()
 {
     $mockedConfig = $this->getMockedConfig();
     $mockedConfig->shouldReceive('get')->with('multilang::prefix')->andReturn('@');
     $mockedConfig->shouldReceive('get')->with('multilang::reservedAttribute')->andReturn('__lang_id__');
     $messageBag = $this->getMockedMessageBag();
     $validator = $this->getMockedValid();
     $wrapper = $this->getWrapper();
     $mockedConfig->shouldReceive('get')->andReturn('Lang');
     $validator->shouldReceive('make')->andReturn(true);
     $multiLang = new MultiLang(new Picker(new Collection(), new Element(), $mockedConfig), $mockedConfig, $messageBag, $validator, $wrapper, $this->app['cache.store']);
     $this->assertTrue($multiLang->create($this->multilangPost, new Content()));
     //                    '_token'    =>'wqkjf9012r0f128f12f',
     //                    'enable'    => 1,
     //                    'visible'   => 1,
     //                    'content@1' => 'Content 1',
     //                    'title@1'   => 'Title 1',
     //                    'content@2' => 'Content 2',
     //                    'title@2'   => 'Title 2',
     $created = Content::find(1);
     $lang1Before = $created->ContentLangs()->getQuery()->where('__lang_id__', 1)->get();
     $this->assertCount(1, $lang1Before);
     $post = $this->multilangPost;
     $post['content@1'] = '';
     $post['title@2'] = '';
     $this->assertTrue($multiLang->update($post, $created));
     $updated = Content::find(1);
     $lang1 = $updated->ContentLangs()->getQuery()->where('__lang_id__', 1)->first();
     $lang2 = $updated->ContentLangs()->getQuery()->where('__lang_id__', 2)->first();
     $this->assertEquals($lang1->content, $post['content@1']);
     $this->assertEquals($lang2->title, $post['title@2']);
 }
Exemplo n.º 3
0
 public function testJsonableInterfaceImplementWithDifferentLang()
 {
     $this->assertTrue($this->createContent(3));
     /* first */
     $content = Content::find(1);
     $postFirst = ['__lang_id__' => 1, 'title' => 'First Title', 'content' => 'First Content'];
     $lang1 = $content->ContentLangs()->create($postFirst);
     $wrapper = $this->wrapper->createNew($content, 2);
     $attributes = array_merge($content->getAttributes(), $lang1->getAttributes());
     $this->assertEquals($attributes, $wrapper->toArray());
     $wrapper->toJson();
     // not need to check!!
     // fixed!!
 }