Esempio n. 1
0
 /**
  * @test
  */
 public function it_provides_an_ordered_trait()
 {
     $i = 1;
     foreach (Dummy::ordered()->get()->lists('order_column') as $order) {
         $this->assertEquals($i++, $order);
     }
 }
Esempio n. 2
0
 protected function setUpDatabase()
 {
     $this->app['db']->connection()->getSchemaBuilder()->create('dummies', function (Blueprint $table) {
         $table->increments('id');
         $table->string('name');
         $table->integer('order_column');
     });
     collect(range(1, 20))->each(function (int $i) {
         Dummy::create(['name' => $i]);
     });
 }
Esempio n. 3
0
 protected function setUpDatabase()
 {
     file_put_contents(__DIR__ . '/database.sqlite', null);
     $this->app['db']->connection()->getSchemaBuilder()->create('dummies', function (Blueprint $table) {
         $table->increments('id');
         $table->string('name');
         $table->integer('order_column');
     });
     for ($i = 1; $i <= 20; $i++) {
         Dummy::create(['name' => $i]);
     }
 }
Esempio n. 4
0
 /**
  * @test
  */
 public function it_can_move_a_model_to_the_last_place()
 {
     $position = 3;
     $oldModels = Dummy::whereNot('id', $position)->get();
     $model = Dummy::find($position);
     $this->assertNotEquals(20, $model->order_column);
     $model = $model->moveToEnd();
     $this->assertEquals(20, $model->order_column);
     $oldModels = $oldModels->pluck('order_column', 'id');
     $newModels = Dummy::whereNot('id', $position)->get()->pluck('order_column', 'id');
     foreach ($oldModels as $key => $order) {
         if ($order > $position) {
             $this->assertEquals($order - 1, $newModels[$key]);
         } else {
             $this->assertEquals($order, $newModels[$key]);
         }
     }
 }
Esempio n. 5
0
 /**
  * @test
  */
 public function it_will_determine_to_sort_when_creating_if_sortable_attribute_does_not_exist()
 {
     $model = new Dummy();
     $this->assertTrue($model->shouldSortWhenCreating());
 }
 /**
  * @test
  */
 public function it_throws_an_exception_when_it_cant_move_the_order_up()
 {
     $lastModel = Dummy::first();
     $this->assertEquals($lastModel->order_column, 1);
     $this->assertFalse($lastModel->moveOrderUp());
 }