1<?php 2 3namespace dokuwiki\plugin\struct\test; 4 5use dokuwiki\plugin\struct\meta\Search; 6 7/** 8 * Tests to the DB for the struct plugin 9 * 10 * @group plugin_struct 11 * @group plugins 12 * 13 */ 14class AccessTableDataDBMulti_struct_test extends StructTest 15{ 16 17 /** @var \helper_plugin_sqlite $sqlite */ 18 protected $sqlite; 19 20 public function setUp(): void 21 { 22 parent::setUp(); 23 24 /** @var \helper_plugin_struct_db $sqlite */ 25 $sqlite = plugin_load('helper', 'struct_db'); 26 $this->sqlite = $sqlite->getDB(); 27 28 $this->loadSchemaJSON('testtable', 'testtable2', 100); 29 30 // revision 1 31 $this->saveData( 32 'testpage', 33 'testtable', 34 array( 35 'testMulitColumn2' => array('value1.1', 'value1.2'), 36 'testMulitColumn' => array('value2.1', 'value2.2') 37 ), 38 123 39 ); 40 41 // revision 2 42 $this->saveData( 43 'testpage', 44 'testtable', 45 array( 46 'testMulitColumn2' => array('value1.1a', 'value1.2a'), 47 'testMulitColumn' => array('value2.1a', 'value2.2a') 48 ), 49 789 50 ); 51 52 // revision 1 of different page 53 $this->saveData( 54 'testpage2', 55 'testtable', 56 array( 57 'testMulitColumn2' => array('value1.1a'), 58 'testMulitColumn' => array('value2.1a') 59 ), 60 789 61 ); 62 63 // global data 64 $this->saveData( 65 '', 66 'testtable', 67 [ 68 'testMulitColumn2' => ['value1.1b', 'value1.2b'], 69 'testMulitColumn' => ['value2.1b', 'value2.2b'] 70 ], 71 0, 72 1 73 ); 74 } 75 76 public function test_getDataFromDB_currentRev() 77 { 78 79 // act 80 $schemaData = mock\AccessTable::getPageAccess('testtable', 'testpage'); 81 $actual_data = $schemaData->getDataFromDB(); 82 83 $expected_data = array( 84 array( 85 'out1' => 'value1.1a' . Search::CONCAT_SEPARATOR . 'value1.2a', 86 'out2' => 'value2.1a' . Search::CONCAT_SEPARATOR . 'value2.2a', 87 'PID' => 'testpage', 88 ), 89 ); 90 91 $this->assertEquals($expected_data, $actual_data, ''); 92 } 93 94 public function test_getDataFromDB_deleteMultiPage() 95 { 96 97 $this->saveData( 98 'testpage', 99 'testtable', 100 [ 101 'testMulitColumn2' => '', 102 'testMulitColumn' => ['value2.1a'], 103 ] 104 ); 105 106 $expected = [ 107 [ 108 'out1' => 'value1.1a' . Search::CONCAT_SEPARATOR . 'value1.2a', 109 'out2' => 'value2.1a' . Search::CONCAT_SEPARATOR . 'value2.2a', 110 'PID' => 'testpage', 111 ], 112 ]; 113 114 $access = mock\AccessTable::getPageAccess('testtable', 'testpage'); 115 $actual = $access->getDataFromDB(); 116 117 $this->assertEquals($expected, $actual); 118 } 119 120 public function test_getDataFromDB_deleteMultiGlobal() 121 { 122 123 $this->saveData( 124 '', 125 'testtable', 126 [ 127 'testMulitColumn2' => ['value1.1c', 'value1.2c'], 128 'testMulitColumn' => [''] 129 ], 130 0, 131 1 132 ); 133 134 $expected = [ 135 [ 136 'out1' => 'value1.1c' . Search::CONCAT_SEPARATOR . 'value1.2c', 137 'out2' => '', 138 'RID' => '1', 139 ], 140 ]; 141 142 $access = mock\AccessTable::getGlobalAccess('testtable', 1); 143 $actual = $access->getDataFromDB(); 144 145 $this->assertEquals($expected, $actual); 146 147 } 148} 149