Beispiel #1
0
 public function fromArray($array, $columns = [])
 {
     if (empty($columns) && count($array) > 0) {
         $columns = array_keys(current($array));
     }
     $adapter = new ArrayAdapter($this->options['length']);
     $adapter->setArray($array);
     $adapter->setParser($this->parser);
     $adapter->setColumns($columns);
     $this->response = $adapter->getResponse();
     return $this;
 }
            $carry[] = $item['name'];
            return $carry;
        });
        expect($names)->toBe(['gebert', 'marvin.maybelle', 'zabernathy']);
    });
    it("should order", function () {
        $_GET = ['columns' => [['data' => 'name', 'searchable' => "true"]], 'order' => [['column' => 0, 'dir' => 'desc']]];
        $dataTables = new ArrayAdapter(20);
        $dataTables->setArray($this->array);
        $dataTables->setColumns(['name', 'email']);
        $dataTables->setParser(new ParamsParser(10));
        $response = $dataTables->getResponse();
        expect(count($response['data']))->toBe(10);
        expect($response['data'][0]['name'])->toBe('zcremin');
    });
    it("should order asc", function () {
        $_GET = ['columns' => [['data' => 'name', 'searchable' => "true"]], 'order' => [['column' => 0, 'dir' => 'asc']]];
        $dataTables = new ArrayAdapter(20);
        $dataTables->setArray($this->array);
        $dataTables->setColumns(['name', 'email']);
        $dataTables->setParser(new ParamsParser(10));
        $response = $dataTables->getResponse();
        expect(count($response['data']))->toBe(10);
        expect($response['data'][0]['name'])->toBe('adelia13');
    });
    afterEach(function () {
        unset($_GET);
        unset($_POST);
        unset($_REQUEST);
    });
});