Skip to content

Commit e0f5495

Browse files
committed
Upd. Code. Unit tests for DbColumnCreator::updateIndexes updated #2.
1 parent 349cfdc commit e0f5495

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/ApbctWP/UpdatePlugin/TestDbColumnCreator.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,33 @@ public function testFallbackIndexCreationFromColumnName()
179179
$this->assertEquals(['status'], $actualIndexes['status']);
180180
}
181181

182+
/**
183+
* Test when index name is different from column name but column exists
184+
*/
185+
public function testCustomIndexNameWithExistingColumn()
186+
{
187+
// Arrange: create a test table
188+
$tableName = self::$tablePrefix . 'test_custom_index';
189+
$this->createTestTableForFallback($tableName);
190+
191+
// Schema with custom index name (different from column)
192+
$schemaIndexes = ['my_custom_status_idx']; // Custom name, not column name
193+
194+
$dbColumnNames = ['id', 'status', 'name'];
195+
196+
// Act
197+
$this->dbColumnCreator = new DbColumnCreator($tableName);
198+
$errors = $this->executeUpdateIndexes($schemaIndexes, $dbColumnNames);
199+
200+
// Assert: Should fail because 'my_custom_status_idx' is not a column name
201+
$this->assertNotEmpty($errors, "Should have error when index name doesn't match any column");
202+
$this->assertStringContainsString(
203+
"not found in schema definitions and column doesn't exist for fallback creation",
204+
$errors[0]
205+
);
206+
}
207+
208+
182209
/**
183210
* DataProvider: all tables from Schema
184211
*/
@@ -352,6 +379,22 @@ protected function tearDown(): void
352379
$wpdb->query("DROP TABLE IF EXISTS `{$tableName}`");
353380
}
354381

382+
// Clean up all test tables
383+
$testTables = [
384+
'test_fallback',
385+
'test_fallback_error',
386+
'test_array_names',
387+
'test_mixed',
388+
'test_custom_index',
389+
'test_no_definition',
390+
'test_column_no_def',
391+
'test_similar'
392+
];
393+
foreach ($testTables as $testTable) {
394+
$tableName = self::$tablePrefix . $testTable;
395+
$wpdb->query("DROP TABLE IF EXISTS `{$tableName}`");
396+
}
397+
355398
parent::tearDown();
356399
}
357400
}

0 commit comments

Comments
 (0)