| Conditions | 6 |
| Paths | 4 |
| Total Lines | 38 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | protected $usesDatabase = true; |
||
| 17 | |||
| 18 | public function testReadOnlyTransaction() |
||
| 19 | { |
||
| 20 | if (DB::get_conn()->supportsTransactions() == true |
||
|
|
|||
| 21 | && DB::get_conn() instanceof PostgreSQLDatabase |
||
| 22 | ) { |
||
| 23 | $page=new Page(); |
||
| 24 | $page->Title='Read only success'; |
||
| 25 | $page->write(); |
||
| 26 | |||
| 27 | DB::get_conn()->transactionStart('READ ONLY'); |
||
| 28 | |||
| 29 | try { |
||
| 30 | $page=new Page(); |
||
| 31 | $page->Title='Read only page failed'; |
||
| 32 | $page->write(); |
||
| 33 | } catch (Exception $e) { |
||
| 34 | //could not write this record |
||
| 35 | //We need to do a rollback or a commit otherwise we'll get error messages |
||
| 36 | DB::get_conn()->transactionRollback(); |
||
| 37 | } |
||
| 38 | |||
| 39 | DB::get_conn()->transactionEnd(); |
||
| 40 | |||
| 41 | DataObject::flush_and_destroy_cache(); |
||
| 42 | |||
| 43 | $success=DataObject::get('Page', "\"Title\"='Read only success'"); |
||
| 44 | $fail=DataObject::get('Page', "\"Title\"='Read only page failed'"); |
||
| 45 | |||
| 46 | //This page should be in the system |
||
| 47 | $this->assertTrue(is_object($success) && $success->exists()); |
||
| 48 | |||
| 49 | //This page should NOT exist, we had 'read only' permissions |
||
| 50 | $this->assertFalse(is_object($fail) && $fail->exists()); |
||
| 51 | } else { |
||
| 52 | $this->markTestSkipped('Current database is not PostgreSQL'); |
||
| 53 | } |
||
| 54 | } |
||
| 56 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.