More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Database / OrderByTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Database;
4
5 use Drupal\Core\Database\Query\Select;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * Tests the orderBy() method of select queries.
10  *
11  * @group Database
12  */
13 class OrderByTest extends UnitTestCase {
14
15   /**
16    * The select query object to test.
17    *
18    * @var \Drupal\Core\Database\Query\Select
19    */
20   protected $query;
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     $connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
27       ->disableOriginalConstructor()
28       ->getMockForAbstractClass();
29     $this->query = new Select('test', NULL, $connection);
30   }
31
32   /**
33    * Checks that invalid sort directions in ORDER BY get converted to ASC.
34    */
35   public function testInvalidDirection() {
36     $this->query->orderBy('test', 'invalid direction');
37     $order_bys = $this->query->getOrderBy();
38     $this->assertEquals($order_bys['test'], 'ASC', 'Invalid order by direction is converted to ASC.');
39   }
40
41   /**
42    * Tests that fields passed for ordering get escaped properly.
43    */
44   public function testFieldEscaping() {
45     $this->query->orderBy('x; DROP table node; --');
46     $sql = $this->query->__toString();
47     $this->assertStringEndsWith('ORDER BY xDROPtablenode ASC', $sql, 'Order by field is escaped correctly.');
48   }
49
50 }