public function testContrustor01() { $config = Loader::load(['requestUrl' => 'url.url', 'requestMethod' => 'get', 'dom' => 'abcd', 'itemName' => 'personne', 'itemsName' => 'personnes', 'itemGenre' => 'e', 'separator' => '|', 'config' => ['test' => 'ing'], 'defaultSort' => [0, 'asc'], 'autoWidth' => true]); $columns = new Columns(Loader::load(['nom' => ['filter' => true, 'sort' => true, 'class' => 'uppercase'], 'prenom' => ['filter' => true, 'sort' => true], 'age' => ['filter' => false, 'sort' => true, 'width' => '10px']])); $this->if($c = $this->newTestedInstance($config, $columns)); return $c; }
public function testConstruct03() { $connection = $this->getConnection(); $conf = Loader::load(['select' => ['a', 'v'], 'from' => ['name' => 'tt', 'alias' => 't'], 'where' => ['a = v'], 'innerJoin' => [['name' => 'uu', 'alias' => 'u', 'on' => 'u.c = t.v']], 'group' => 't.a']); $columns = new Columns(Loader::load(['a' => ['source' => 't.a']])); $this->if($c = $this->newTestedInstance($conf, $columns, $connection))->and($c->addOrder('a', 'ASC'))->and($c->addFilter([['t.a'], 'trieur php', 'Contain']))->and($c->setOffset(10))->and($c->setLength(5))->and($qB = $c->getQuery())->string($qB->getSQL())->isEqualTo('SELECT a, v FROM tt t INNER JOIN uu u ON u.c = t.v WHERE a = v')->and($qB = $c->getDataQuery())->string($qB->getSQL())->isEqualTo('SELECT a, v ' . 'FROM tt t ' . 'INNER JOIN uu u ON u.c = t.v ' . 'WHERE (a = v) ' . 'AND (t.a LIKE "%trieur php%" OR t.a LIKE "%trieur%" OR t.a LIKE "%php%") ' . 'GROUP BY t.a ' . 'ORDER BY IF(t.a LIKE "%trieur php%", 10, 0) + IF(t.a LIKE "%trieur%", 6, 0) + IF(t.a LIKE "%php%", 3, 0) DESC, ' . 't.a ' . 'ASC ' . 'LIMIT 5 ' . 'OFFSET 10')->and($qB = $c->getCountQuery())->string($qB->getSQL())->isEqualTo('SELECT COUNT(DISTINCT t.a) ' . 'FROM tt t ' . 'INNER JOIN uu u ON u.c = t.v ' . 'WHERE a = v')->and($qB = $c->getFilteredCountQuery())->string($qB->getSQL())->isEqualTo('SELECT COUNT(DISTINCT t.a) ' . 'FROM tt t ' . 'INNER JOIN uu u ' . 'ON u.c = t.v ' . 'WHERE (a = v) ' . 'AND (t.a LIKE "%trieur php%" OR t.a LIKE "%trieur%" OR t.a LIKE "%php%")'); }
public function testConstruct01() { $connection = $this->getConnection(); $conf = Loader::load(['select' => ['c.id', 'c.nom'], 'from' => [['name' => Profil::class, 'alias' => 'c']], 'group' => 'c.id']); $columns = new Columns(Loader::load(['id' => ['source' => 'c.id'], 'nom' => ['source' => 'c.nom']])); /* @var $param Parameter */ $this->if($c = $this->newTestedInstance($conf, $columns, $connection))->object($c)->object($qB = $c->getQuery())->isInstanceOf(QueryBuilder::class)->string($dql = $qB->getDQL())->isEqualTo('SELECT c.id, c.nom FROM ' . Profil::class . ' c')->string($qB->getQuery()->getSQL())->match('#^SELECT (\\w+)\\.id AS (\\w+), \\1\\.nom AS (\\w+) FROM profil \\1$#')->object($qB = $c->getDataQuery())->isInstanceOf(QueryBuilder::class)->string($dql = $qB->getDQL())->isEqualTo('SELECT c.id, c.nom FROM ' . Profil::class . ' c GROUP BY c.id')->string($qB->getQuery()->getSQL())->match('#^SELECT (\\w+)\\.id AS (\\w+), \\1\\.nom AS (\\w+) FROM profil \\1 GROUP BY \\1.id$#')->object($qB = $c->getCountQuery())->isInstanceOf(QueryBuilder::class)->string($dql = $qB->getDQL())->isEqualTo('SELECT COUNT(DISTINCT c.id) FROM ' . Profil::class . ' c')->string($qB->getQuery()->getSQL())->match('#^SELECT COUNT\\(DISTINCT (\\w+)\\.id\\) AS (\\w+) FROM profil \\1$#')->object($qB = $c->getFilteredCountQuery())->isInstanceOf(QueryBuilder::class)->string($dql = $qB->getDQL())->isEqualTo('SELECT COUNT(DISTINCT c.id) FROM ' . Profil::class . ' c')->string($qB->getQuery()->getSQL())->match('#^SELECT COUNT\\(DISTINCT (\\w+)\\.id\\) AS (\\w+) FROM profil \\1$#')->if($term = 'audi')->and($c->addFilter(['c.nom', $term, 'Contain']))->object($qB = $c->getDataQuery())->isInstanceOf(QueryBuilder::class)->string($dql = $qB->getDQL())->isEqualTo('SELECT c.id, c.nom FROM ' . Profil::class . ' c WHERE c.nom LIKE :word_1 GROUP BY c.id')->string($qB->getQuery()->getSQL())->match('#^SELECT (\\w+)\\.id AS (\\w+), \\1\\.nom AS (\\w+) FROM profil \\1 WHERE \\1\\.nom LIKE \\? GROUP BY \\1\\.id$#')->object($param = $qB->getParameter('word_1'))->isInstanceOf(Parameter::class)->string($param->getValue())->isEqualTo('%' . $term . '%')->if($c->setLength(1))->and($c->setOffset(1))->object($qB = $c->getDataQuery())->isInstanceOf(QueryBuilder::class)->string($dql = $qB->getDQL())->isEqualTo('SELECT c.id, c.nom FROM ' . Profil::class . ' c WHERE c.nom LIKE :word_1 GROUP BY c.id')->string($qB->getQuery()->getSQL())->match('#^SELECT (\\w+)\\.id AS (\\w+), \\1\\.nom AS (\\w+) FROM profil \\1 WHERE \\1\\.nom LIKE \\? GROUP BY \\1\\.id LIMIT 1 OFFSET 1$#')->if($c->addOrder('id'))->object($qB = $c->getDataQuery())->isInstanceOf(QueryBuilder::class)->string($dql = $qB->getDQL())->isEqualTo('SELECT c.id, c.nom FROM ' . Profil::class . ' c WHERE c.nom LIKE :word_1 GROUP BY c.id ORDER BY c.id ASC')->string($qB->getQuery()->getSQL())->match('#^SELECT (\\w+)\\.id AS (\\w+), \\1\\.nom AS (\\w+) FROM profil \\1 WHERE \\1\\.nom LIKE \\? GROUP BY \\1\\.id ORDER BY \\1\\.id ASC LIMIT 1 OFFSET 1$#'); }
public static function run() { $configPath = 'config/client.yml'; $array = Yaml::parse($configPath); $conf = Loader::load($array); $trieur = new Trieur($conf); self::$jsConfig = $trieur->getDriver()->getJsConfig(); self::$jsColumnFilterConfig = $trieur->getDriver()->getColumnFilterConfig(); }
public static function run() { $configPath = 'config/client.yml'; $array = Yaml::parse($configPath); $conf = Loader::load($array); $trieur = new Trieur($conf, 'data/clients.csv'); $trieur->setRequest($_POST); $response = $trieur->getResponse(); return $response; }
/** * Contrôle des getters & setters * * @return void */ public function testLoad() { $data = ['test' => 'plop', 'foo' => ['bar' => 'foobar']]; $confResult = new \Solire\Conf\Conf(); $confResult->set('plop', 'test')->set('foobar', 'foo', 'bar'); $this->assert('$data est un un objet conf')->object(TestClass::load($confResult))->isEqualTo($confResult)->assert('$data est un tableau')->object(TestClass::load($data))->isEqualTo($confResult)->assert('$data est un chemin vers un .ini')->if($confIniRef = new IniToConf($this->localIni))->given($confIni = TestClass::load($this->localIni))->object($confIni->get('database'))->isEqualTo($confIniRef->get('database'))->assert('$data est un chemin vers un .yml')->if($confYmlRef = new YmlToConf($this->localYml))->given($confYml = TestClass::load($this->localYml))->object($confYml->get('database'))->isEqualTo($confYmlRef->get('database'))->assert('$data n\'est pas exploitable')->exception(function () { TestClass::load('Data'); })->hasMessage('Aucune données exploitable pour charger une Conf')->isInstanceOf('\\Solire\\Conf\\Exception')->exception(function () { TestClass::load(TEST_DATA_DIR . '/foo.falsext'); })->hasMessage('Aucune données exploitable pour charger une Conf')->isInstanceOf('\\Solire\\Conf\\Exception')->assert('$data multiple')->if($conf = TestClass::load($data, $this->localIni, $this->localYml))->string($conf->database->host)->isEqualTo('localhost')->string($conf->get('foo', 'bar'))->isEqualTo('foobar'); }
public function testGet() { $col03 = Loader::load(['attr01' => 'value.03.01', 'attr02' => 'value.03.02', 'source' => 'source.03', 'sourceSort' => 'sourceSort.03', 'sourceFilter' => 'sourceFilter.03', 'filterType' => 'select']); $conf = Loader::load(['offset01' => ['attr01' => 'value.01.01', 'attr02' => 'value.01.02'], 'offset02' => ['attr01' => 'value.02.01', 'attr02' => 'value.02.02', 'source' => 'source.02'], 'offset03' => $col03]); $this->if($columns = $this->newTestedInstance($conf))->object($columns->get(0))->isInstanceOf('\\Solire\\Conf\\Conf')->object($columns->get('offset01'))->isInstanceOf('\\Solire\\Conf\\Conf')->exception(function () use($columns) { $columns->get('wrongIndex'); })->isInstanceOf('\\Exception')->hasMessage('Undefined index "wrongIndex" in the columns list'); $keys = range(0, 2); foreach ($columns as $key => $column) { $this->integer($key)->isEqualTo(array_shift($keys))->object($column)->isInstanceOf('\\Solire\\Conf\\Conf'); } }
public static function run() { $configPath = 'config/client.yml'; $array = Yaml::parse($configPath); $conf = Loader::load($array); $configDbPath = 'config/connection.ini'; $configDb = parse_ini_file($configDbPath); $configDb['driverOptions'] = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']; $doctrineConnection = DriverManager::getConnection($configDb); $trieur = new Trieur($conf, $doctrineConnection); $response = $trieur->getResponse(); return $response; }
public function testConstruct() { $conf = Loader::load(['nom' => ['format' => []]]); $columns = new \Solire\Trieur\Columns($conf); $this->if($f = $this->newTestedInstance($columns))->exception(function () use($f) { $f->format([['nom' => 'solire']]); })->hasMessage('Undefined format class for column [nom]'); $conf = Loader::load(['nom' => ['format' => ['class' => 'arg']]]); $columns = new \Solire\Trieur\Columns($conf); $this->if($f = $this->newTestedInstance($columns))->exception(function () use($f) { $f->format([['nom' => 'solire']]); })->hasMessage('Format class [arg] for column [nom] does not exist'); $conf = Loader::load(['nom' => ['format' => ['class' => '\\DateTime']]]); $columns = new \Solire\Trieur\Columns($conf); $this->if($f = $this->newTestedInstance($columns))->exception(function () use($f) { $f->format([['nom' => 'solire']]); })->hasMessage('Format class [\\DateTime] does not extend abstract class [\\Solire\\Trieur\\AbstractFormat]'); $conf = Loader::load(['nom' => ['format' => ['class' => 'Callback', 'name' => 'strtoupper', 'cell' => 'str']], 'prenom' => ['format' => ['class' => 'Solire\\Trieur\\Format\\Callback', 'name' => 'ucfirst', 'cell' => 'str']], 'age' => []]); $columns = new \Solire\Trieur\Columns($conf); $this->if($f = $this->newTestedInstance($columns))->array($f->format([['nom' => 'solire', 'prenom' => 'thomas']]))->isEqualTo([['nom' => 'SOLIRE', 'prenom' => 'Thomas', 'age' => '']]); }
public function testConstruct02() { $conf = Loader::load([]); $columns = new Columns(Loader::load(['0' => ['sort' => 1], '1' => ['sort' => 1], '2' => ['sort' => 1], '3' => ['sort' => 1]])); $this->if($c = $this->newTestedInstance($conf, $columns, TEST_TMP_DIR . DIRECTORY_SEPARATOR . $this->fileName))->integer($c->getCount())->isEqualTo(6)->phpArray($c->getData())->isEqualTo([['1', 'a', '3', 'thomas'], ['2', 'z', '2', 'thomas'], ['3', 'z', '2', 'jérôme'], ['4', 't', '5', 'julie'], ['5', 't', '5', 'abel'], ['6', 'c', '5', 'julie']])->and($c->setOrders([['1', 'asc']]))->phpArray($c->getData())->isEqualTo([['1', 'a', '3', 'thomas'], ['6', 'c', '5', 'julie'], ['4', 't', '5', 'julie'], ['5', 't', '5', 'abel'], ['2', 'z', '2', 'thomas'], ['3', 'z', '2', 'jérôme']])->and($c->addOrder('3', 'asc'))->phpArray($c->getData())->isEqualTo([['1', 'a', '3', 'thomas'], ['6', 'c', '5', 'julie'], ['5', 't', '5', 'abel'], ['4', 't', '5', 'julie'], ['3', 'z', '2', 'jérôme'], ['2', 'z', '2', 'thomas']])->and($c->setOrders([['1', 'desc'], ['3', 'desc']]))->phpArray($c->getData())->isEqualTo([['2', 'z', '2', 'thomas'], ['3', 'z', '2', 'jérôme'], ['4', 't', '5', 'julie'], ['5', 't', '5', 'abel'], ['6', 'c', '5', 'julie'], ['1', 'a', '3', 'thomas']])->and($c->setOffset(2))->and($c->setLength(3))->phpArray($c->getData())->isEqualTo([['4', 't', '5', 'julie'], ['5', 't', '5', 'abel'], ['6', 'c', '5', 'julie']])->and($c->setOffset(0))->and($c->setFilters([[[3], ['a'], 'Contain']]))->phpArray($c->getData())->isEqualTo([['2', 'z', '2', 'thomas'], ['5', 't', '5', 'abel'], ['1', 'a', '3', 'thomas']])->and($c->addFilter([[3], 'th', 'Contain']))->phpArray($c->getData())->isEqualTo([['2', 'z', '2', 'thomas'], ['1', 'a', '3', 'thomas']])->integer($c->getFilteredCount())->isEqualTo(2); }
public function testContrustor00() { $config = Loader::load([]); $columns = new Columns(Loader::load(['nom' => ['filter' => true, 'sort' => true], 'prenom' => ['filter' => true, 'sort' => true]])); $this->if($c = $this->newTestedInstance($config, $columns))->and($c->setRequest([]))->array($c->getOrder())->isEqualTo([])->array($c->getFilters())->isEqualTo([])->variable($c->getOffset())->isNull()->variable($c->getLength())->isNull()->phpArray($c->getFilters())->isEmpty()->string($c->getResponse([['dubois', 'jean'], ['patrick', 'duchmucl']]))->isEqualTo('dubois,jean' . "\n" . 'patrick,duchmucl' . "\n"); }
public function testGetResponse() { $conf = Loader::load(['driver' => ['name' => 'csv'], 'source' => ['name' => 'csv'], 'columns' => ['4' => ['format' => ['class' => 'Solire\\Trieur\\Format\\Callback', 'name' => ['\\Solire\\Trieur\\Example\\Format', 'sqlTo'], 'cell' => 'dateSql', 'arguments' => ['format' => 'd/m/Y']]]]]); $this->if($trieur = $this->newTestedInstance($conf, $this->csvPath()))->string($trieur->getResponse())->isEqualTo('06/02/2014' . "\n" . '08/02/2014' . "\n" . '16/02/2014' . "\n" . '22/02/2014' . "\n" . '01/02/2014' . "\n" . '11/02/2014' . "\n"); $conf = Loader::load(['driver' => ['name' => 'csv'], 'source' => ['name' => 'csv'], 'columns' => ['0' => ['format' => ['class' => 'Solire\\Trieur\\Format\\Callback', 'name' => ['\\Solire\\Trieur\\Example\\Format', 'serialize'], 'row' => 'row', 'cell' => 'value']]]]); $this->if($trieur = $this->newTestedInstance($conf, $this->csvPath()))->string($trieur->getResponse())->isEqualTo('"a:5:{i:0;s:1:""1"";i:1;s:1:""a"";i:2;s:1:""3"";i:3;s:6:""thomas"";i:4;s:10:""2014-02-06"";}|1"' . "\n" . '"a:5:{i:0;s:1:""2"";i:1;s:1:""z"";i:2;s:1:""2"";i:3;s:6:""thomas"";i:4;s:10:""2014-02-08"";}|2"' . "\n" . '"a:5:{i:0;s:1:""3"";i:1;s:1:""z"";i:2;s:1:""2"";i:3;s:8:""jérôme"";i:4;s:10:""2014-02-16"";}|3"' . "\n" . '"a:5:{i:0;s:1:""4"";i:1;s:1:""t"";i:2;s:1:""5"";i:3;s:5:""julie"";i:4;s:10:""2014-02-22"";}|4"' . "\n" . '"a:5:{i:0;s:1:""5"";i:1;s:1:""t"";i:2;s:1:""5"";i:3;s:4:""abel"";i:4;s:10:""2014-02-01"";}|5"' . "\n" . '"a:5:{i:0;s:1:""6"";i:1;s:1:""c"";i:2;s:1:""5"";i:3;s:5:""julie"";i:4;s:10:""2014-02-11"";}|6"' . "\n"); $conf = Loader::load(['driver' => ['name' => 'csv'], 'source' => ['name' => 'csv'], 'columns' => ['0' => [], '1' => [], '2' => []]]); $this->if($trieur = $this->newTestedInstance($conf, $this->csvPath()))->string($trieur->getResponse())->isEqualTo('1,a,3' . "\n" . '2,z,2' . "\n" . '3,z,2' . "\n" . '4,t,5' . "\n" . '5,t,5' . "\n" . '6,c,5' . "\n"); }