Beispiel #1
0
 public function testMerge()
 {
     // Basic merge.
     $tag1 = Tag::firstOrCreate(['name' => 'Tag 1']);
     $tag2 = Tag::firstOrCreate(['name' => 'Tag 2']);
     $this->assertSame(2, Tag::count());
     $tag1->merge($tag2);
     $this->assertSame(1, Tag::count());
     $this->assertSame('Tag 1', Tag::first()->name);
     // Merge when the other-tag has assets attached.
     $tag3 = Tag::firstOrCreate(['name' => 'Tag 3']);
     $asset = Asset::firstOrCreate(['identifier' => 'Asset 1']);
     $asset->addTags('Tag 3');
     $this->assertSame(2, Tag::count());
     $tag1->merge($tag3);
     $this->assertSame(1, Tag::count());
     $this->assertSame(1, $tag1->assets->count());
     $this->assertSame('Tag 1', $asset->tagsAsString());
     // What about when a JobList is already tagged with both tags?
     $type = new \App\Model\JobType();
     $type->save();
     $jobList = new JobList();
     $jobList->name = 'JL1';
     $jobList->type_id = $type->id;
     $jobList->save();
     $jobList->addTags('Tag 1, Tag 4, Tag 5');
     $tag4 = Tag::firstOrCreate(['name' => 'Tag 4']);
     $this->assertSame(3, Tag::count());
     $tag1->merge($tag4);
     $this->assertSame(2, Tag::count());
     $this->assertSame('Tag 1, Tag 5', $jobList->tagsAsString());
 }
 /**
  * @testdox Tags can be added to Job Lists.
  * @test
  */
 public function tags()
 {
     $type = new \App\Model\JobType();
     $type->save();
     $jobList = new JobList();
     $jobList->type_id = $type->id;
     $jobList->save();
     $jobList->addTags('one,two');
     $this->assertEquals(2, Tag::count());
 }
 public function saveNew(Request $request)
 {
     DB::beginTransaction();
     $jobList = new JobList();
     $jobList->name = $request->input('name');
     $jobList->type_id = $request->input('type_id');
     $jobList->start_date = $request->input('start_date');
     $jobList->due_date = $request->input('due_date');
     $jobList->crew_id = $request->input('crew_id');
     $jobList->comments = $request->input('comments');
     $jobList->save();
     $jobList->addTags($request->input('tags'));
     // Then save all assets.
     $assets = $this->getAssets($request);
     foreach ($assets as $asset) {
         $job = new Job();
         $job->job_list_id = $jobList->id;
         $job->asset_id = $asset->id;
         $job->date_added = date('Y-m-d');
         $job->save();
     }
     DB::commit();
     return redirect('job-lists/' . $jobList->id);
 }