[TASK] Increase test coverage of DatabaseConnection classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Database / PreparedStatementTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Database;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Database\DatabaseConnection;
18 use TYPO3\CMS\Core\Tests\FunctionalTestCase;
19
20 /**
21 * Test case for \TYPO3\CMS\Core\Database\PreparedStatement
22 */
23 class PreparedStatementTest extends FunctionalTestCase
24 {
25 /**
26 * @var DatabaseConnection
27 */
28 protected $subject = null;
29
30 /**
31 * @var string
32 */
33 protected $testTable = 'test_database_connection';
34
35 /**
36 * @var string
37 */
38 protected $testField = 'test_field';
39
40 /**
41 * @var string
42 */
43 protected $anotherTestField = 'another_test_field';
44
45 /**
46 * Set the test up
47 *
48 * @return void
49 */
50 protected function setUp()
51 {
52 parent::setUp();
53 $this->subject = $GLOBALS['TYPO3_DB'];
54 $this->subject->sql_query(
55 "CREATE TABLE {$this->testTable} (" .
56 ' id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,' .
57 " {$this->testField} MEDIUMBLOB," .
58 " {$this->anotherTestField} MEDIUMBLOB," .
59 ' PRIMARY KEY (id)' .
60 ') ENGINE=MyISAM DEFAULT CHARSET=utf8;'
61 );
62 }
63
64 /**
65 * Tear the test down
66 *
67 * @return void
68 */
69 protected function tearDown()
70 {
71 $this->subject->sql_query("DROP TABLE {$this->testTable};");
72 unset($this->subject);
73 }
74
75 /**
76 * @test
77 *
78 * @return void
79 */
80 public function prepareSelectQueryCreateValidQuery()
81 {
82 $this->assertTrue(
83 $this->subject->admin_query("INSERT INTO {$this->testTable} ({$this->testField}) VALUES ('aTestValue')")
84 );
85 $preparedQuery = $this->subject->prepare_SELECTquery(
86 "{$this->testField},{$this->anotherTestField}",
87 $this->testTable,
88 'id=:id',
89 '',
90 '',
91 '',
92 [':id' => 1]
93 );
94 $preparedQuery->execute();
95 $result = $preparedQuery->fetch();
96 $expectedResult = [
97 $this->testField => 'aTestValue',
98 $this->anotherTestField => null,
99 ];
100 $this->assertSame($expectedResult, $result);
101 }
102 }