Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin de Graaf committed Sep 28, 2017
2 parents 2393156 + 11be5b2 commit cb709fd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Parable PHP Framework Changelog

### 0.12.11

__Bugfixes__
- I can't believe nobody noticed this yet, but there was a bug in `\Parable\ORM\Query::buildOrderBy()`, where the key is actually escaped through `quote` rather than `quoteIdentifier`, leaving it as a quoted value rather than a key.
- Also `buildGroupBy()`, grmbl.

### 0.12.10

I'm cleaning up this file. All CHANGELOG entries older than the current 'major' pre-release version and the version before that have been moved to CHANGELOG-HISTORY.md.
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class App
protected $database;

/** @var string */
protected $version = '0.12.10';
protected $version = '0.12.11';

public function __construct(
\Parable\Filesystem\Path $path,
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ protected function buildOrderBy()

$orders = [];
foreach ($this->orderBy as $orderBy) {
$key = $this->quoteIdentifier($orderBy["tableName"]) . "." . $this->quote($orderBy["key"]);
$key = $this->quoteIdentifier($orderBy["tableName"]) . "." . $this->quoteIdentifier($orderBy["key"]);
$orders[] = $key . ' ' . $orderBy['direction'];
}
return "ORDER BY " . implode(', ', $orders);
Expand All @@ -527,7 +527,7 @@ protected function buildGroupBy()

$groups = [];
foreach ($this->groupBy as $groupBy) {
$groupBy = $this->quoteIdentifier($groupBy["tableName"]) . "." . $this->quote($groupBy["key"]);
$groupBy = $this->quoteIdentifier($groupBy["tableName"]) . "." . $this->quoteIdentifier($groupBy["key"]);
$groups[] = $groupBy;
}
return "GROUP BY " . implode(', ', $groups);
Expand Down
2 changes: 1 addition & 1 deletion structure/app/View/Home/index.phtml_struct
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
font-size: 4.15rem;
}
.container aside {
font-size: 0.78rem;
font-size: 0.73rem;
margin-top: -0.8rem;
letter-spacing: 5px;
margin-left: 3px;
Expand Down
16 changes: 8 additions & 8 deletions tests/Components/ORM/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ public function testOrderBy($key, $direction, $expected)
public function dpOrderBys()
{
return [
['id', \Parable\ORM\Query::ORDER_ASC, "SELECT * FROM `user` ORDER BY `user`.'id' ASC;"],
['id', \Parable\ORM\Query::ORDER_DESC, "SELECT * FROM `user` ORDER BY `user`.'id' DESC;"],
['id', \Parable\ORM\Query::ORDER_ASC, "SELECT * FROM `user` ORDER BY `user`.`id` ASC;"],
['id', \Parable\ORM\Query::ORDER_DESC, "SELECT * FROM `user` ORDER BY `user`.`id` DESC;"],
];
}

Expand All @@ -276,7 +276,7 @@ public function testMultipleOrderBys()
$this->query->orderBy("id", \Parable\ORM\Query::ORDER_DESC);
$this->query->orderBy("name", \Parable\ORM\Query::ORDER_ASC);
$this->assertSame(
"SELECT * FROM `user` ORDER BY `user`.'id' DESC, `user`.'name' ASC;",
"SELECT * FROM `user` ORDER BY `user`.`id` DESC, `user`.`name` ASC;",
(string)$this->query
);
}
Expand All @@ -286,29 +286,29 @@ public function testMultipleOrderBysFromDifferentTables()
$this->query->orderBy("id", \Parable\ORM\Query::ORDER_DESC);
$this->query->orderBy("name", \Parable\ORM\Query::ORDER_ASC, 'settings');
$this->assertSame(
"SELECT * FROM `user` ORDER BY `user`.'id' DESC, `settings`.'name' ASC;",
"SELECT * FROM `user` ORDER BY `user`.`id` DESC, `settings`.`name` ASC;",
(string)$this->query
);
}

public function testGroupBy()
{
$this->query->groupBy('name');
$this->assertSame("SELECT * FROM `user` GROUP BY `user`.'name';", (string)$this->query);
$this->assertSame("SELECT * FROM `user` GROUP BY `user`.`name`;", (string)$this->query);
}

public function testMultipleGroupBys()
{
$this->query->groupBy('name');
$this->query->groupBy('id');
$this->assertSame("SELECT * FROM `user` GROUP BY `user`.'name', `user`.'id';", (string)$this->query);
$this->assertSame("SELECT * FROM `user` GROUP BY `user`.`name`, `user`.`id`;", (string)$this->query);
}

public function testMultipleGroupBysFromDifferentTables()
{
$this->query->groupBy('name');
$this->query->groupBy('id', 'settings');
$this->assertSame("SELECT * FROM `user` GROUP BY `user`.'name', `settings`.'id';", (string)$this->query);
$this->assertSame("SELECT * FROM `user` GROUP BY `user`.`name`, `settings`.`id`;", (string)$this->query);
}

public function testLimitOffset()
Expand Down Expand Up @@ -358,7 +358,7 @@ public function testRidiculouslyComplexQuery()

// Understandably, this query is also ridiculously long
$this->assertSame(
"SELECT * FROM `complex` LEFT JOIN `settings` ON `settings`.`user_id` = `complex`.`id` WHERE (`complex`.`id` = '1' AND `complex`.`active` IS NOT NULL AND (`complex`.`id` != '1' OR `complex`.`active` IS NULL OR `complex`.`created_at` IN ('option1','option2'))) GROUP BY `complex`.'name', `settings`.'id' HAVING (`complex`.`id` != '1' AND `complex`.`active` IS NULL) ORDER BY `complex`.'id' DESC, `settings`.'name' ASC LIMIT 5;",
"SELECT * FROM `complex` LEFT JOIN `settings` ON `settings`.`user_id` = `complex`.`id` WHERE (`complex`.`id` = '1' AND `complex`.`active` IS NOT NULL AND (`complex`.`id` != '1' OR `complex`.`active` IS NULL OR `complex`.`created_at` IN ('option1','option2'))) GROUP BY `complex`.`name`, `settings`.`id` HAVING (`complex`.`id` != '1' AND `complex`.`active` IS NULL) ORDER BY `complex`.`id` DESC, `settings`.`name` ASC LIMIT 5;",
(string)$this->query
);
}
Expand Down

0 comments on commit cb709fd

Please sign in to comment.