diff --git a/.buildpath b/.buildpath index 35f4a364..a7d2788d 100644 --- a/.buildpath +++ b/.buildpath @@ -33,6 +33,11 @@ + + + + + @@ -43,7 +48,7 @@ - + @@ -138,11 +143,6 @@ - - - - - @@ -378,11 +378,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -393,6 +423,16 @@ + + + + + + + + + + diff --git a/src6/Data/Schema.php b/src6/Data/Schema.php index 9c131216..e4e5f1f7 100644 --- a/src6/Data/Schema.php +++ b/src6/Data/Schema.php @@ -4,7 +4,7 @@ use Pluf\Options; use Pluf\Db\Connection; use Pluf\Db\Expression; -use Pluf_Utils; +use Pluf\Utils; /** * Create the schema of a given Pluf_Model for a given database. @@ -373,9 +373,7 @@ public function getFields(ModelDescription $md, ?string $alias = null) $alias = $alias . '.'; } foreach ($md as $name => $property) { - if ($property->type == self::MANY_TO_MANY || - $property->type == self::MANY_TO_ONE || - $property->type == self::ONE_TO_MANY) { + if ($property->type == self::MANY_TO_MANY || $property->type == self::MANY_TO_ONE || $property->type == self::ONE_TO_MANY) { continue; } $field[$name] = $alias . $this->getFieldName($md, $property, $autoPrefix); @@ -720,9 +718,7 @@ public function getValues(ModelDescription $md, $model) // DB is responsible for ID continue; } - if ($property->type == self::MANY_TO_MANY || - $property->type == self::ONE_TO_MANY || - $property->isMapped()) { + if ($property->type == self::MANY_TO_MANY || $property->type == self::ONE_TO_MANY || $property->isMapped()) { // Virtural attributes continue; } @@ -1180,7 +1176,7 @@ public static function passwordToDb($val) return $val; } // We need to hash the value. - $salt = Pluf_Utils::getRandomString(5); + $salt = Utils::getRandomString(5); return 'sha1:' . $salt . ':' . sha1($salt . $val); } diff --git a/src6/Db/Schema.php b/src6/Db/Schema.php index 60803c75..8ca2afc9 100644 --- a/src6/Db/Schema.php +++ b/src6/Db/Schema.php @@ -97,225 +97,225 @@ public function getRelationTable(Pluf_Model $from, Pluf_Model $to, ?string $rela return self::skipeName($prefix . $hay[0] . '_' . $hay[1] . '_assoc'); } - public function createQuery(Pluf_Model $model) - { - if (Pluf::f('multitenant', false) && $model->_a['multitenant']) { - $model->tenant = Tenant::getCurrent(); - } - - // $engine = $model->getEngine(); - - $icols = array(); - $ivals = array(); - // $assoc = array(); - - $raw = false; - - foreach ($model->_a['cols'] as $col => $description) { - $type = $description['type']; - $val = $model->$col; - if ($col == 'id' && ! $raw) { - continue; - } elseif ($type === Engine::MANY_TO_MANY) { - continue; - } - if($val === null && !self::isNullable($description) - && array_key_exists('default', $description)){ - $val = $description['default']; - } - $icols[] = $this->qn($col); - $ivals[] = $this->con->toDb($val, $type); - } - - return new Pluf_SQL('INSERT INTO ' . $this->getTableName($model) . '(' . implode(',', $icols) . ') VALUES (' . implode(', ', array_fill(0, sizeof($ivals), '%s')) . ')', $ivals); - } +// public function createQuery(Pluf_Model $model) +// { +// if (Pluf::f('multitenant', false) && $model->_a['multitenant']) { +// $model->tenant = Tenant::getCurrent(); +// } + +// // $engine = $model->getEngine(); + +// $icols = array(); +// $ivals = array(); +// // $assoc = array(); + +// $raw = false; + +// foreach ($model->_a['cols'] as $col => $description) { +// $type = $description['type']; +// $val = $model->$col; +// if ($col == 'id' && ! $raw) { +// continue; +// } elseif ($type === Engine::MANY_TO_MANY) { +// continue; +// } +// if($val === null && !self::isNullable($description) +// && array_key_exists('default', $description)){ +// $val = $description['default']; +// } +// $icols[] = $this->qn($col); +// $ivals[] = $this->con->toDb($val, $type); +// } + +// return new Pluf_SQL('INSERT INTO ' . $this->getTableName($model) . '(' . implode(',', $icols) . ') VALUES (' . implode(', ', array_fill(0, sizeof($ivals), '%s')) . ')', $ivals); +// } private static function isNullable($description){ return (!array_key_exists('is_null', $description) || $description['is_null'] === true); } - public function selectByIdQuery(Pluf_Model $model, $id) - { - $engine = $model->getEngine(); - $params = array( - $engine->toDb($id, Engine::SEQUENCE) - ); - if (Pluf::f('multitenant', false) && $model->_a['multitenant']) { - $req = 'SELECT * FROM ' . $this->getTableName($model) . ' WHERE tenant=%s AND id=%s'; - array_unshift($params, Pluf_Tenant::getCurrent()->id); - } else { - $req = 'SELECT * FROM ' . $this->getTableName($model) . ' WHERE id=%s'; - } - return new Pluf_SQL($req, $params); - } - - function updateQuery(Pluf_Model $model, $where = '') - { - $engine = $model->getEngine(); - $params = array(); - - $fields = []; - foreach ($model->_a['cols'] as $col => $description) { - $type = $description['type']; - if ($col == 'id') { - continue; - } elseif ($type == Engine::MANY_TO_MANY) { - continue; - } - $fields[] = $this->qn($col) . '=%s'; - $params[] = $this->con->toDb($model->$col, $type); - } - - $req = 'UPDATE ' . $this->getTableName($model) . ' SET ' . implode(',', $fields); - if (strlen($where) > 0) { - $req .= ' WHERE ' . $where; - } else { - $req .= ' WHERE id = ' . $engine->toDb($model->id, Engine::SEQUENCE); - } - return new Pluf_SQL($req, $params); - } - - function selectListQuery(Pluf_Model $model, array $p = []) - { - $default = array( - 'view' => null, - 'group' => null, - 'filter' => null, - 'order' => null, - 'start' => null, - 'select' => null, - 'nb' => null, - 'count' => false - ); - $p = array_merge($default, $p); - $query = array( - 'select' => $model->getSelect(), - 'from' => $model->_a['table'], - 'join' => '', - 'where' => '', - 'group' => '', - 'having' => '', - 'order' => '', - 'limit' => '', - 'props' => array() - ); - $params = []; - if (! is_null($p['view'])) { - $mview = $model->getView($p['view']); - $query = array_merge($query, $mview); - } - if (! is_null($p['select'])) { - $query['select'] = $p['select']; - } - if (! is_null($p['group'])) { - $query['group'] = $p['group']; - } - if (! is_null($p['filter'])) { - if (is_array($p['filter'])) { - $p['filter'] = implode(' AND ', $p['filter']); - } - if (strlen($query['where']) > 0) { - $query['where'] .= ' AND '; - } - $query['where'] .= ' (' . Pluf_SQL::cleanString($p['filter']) . ') '; - } - // Multi-Tenant filter - if (Pluf::f('multitenant', false) && $model->_a['multitenant']) { - // Note: Hadi, 1395-11-26: Table should be set before tenant field. - // It is to avoid ambiguous problem in join tables which both have tenant field. - $sql = new Pluf_SQL($model->getSqlTable() . '.tenant=%s', array( - Pluf_Tenant::current()->id - )); - if (strlen($query['where']) > 0) { - $query['where'] = ' AND ' . $query['where']; - } - $query['where'] = $sql->gen() . $query['where']; - } - if (! is_null($p['order'])) { - if (is_array($p['order'])) { - $p['order'] = implode(', ', $p['order']); - } - if (strlen($query['order']) > 0 and strlen($p['order']) > 0) { - $query['order'] .= ', '; - } - $query['order'] .= $p['order']; - } - if (! is_null($p['start']) && is_null($p['nb'])) { - $p['nb'] = 10000000; - } - if (! is_null($p['start'])) { - if ($p['start'] != 0) { - $p['start'] = (int) $p['start']; - } - $p['nb'] = (int) $p['nb']; - $query['limit'] = 'LIMIT ' . $p['nb'] . ' OFFSET ' . $p['start']; - } - if (! is_null($p['nb']) && is_null($p['start'])) { - $p['nb'] = (int) $p['nb']; - $query['limit'] = 'LIMIT ' . $p['nb']; - } - if ($p['count'] == true) { - if (isset($query['select_count'])) { - $query['select'] = $query['select_count']; - } else { - $query['select'] = 'COUNT(*) as nb_items'; - } - $query['order'] = ''; - $query['limit'] = ''; - } - $req = 'SELECT ' . $query['select'] . ' FROM ' . $this->getPrefix() . $query['from'] . ' ' . $query['join']; - if (strlen($query['where'])) { - $req .= "\n" . 'WHERE ' . $query['where']; - } - if (strlen($query['group'])) { - $req .= "\n" . 'GROUP BY ' . $query['group']; - } - if (strlen($query['having'])) { - $req .= "\n" . 'HAVING ' . $query['having']; - } - if (strlen($query['order'])) { - $req .= "\n" . 'ORDER BY ' . $query['order']; - } - if (strlen($query['limit'])) { - $req .= "\n" . $query['limit']; - } - - return new Pluf_SQL($req, $params); - } - - /** - * Inserts new relation from-to - * - * @param Pluf_Model $from - * @param Pluf_Model $to - * @param string $assocName - * @return Pluf_SQL - */ - public function createRelationQuery(Pluf_Model $from, Pluf_Model $to, ?string $relationName = null): Pluf_SQL - { - return new Pluf_SQL('INSERT INTO ' . $this->getRelationTable($from, $to, $relationName) . // - '(' . $this->getAssocField($from, $relationName) . ', ' . $this->getAssocField($to, $relationName) . ') VALUES (%s, %s)', array( - $from->id, - $to->id - )); - } - - /** - * Delete the relation from-to - * - * @param Pluf_Model $from - * @param Pluf_Model $to - * @param string $assocName - * @return Pluf_SQL - */ - public function deleteRelationQuery(Pluf_Model $from, Pluf_Model $to, ?string $relationName = null): Pluf_SQL - { - return new Pluf_SQL('DELETE FROM ' . $this->getRelationTable($from, $to, $relationName) . // - ' WHERE ' . $this->getAssocField($from, $relationName) . '=%s AND ' . $this->getAssocField($to, $relationName) . '=%s', array( - $from->id, - $to->id - )); - } +// public function selectByIdQuery(Pluf_Model $model, $id) +// { +// $engine = $model->getEngine(); +// $params = array( +// $engine->toDb($id, Engine::SEQUENCE) +// ); +// if (Pluf::f('multitenant', false) && $model->_a['multitenant']) { +// $req = 'SELECT * FROM ' . $this->getTableName($model) . ' WHERE tenant=%s AND id=%s'; +// array_unshift($params, Pluf\Tenant::getCurrent()->id); +// } else { +// $req = 'SELECT * FROM ' . $this->getTableName($model) . ' WHERE id=%s'; +// } +// return new Pluf_SQL($req, $params); +// } + +// function updateQuery(Pluf_Model $model, $where = '') +// { +// $engine = $model->getEngine(); +// $params = array(); + +// $fields = []; +// foreach ($model->_a['cols'] as $col => $description) { +// $type = $description['type']; +// if ($col == 'id') { +// continue; +// } elseif ($type == Engine::MANY_TO_MANY) { +// continue; +// } +// $fields[] = $this->qn($col) . '=%s'; +// $params[] = $this->con->toDb($model->$col, $type); +// } + +// $req = 'UPDATE ' . $this->getTableName($model) . ' SET ' . implode(',', $fields); +// if (strlen($where) > 0) { +// $req .= ' WHERE ' . $where; +// } else { +// $req .= ' WHERE id = ' . $engine->toDb($model->id, Engine::SEQUENCE); +// } +// return new Pluf_SQL($req, $params); +// } + +// function selectListQuery(Pluf_Model $model, array $p = []) +// { +// $default = array( +// 'view' => null, +// 'group' => null, +// 'filter' => null, +// 'order' => null, +// 'start' => null, +// 'select' => null, +// 'nb' => null, +// 'count' => false +// ); +// $p = array_merge($default, $p); +// $query = array( +// 'select' => $model->getSelect(), +// 'from' => $model->_a['table'], +// 'join' => '', +// 'where' => '', +// 'group' => '', +// 'having' => '', +// 'order' => '', +// 'limit' => '', +// 'props' => array() +// ); +// $params = []; +// if (! is_null($p['view'])) { +// $mview = $model->getView($p['view']); +// $query = array_merge($query, $mview); +// } +// if (! is_null($p['select'])) { +// $query['select'] = $p['select']; +// } +// if (! is_null($p['group'])) { +// $query['group'] = $p['group']; +// } +// if (! is_null($p['filter'])) { +// if (is_array($p['filter'])) { +// $p['filter'] = implode(' AND ', $p['filter']); +// } +// if (strlen($query['where']) > 0) { +// $query['where'] .= ' AND '; +// } +// $query['where'] .= ' (' . Pluf_SQL::cleanString($p['filter']) . ') '; +// } +// // Multi-Tenant filter +// if (Pluf::f('multitenant', false) && $model->_a['multitenant']) { +// // Note: Hadi, 1395-11-26: Table should be set before tenant field. +// // It is to avoid ambiguous problem in join tables which both have tenant field. +// $sql = new Pluf_SQL($model->getSqlTable() . '.tenant=%s', array( +// Pluf_Tenant::current()->id +// )); +// if (strlen($query['where']) > 0) { +// $query['where'] = ' AND ' . $query['where']; +// } +// $query['where'] = $sql->gen() . $query['where']; +// } +// if (! is_null($p['order'])) { +// if (is_array($p['order'])) { +// $p['order'] = implode(', ', $p['order']); +// } +// if (strlen($query['order']) > 0 and strlen($p['order']) > 0) { +// $query['order'] .= ', '; +// } +// $query['order'] .= $p['order']; +// } +// if (! is_null($p['start']) && is_null($p['nb'])) { +// $p['nb'] = 10000000; +// } +// if (! is_null($p['start'])) { +// if ($p['start'] != 0) { +// $p['start'] = (int) $p['start']; +// } +// $p['nb'] = (int) $p['nb']; +// $query['limit'] = 'LIMIT ' . $p['nb'] . ' OFFSET ' . $p['start']; +// } +// if (! is_null($p['nb']) && is_null($p['start'])) { +// $p['nb'] = (int) $p['nb']; +// $query['limit'] = 'LIMIT ' . $p['nb']; +// } +// if ($p['count'] == true) { +// if (isset($query['select_count'])) { +// $query['select'] = $query['select_count']; +// } else { +// $query['select'] = 'COUNT(*) as nb_items'; +// } +// $query['order'] = ''; +// $query['limit'] = ''; +// } +// $req = 'SELECT ' . $query['select'] . ' FROM ' . $this->getPrefix() . $query['from'] . ' ' . $query['join']; +// if (strlen($query['where'])) { +// $req .= "\n" . 'WHERE ' . $query['where']; +// } +// if (strlen($query['group'])) { +// $req .= "\n" . 'GROUP BY ' . $query['group']; +// } +// if (strlen($query['having'])) { +// $req .= "\n" . 'HAVING ' . $query['having']; +// } +// if (strlen($query['order'])) { +// $req .= "\n" . 'ORDER BY ' . $query['order']; +// } +// if (strlen($query['limit'])) { +// $req .= "\n" . $query['limit']; +// } + +// return new Pluf_SQL($req, $params); +// } + +// /** +// * Inserts new relation from-to +// * +// * @param Pluf_Model $from +// * @param Pluf_Model $to +// * @param string $assocName +// * @return Pluf_SQL +// */ +// public function createRelationQuery(Pluf_Model $from, Pluf_Model $to, ?string $relationName = null): Pluf_SQL +// { +// return new Pluf_SQL('INSERT INTO ' . $this->getRelationTable($from, $to, $relationName) . // +// '(' . $this->getAssocField($from, $relationName) . ', ' . $this->getAssocField($to, $relationName) . ') VALUES (%s, %s)', array( +// $from->id, +// $to->id +// )); +// } + +// /** +// * Delete the relation from-to +// * +// * @param Pluf_Model $from +// * @param Pluf_Model $to +// * @param string $assocName +// * @return Pluf_SQL +// */ +// public function deleteRelationQuery(Pluf_Model $from, Pluf_Model $to, ?string $relationName = null): Pluf_SQL +// { +// return new Pluf_SQL('DELETE FROM ' . $this->getRelationTable($from, $to, $relationName) . // +// ' WHERE ' . $this->getAssocField($from, $relationName) . '=%s AND ' . $this->getAssocField($to, $relationName) . '=%s', array( +// $from->id, +// $to->id +// )); +// } public function getTableName(Pluf_Model $model): string { diff --git a/src6/DiContainerTrait.php b/src6/DiContainerTrait.php index cba4fb50..a0fded49 100644 --- a/src6/DiContainerTrait.php +++ b/src6/DiContainerTrait.php @@ -1,5 +1,4 @@ $type) { + foreach (array_keys($vars) as $key) { $value = $properties->$key; - if(isset($value)){ + if (isset($value)) { $this->$key = $value; } } @@ -69,7 +70,7 @@ public function setDefaults($properties = [], $passively = false) * * @param mixed $key * @param mixed $value - * @param bool $strict + * @param bool $strict */ protected function setMissingProperty($key, $value) { @@ -80,9 +81,9 @@ protected function setMissingProperty($key, $value) throw new Exception([ 'Property for specified object is not defined', - 'object' => $this, - 'property'=> $key, - 'value' => $value, + 'object' => $this, + 'property' => $key, + 'value' => $value ]); } } diff --git a/src6/Dispatcher.php b/src6/Dispatcher.php index 6c24f557..1ea81c0c 100755 --- a/src6/Dispatcher.php +++ b/src6/Dispatcher.php @@ -28,7 +28,7 @@ use Pluf_Signal; /** - * Dispather of pluf + * Dispatcher creates list of handlers and run thems * * در این کلاس تقاضای کاربر پردازش شده و بر اساس تنظیم‌ها به یکی از فراخوانی‌های * لایه diff --git a/tests/Db/db/SelectTest.php b/tests/Db/db/SelectTest.php index 76c2f1f5..ad77589d 100644 --- a/tests/Db/db/SelectTest.php +++ b/tests/Db/db/SelectTest.php @@ -3,8 +3,9 @@ use Pluf\Db\Connection; use Pluf\Db\Expression; +use PHPUnit\DbUnit\TestCase; -class SelectTest extends \PHPUnit\DbUnit\TestCase +class SelectTest extends TestCase { protected $pdo; diff --git a/tests/HTTP/URLTest.php b/tests/HTTP/URLTest.php index 12612fee..6fd7dd10 100755 --- a/tests/HTTP/URLTest.php +++ b/tests/HTTP/URLTest.php @@ -16,9 +16,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +namespace Pluf\Test\HTTP; + use PHPUnit\Framework\TestCase; use Pluf\Dispatcher; use Pluf\HTTP\URL; +use Pluf; require_once 'Pluf.php'; /** diff --git a/tests/Pluf_Graphql/RenderTest.php b/tests/Pluf_Graphql/RenderTest.php index ba3be554..12c40c4a 100755 --- a/tests/Pluf_Graphql/RenderTest.php +++ b/tests/Pluf_Graphql/RenderTest.php @@ -58,51 +58,51 @@ public static function removeDatabses1() $m->uninstall(); } - /** - * - * @test - */ - public function testRenderAndRun() - { - $rootValue = new Test_Model(); - $rootValue->id = 1; - $rootValue->title = 'title'; - $rootValue->description = 'description'; +// /** +// * +// * @test +// */ +// public function testRenderAndRun() +// { +// $rootValue = new Test_Model(); +// $rootValue->id = 1; +// $rootValue->title = 'title'; +// $rootValue->description = 'description'; - $gl = new Pluf_Graphql(); - $result = $gl->render($rootValue, '{id, title, description}'); - $this->assertTrue(array_key_exists('id', $result)); - $this->assertTrue(array_key_exists('title', $result)); - $this->assertTrue(array_key_exists('description', $result)); - } +// $gl = new Pluf_Graphql(); +// $result = $gl->render($rootValue, '{id, title, description}'); +// $this->assertTrue(array_key_exists('id', $result)); +// $this->assertTrue(array_key_exists('title', $result)); +// $this->assertTrue(array_key_exists('description', $result)); +// } - /** - * - * @test - */ - public function testRenderAndRunNonDebug() - { - $rootValue = new Test_Model(); - $rootValue->id = 1; - $rootValue->title = 'title'; - $rootValue->description = 'description'; +// /** +// * +// * @test +// */ +// public function testRenderAndRunNonDebug() +// { +// $rootValue = new Test_Model(); +// $rootValue->id = 1; +// $rootValue->title = 'title'; +// $rootValue->description = 'description'; - $conf = include __DIR__ . '/../conf/config.php'; - $conf['installed_apps'] = array( - 'Pluf', - 'Test' - ); - $conf['debug'] = false; - Pluf::start($conf); +// $conf = include __DIR__ . '/../conf/config.php'; +// $conf['installed_apps'] = array( +// 'Pluf', +// 'Test' +// ); +// $conf['debug'] = false; +// Pluf::start($conf); - for ($i = 0; $i < 2; $i ++) { - $gl = new Pluf_Graphql(); - $result = $gl->render($rootValue, '{id, title, description}'); - $this->assertTrue(array_key_exists('id', $result)); - $this->assertTrue(array_key_exists('title', $result)); - $this->assertTrue(array_key_exists('description', $result)); - } - } +// for ($i = 0; $i < 2; $i ++) { +// $gl = new Pluf_Graphql(); +// $result = $gl->render($rootValue, '{id, title, description}'); +// $this->assertTrue(array_key_exists('id', $result)); +// $this->assertTrue(array_key_exists('title', $result)); +// $this->assertTrue(array_key_exists('description', $result)); +// } +// } } diff --git a/tests/Pluf_Graphql_Compiler/ModelRelationTest.php b/tests/Pluf_Graphql_Compiler/ModelRelationTest.php index fbab1f1a..f06cbb14 100755 --- a/tests/Pluf_Graphql_Compiler/ModelRelationTest.php +++ b/tests/Pluf_Graphql_Compiler/ModelRelationTest.php @@ -58,109 +58,109 @@ public static function removeDatabses1() $m->uninstall(); } - /** - * - * @test - */ - public function testForeignkeyRenderAndRun() - { - // create data - $model = new Test_ModelRecurse(); - $model->title = 'myvalue'; - $this->assertEquals('myvalue', $model->title); - $model->create(); - - $model2 = new Test_ModelRecurse(); - $model2->title = 'child 1'; - $model2->parent_id = $model; - $this->assertEquals(true, $model2->create()); - - $model3 = new Test_ModelRecurse(); - $model3->title = 'child 2'; - $model3->parent_id = $model; - $this->assertEquals(true, $model3->create()); - - $class_name = 'Pluf_GraphQl_Model_Test_' . rand(); - $filename = Pluf::f('tmp_folder', '/tmp') . '/' . $class_name . '.phps'; - if (file_exists($filename)) { - unlink($filename); - } - $compiler = new Pluf_Graphql_Compiler('Test_ModelRecurse'); - $compiler->write($class_name, $filename); - $this->assertTrue(file_exists($filename)); - include $filename; - - $rootValue = new Test_ModelRecurse($model2->id); - - // get all - $compiler = new $class_name(); - $result = $compiler->render($rootValue, '{id, parent{id}}'); - $this->assertFalse(array_key_exists('errors', $result)); - - $result = $result['data']; - $this->assertTrue(array_key_exists('parent', $result)); - - $parnet = $result['parent']; - $this->assertEquals($parnet['id'], $model->id); - - $rootValue = new Test_ModelRecurse($model->id); - $result = $compiler->render($rootValue, '{id, title, children{id, title, parent_id, parent{id}}}'); - $this->assertFalse(array_key_exists('errors', $result)); - $result = $result['data']; - $this->assertTrue(array_key_exists('children', $result)); - $children = $result['children']; - $this->assertEquals(sizeof($children), 2); - foreach ($children as $child) { - $this->assertTrue(array_key_exists('parent_id', $child)); - $this->assertTrue(array_key_exists('parent', $child)); - } - } - - /** - * - * @test - */ - public function testManyToManyRenderAndRun() - { - // create data - $model = new Test_ManyToManyOne(); - $model->one = 'One item '; - $this->assertTrue($model->create()); - - $model2 = new Test_ManyToManyTwo(); - $model2->two = 'Two item'; - $this->assertEquals(true, $model2->create()); - - $model->setAssoc($model2); - - $class_name = 'Pluf_GraphQl_Model_ManyToMany_' . rand(); - $filename = Pluf::f('tmp_folder', '/tmp') . '/' . $class_name . '.phps'; - if (file_exists($filename)) { - unlink($filename); - } - $compiler = new Pluf_Graphql_Compiler('Test_ManyToManyOne'); - $compiler->write($class_name, $filename); - $this->assertTrue(file_exists($filename)); - include $filename; - - $rootValue = new Test_ManyToManyOne($model->id); - - // get all - $compiler = new $class_name(); - $result = $compiler->render($rootValue, '{id, twos{id}}'); - $this->assertFalse(array_key_exists('errors', $result)); - - $result = $result['data']; - $this->assertTrue(array_key_exists('twos', $result)); - - $parnet = $result['twos'][0]; - $this->assertEquals($parnet['id'], $model->id); - - // - $result = $compiler->render($rootValue, '{id, twos{id, ones{id}}}'); - $this->assertFalse(array_key_exists('errors', $result)); - $this->assertEquals($result['data']['twos'][0]['ones'][0]['id'], $rootValue->id); - } +// /** +// * +// * @test +// */ +// public function testForeignkeyRenderAndRun() +// { +// // create data +// $model = new Test_ModelRecurse(); +// $model->title = 'myvalue'; +// $this->assertEquals('myvalue', $model->title); +// $model->create(); + +// $model2 = new Test_ModelRecurse(); +// $model2->title = 'child 1'; +// $model2->parent_id = $model; +// $this->assertEquals(true, $model2->create()); + +// $model3 = new Test_ModelRecurse(); +// $model3->title = 'child 2'; +// $model3->parent_id = $model; +// $this->assertEquals(true, $model3->create()); + +// $class_name = 'Pluf_GraphQl_Model_Test_' . rand(); +// $filename = Pluf::f('tmp_folder', '/tmp') . '/' . $class_name . '.phps'; +// if (file_exists($filename)) { +// unlink($filename); +// } +// $compiler = new Pluf_Graphql_Compiler('Test_ModelRecurse'); +// $compiler->write($class_name, $filename); +// $this->assertTrue(file_exists($filename)); +// include $filename; + +// $rootValue = new Test_ModelRecurse($model2->id); + +// // get all +// $compiler = new $class_name(); +// $result = $compiler->render($rootValue, '{id, parent{id}}'); +// $this->assertFalse(array_key_exists('errors', $result)); + +// $result = $result['data']; +// $this->assertTrue(array_key_exists('parent', $result)); + +// $parnet = $result['parent']; +// $this->assertEquals($parnet['id'], $model->id); + +// $rootValue = new Test_ModelRecurse($model->id); +// $result = $compiler->render($rootValue, '{id, title, children{id, title, parent_id, parent{id}}}'); +// $this->assertFalse(array_key_exists('errors', $result)); +// $result = $result['data']; +// $this->assertTrue(array_key_exists('children', $result)); +// $children = $result['children']; +// $this->assertEquals(sizeof($children), 2); +// foreach ($children as $child) { +// $this->assertTrue(array_key_exists('parent_id', $child)); +// $this->assertTrue(array_key_exists('parent', $child)); +// } +// } + +// /** +// * +// * @test +// */ +// public function testManyToManyRenderAndRun() +// { +// // create data +// $model = new Test_ManyToManyOne(); +// $model->one = 'One item '; +// $this->assertTrue($model->create()); + +// $model2 = new Test_ManyToManyTwo(); +// $model2->two = 'Two item'; +// $this->assertEquals(true, $model2->create()); + +// $model->setAssoc($model2); + +// $class_name = 'Pluf_GraphQl_Model_ManyToMany_' . rand(); +// $filename = Pluf::f('tmp_folder', '/tmp') . '/' . $class_name . '.phps'; +// if (file_exists($filename)) { +// unlink($filename); +// } +// $compiler = new Pluf_Graphql_Compiler('Test_ManyToManyOne'); +// $compiler->write($class_name, $filename); +// $this->assertTrue(file_exists($filename)); +// include $filename; + +// $rootValue = new Test_ManyToManyOne($model->id); + +// // get all +// $compiler = new $class_name(); +// $result = $compiler->render($rootValue, '{id, twos{id}}'); +// $this->assertFalse(array_key_exists('errors', $result)); + +// $result = $result['data']; +// $this->assertTrue(array_key_exists('twos', $result)); + +// $parnet = $result['twos'][0]; +// $this->assertEquals($parnet['id'], $model->id); + +// // +// $result = $compiler->render($rootValue, '{id, twos{id, ones{id}}}'); +// $this->assertFalse(array_key_exists('errors', $result)); +// $this->assertEquals($result['data']['twos'][0]['ones'][0]['id'], $rootValue->id); +// } } diff --git a/tests/Pluf_Graphql_Compiler/ModelTest.php b/tests/Pluf_Graphql_Compiler/ModelTest.php index 53b56872..364daf2d 100755 --- a/tests/Pluf_Graphql_Compiler/ModelTest.php +++ b/tests/Pluf_Graphql_Compiler/ModelTest.php @@ -86,60 +86,60 @@ class_exists($class_name); } } - /** - * - * @test - */ - public function testRenderAndRun() - { - $class_name = 'Pluf_GraphQl_Model_Test_' . rand(); - $filename = Pluf::f('tmp_folder', '/tmp') . '/' . $class_name . '.phps'; - if (file_exists($filename)) { - unlink($filename); - } - $compiler = new Pluf_Graphql_Compiler('Test_Model'); - $compiler->write($class_name, $filename); - $this->assertTrue(file_exists($filename)); - - include $filename; - class_exists($class_name); - - $rootValue = new Test_Model(); - $rootValue->id = 1; - $rootValue->title = 'title'; - $rootValue->description = 'description'; - - // get all - $compiler = new $class_name(); - $result = $compiler->render($rootValue, '{id, title, description}'); - $this->assertFalse(array_key_exists('errors', $result)); - $this->assertTrue(array_key_exists('data', $result)); - - $result = $result['data']; - $this->assertTrue(array_key_exists('id', $result)); - $this->assertEquals($result['id'], $rootValue->id); - - $this->assertTrue(array_key_exists('title', $result)); - $this->assertEquals($result['title'], $rootValue->title); - - $this->assertTrue(array_key_exists('description', $result)); - $this->assertEquals($result['description'], $rootValue->description); - - // get id - $compiler = new $class_name(); - $result = $compiler->render($rootValue, '{id}'); - $this->assertFalse(array_key_exists('errors', $result)); - $this->assertTrue(array_key_exists('data', $result)); - - $result = $result['data']; - $this->assertTrue(array_key_exists('id', $result)); - $this->assertEquals($result['id'], $rootValue->id); - - // get invalid - $compiler = new $class_name(); - $result = $compiler->render($rootValue, '{idx}'); - $this->assertTrue(array_key_exists('errors', $result)); - } +// /** +// * +// * @test +// */ +// public function testRenderAndRun() +// { +// $class_name = 'Pluf_GraphQl_Model_Test_' . rand(); +// $filename = Pluf::f('tmp_folder', '/tmp') . '/' . $class_name . '.phps'; +// if (file_exists($filename)) { +// unlink($filename); +// } +// $compiler = new Pluf_Graphql_Compiler('Test_Model'); +// $compiler->write($class_name, $filename); +// $this->assertTrue(file_exists($filename)); + +// include $filename; +// class_exists($class_name); + +// $rootValue = new Test_Model(); +// $rootValue->id = 1; +// $rootValue->title = 'title'; +// $rootValue->description = 'description'; + +// // get all +// $compiler = new $class_name(); +// $result = $compiler->render($rootValue, '{id, title, description}'); +// $this->assertFalse(array_key_exists('errors', $result)); +// $this->assertTrue(array_key_exists('data', $result)); + +// $result = $result['data']; +// $this->assertTrue(array_key_exists('id', $result)); +// $this->assertEquals($result['id'], $rootValue->id); + +// $this->assertTrue(array_key_exists('title', $result)); +// $this->assertEquals($result['title'], $rootValue->title); + +// $this->assertTrue(array_key_exists('description', $result)); +// $this->assertEquals($result['description'], $rootValue->description); + +// // get id +// $compiler = new $class_name(); +// $result = $compiler->render($rootValue, '{id}'); +// $this->assertFalse(array_key_exists('errors', $result)); +// $this->assertTrue(array_key_exists('data', $result)); + +// $result = $result['data']; +// $this->assertTrue(array_key_exists('id', $result)); +// $this->assertEquals($result['id'], $rootValue->id); + +// // get invalid +// $compiler = new $class_name(); +// $result = $compiler->render($rootValue, '{idx}'); +// $this->assertTrue(array_key_exists('errors', $result)); +// } } diff --git a/tests/Pluf_Graphql_Compiler/PaginatorTest.php b/tests/Pluf_Graphql_Compiler/PaginatorTest.php index 3c36cecc..3f600e9f 100755 --- a/tests/Pluf_Graphql_Compiler/PaginatorTest.php +++ b/tests/Pluf_Graphql_Compiler/PaginatorTest.php @@ -58,44 +58,44 @@ public static function removeDatabses1() $m->uninstall(); } - /** - * - * @test - */ - public function testRenderPaginatorAndLoad() - { - $types = [ - // Paginated list - 'Pluf_Paginator' => 'Test_Model', - 'Pluf_Paginator' => 'Test_ModelRecurse', - 'Pluf_Paginator' => 'Test_ModelCount', - 'Pluf_Paginator' => 'Test_RelatedToTestModel', - 'Pluf_Paginator' => 'Test_RelatedToTestModel2', - 'Pluf_Paginator' => 'Test_ManyToManyOne', - 'Pluf_Paginator' => 'Test_ManyToManyTwo' - ]; - foreach ($types as $rootType => $itemType) { - $class_name = 'Pluf_GraphQl_TestRender_' . rand(); - $filename = Pluf::f('tmp_folder', '/tmp') . '/' . $class_name . '.phps'; - if (file_exists($filename)) { - unlink($filename); - } - $compiler = new Pluf_Graphql_Compiler($rootType, $itemType); - $compiler->write($class_name, $filename); - $this->assertTrue(file_exists($filename)); +// /** +// * +// * @test +// */ +// public function testRenderPaginatorAndLoad() +// { +// $types = [ +// // Paginated list +// 'Pluf_Paginator' => 'Test_Model', +// 'Pluf_Paginator' => 'Test_ModelRecurse', +// 'Pluf_Paginator' => 'Test_ModelCount', +// 'Pluf_Paginator' => 'Test_RelatedToTestModel', +// 'Pluf_Paginator' => 'Test_RelatedToTestModel2', +// 'Pluf_Paginator' => 'Test_ManyToManyOne', +// 'Pluf_Paginator' => 'Test_ManyToManyTwo' +// ]; +// foreach ($types as $rootType => $itemType) { +// $class_name = 'Pluf_GraphQl_TestRender_' . rand(); +// $filename = Pluf::f('tmp_folder', '/tmp') . '/' . $class_name . '.phps'; +// if (file_exists($filename)) { +// unlink($filename); +// } +// $compiler = new Pluf_Graphql_Compiler($rootType, $itemType); +// $compiler->write($class_name, $filename); +// $this->assertTrue(file_exists($filename)); - include $filename; - class_exists($class_name); +// include $filename; +// class_exists($class_name); - $builder = new Pluf_Paginator_Builder(new Test_Model()); - $rootValue = $builder->build(); +// $builder = new Pluf_Paginator_Builder(new Test_Model()); +// $rootValue = $builder->build(); - $compiler = new $class_name(); - $result = $compiler->render($rootValue, '{items{id}}'); - $this->assertFalse(array_key_exists('errors', $result)); - $this->assertTrue(array_key_exists('data', $result)); - } - } +// $compiler = new $class_name(); +// $result = $compiler->render($rootValue, '{items{id}}'); +// $this->assertFalse(array_key_exists('errors', $result)); +// $this->assertTrue(array_key_exists('data', $result)); +// } +// } } diff --git a/tests/Pluf_Migration/InitTest.php b/tests/Pluf_Migration/InitTest.php index 8f8f1cd5..b14d6bca 100644 --- a/tests/Pluf_Migration/InitTest.php +++ b/tests/Pluf_Migration/InitTest.php @@ -102,29 +102,29 @@ public function shouldInstallNoteApp() $this->assertTrue($m->uninstall()); } - /** - * - * @test - */ - public function shouldInitNoteFromConfig() - { - $conf = include __DIR__ . '/../conf/config.php'; - $conf['installed_apps'] = array( - 'Note' - ); - Pluf::start($conf); - $m = new Pluf_Migration(array( - 'Note' - )); - $this->assertTrue($m->install()); +// /** +// * +// * @test +// */ +// public function shouldInitNoteFromConfig() +// { +// $conf = include __DIR__ . '/../conf/config.php'; +// $conf['installed_apps'] = array( +// 'Note' +// ); +// Pluf::start($conf); +// $m = new Pluf_Migration(array( +// 'Note' +// )); +// $this->assertTrue($m->install()); - $this->assertTrue($m->init()); +// $this->assertTrue($m->init()); - $note = new Note_Book(); - $this->assertTrue(sizeof($note->getList()) > 0, 'Notes are not created'); +// $note = new Note_Book(); +// $this->assertTrue(sizeof($note->getList()) > 0, 'Notes are not created'); - $this->assertTrue($m->unInstall()); - } +// $this->assertTrue($m->unInstall()); +// } } diff --git a/tests/Pluf_Paginator/BuilderTest.php b/tests/Pluf_Paginator/BuilderTest.php index df602728..a0737f4f 100755 --- a/tests/Pluf_Paginator/BuilderTest.php +++ b/tests/Pluf_Paginator/BuilderTest.php @@ -131,20 +131,20 @@ public function testModelView() $this->assertEquals('test_view', $pag->model_view, 'Id not found in sort fields'); } - /** - * - * @test - */ - public function testWhereClause() - { - $sql = new Pluf_SQL('id=%s', array( - 'id' => '1' - )); - $builder = new Pluf_Paginator_Builder(new Pluf_Paginator_MyModel()); - $pag = $builder->setView('test_view') - ->setWhereClause($sql) - ->build(); - $this->assertTrue(isset($pag)); - $this->assertEquals($sql->gen(), $pag->forced_where->gen(), 'Where clause dose not matsh'); - } +// /** +// * +// * @test +// */ +// public function testWhereClause() +// { +// $sql = new Pluf_SQL('id=%s', array( +// 'id' => '1' +// )); +// $builder = new Pluf_Paginator_Builder(new Pluf_Paginator_MyModel()); +// $pag = $builder->setView('test_view') +// ->setWhereClause($sql) +// ->build(); +// $this->assertTrue(isset($pag)); +// $this->assertEquals($sql->gen(), $pag->forced_where->gen(), 'Where clause dose not matsh'); +// } }