/** * Simple test that will test if the immutable object is created as wished */ public function testBasicColumnConfiguration() { $name = "fooBar"; $cc = ColumnConfigurationBuilder::create()->name($name)->searchable(Searchable::REGEX())->orderable(Orderable::NONE())->build(); $this->assertSame($name, $cc->getName(), "Name should be set correctly"); $this->assertTrue($cc->getSearch()->isSearchable(), "The column should be searchable"); $this->assertFalse($cc->getOrder()->isOrderable(), "The column should be orderable"); }
/** * Will test if the query parser will ignore search and order advise if the columns forbid them * */ public function testWrongParsing() { // create columnconfiguration $column = ColumnConfigurationBuilder::create()->name("fooBar")->orderable(Orderable::NONE())->searchable(Searchable::NONE())->build(); $conf = $this->parser->parse($this->request, [$column]); // assert column search $this->assertCount(0, $conf->searchColumns()); // assert column order $this->assertCount(0, $conf->orderColumns()); }
public function testClass() { $t = Orderable::DESC(); $this->assertTrue($t->isOrderable()); }
/** * Will check if the orderable flag is correctly set, otherwise it will be set to the default NONE */ private function checkOrderable() { if ($this->orderable == null) { $this->orderable = Orderable::BOTH(); } }
/** * Will check if the column method with the name and a callable as well as the searchable and orderable flag has * all values set to the right defaults */ public function testNameFunctionSearchableOrderableColumn() { $name = "fooBar"; $callable = function ($data) { return "bar"; }; $this->composer->column($name, $callable, Searchable::NONE(), Orderable::NONE()); // get configuration and verify $numberOfColumns = count($this->composer->getColumnConfiguration()); $this->assertSame($numberOfColumns, 1, "There should only be one column configuration"); /** * @var ColumnConfiguration */ $cc = $this->composer->getColumnConfiguration()[0]; /** * @var callable */ $func = $cc->getCallable(); $this->assertTrue($cc->getSearch()->isSearchable(), "The column should not be searchable"); $this->assertTrue($cc->getOrder()->isOrderable(), "The column should be orderable"); $this->assertSame($name, $cc->getName(), "The name should be set to 'fooBar'"); $this->assertSame("bar", $func("fooBar")); }
/** * Will create a new ColumnConfiguration with all defaults but allows overriding of all properties through the method. * * @param string $name The name of the configuration, required for the configuration * @param string|callable $callable The function to execute, defaults to null which means the default will be set. * @param Searchable $searchable If the column should be searchable or not * @param Orderable $orderable If the column should be orderable or not * @return $this */ public function column($name, $callable = null, Searchable $searchable = null, Orderable $orderable = null) { /** * @var ColumnConfigurationBuilder */ $config = ColumnConfigurationBuilder::create(); if (is_string($name)) { $config->name($name); } else { throw new \InvalidArgumentException('$name must be a string'); } if (!is_null($callable)) { if (is_callable($callable)) { $config->withCallable($callable); } elseif (is_string($callable)) { $config->withCallable(function () use($callable) { return $callable; }); } } if (is_null($searchable)) { $config->searchable(Searchable::NORMAL()); } if (is_null($orderable)) { $config->orderable(Orderable::BOTH()); } $this->columnConfiguration[] = $config->build(); return $this; }