@@ -1538,6 +1538,141 @@ final class StorageTypeExtensionsTests: XCTestCase {
15381538 XCTAssertNil ( foundPlugin)
15391539 }
15401540
1541+ // MARK: - `loadSystemPlugin(siteID:fileNameWithoutExtension:)`
1542+
1543+ func test_loadSystemPlugin_by_fileNameWithoutExtension_returns_matching_plugin_when_two_plugins_in_storage( ) throws {
1544+ // Given
1545+ let systemPlugin1 = storage. insertNewObject ( ofType: SystemPlugin . self)
1546+ systemPlugin1. plugin = " woocommerce-payments/woocommerce-payments.php "
1547+ systemPlugin1. siteID = sampleSiteID
1548+
1549+ let systemPlugin2 = storage. insertNewObject ( ofType: SystemPlugin . self)
1550+ systemPlugin2. plugin = " test-plugin/woocommerce-gift-cards.php "
1551+ systemPlugin2. siteID = sampleSiteID
1552+
1553+ // When
1554+ let foundSystemPlugin = try XCTUnwrap ( storage. loadSystemPlugin ( siteID: sampleSiteID, fileNameWithoutExtension: " woocommerce-gift-cards " ) )
1555+
1556+ // Then
1557+ XCTAssertEqual ( foundSystemPlugin, systemPlugin2)
1558+ }
1559+
1560+ func test_loadSystemPlugin_by_fileNameWithoutExtension_returns_matching_plugin_when_plugin_path_is_in_different_valid_formats( ) throws {
1561+ let validPluginPaths = [
1562+ " woocommerce/woocommerce.php " ,
1563+ " woocommerce/woocommerce.swift " ,
1564+ " woocommerce//woocommerce.php " ,
1565+ " test-plugin/test-plugin/woocommerce.php " ,
1566+ " test-plugin/test-plugin/test-plugin/woocommerce.tmp.php " ,
1567+ " test-plugin/test-plugin/woocommerce.tmp.php " ,
1568+ " test-plugin/woocommerce.tmp.php " ,
1569+ " /woocommerce.tmp.php "
1570+ ]
1571+
1572+ for pluginPath in validPluginPaths {
1573+ // Given
1574+ let plugin = storage. insertNewObject ( ofType: SystemPlugin . self)
1575+ plugin. plugin = pluginPath
1576+ plugin. siteID = sampleSiteID
1577+
1578+ // When
1579+ let foundPlugin = try XCTUnwrap ( storage. loadSystemPlugin ( siteID: sampleSiteID, fileNameWithoutExtension: " woocommerce " ) )
1580+
1581+ // Then
1582+ XCTAssertEqual ( foundPlugin, plugin)
1583+
1584+ // Cleanup for next iteration
1585+ storage. deleteObject ( plugin)
1586+ }
1587+ }
1588+
1589+ func test_loadSystemPlugin_by_fileNameWithoutExtension_returns_nil_when_plugin_path_is_in_different_invalid_formats( ) throws {
1590+ let invalidPluginPaths = [
1591+ " woocommerce/woocommerce " ,
1592+ " woocommerce/woocommerce-dev.php " ,
1593+ " test-plugin/woocommerce-dev.php " ,
1594+ " test-plugin/test-plugin/woocommerce-dev.php " ,
1595+ " woocommerce.tmp.php "
1596+ ]
1597+
1598+ for pluginPath in invalidPluginPaths {
1599+ // Given
1600+ let plugin = storage. insertNewObject ( ofType: SystemPlugin . self)
1601+ plugin. plugin = pluginPath
1602+ plugin. siteID = sampleSiteID
1603+
1604+ // When
1605+ let foundPlugin = storage. loadSystemPlugin ( siteID: sampleSiteID, fileNameWithoutExtension: " woocommerce " )
1606+
1607+ // Then
1608+ XCTAssertNil ( foundPlugin)
1609+
1610+ // Cleanup for next iteration
1611+ storage. deleteObject ( plugin)
1612+ }
1613+ }
1614+
1615+ func test_loadSystemPlugin_by_fileNameWithoutExtension_returns_matching_plugin_when_active_state_is_set( ) throws {
1616+ // Given
1617+ let inactivePlugin = storage. insertNewObject ( ofType: SystemPlugin . self)
1618+ inactivePlugin. plugin = " test-plugin/woocommerce.php "
1619+ inactivePlugin. siteID = sampleSiteID
1620+ inactivePlugin. active = false
1621+
1622+ let activePlugin = storage. insertNewObject ( ofType: SystemPlugin . self)
1623+ activePlugin. plugin = " woocommerce/woocommerce.php "
1624+ activePlugin. siteID = sampleSiteID
1625+ activePlugin. active = true
1626+
1627+ // When
1628+ let foundActivePlugin = try XCTUnwrap ( storage. loadSystemPlugin ( siteID: sampleSiteID, fileNameWithoutExtension: " woocommerce " , active: true ) )
1629+
1630+ // Then
1631+ XCTAssertEqual ( foundActivePlugin, activePlugin)
1632+
1633+ // When
1634+ let foundInactivePlugin = try XCTUnwrap ( storage. loadSystemPlugin ( siteID: sampleSiteID, fileNameWithoutExtension: " woocommerce " , active: false ) )
1635+
1636+ // Then
1637+ XCTAssertEqual ( foundInactivePlugin, inactivePlugin)
1638+ }
1639+
1640+ func test_loadSystemPlugin_by_fileNameWithoutExtension_returns_matching_plugin_when_active_state_is_nil( ) throws {
1641+ // Given
1642+ let activePlugin = storage. insertNewObject ( ofType: SystemPlugin . self)
1643+ activePlugin. plugin = " test-plugin/woocommerce.php "
1644+ activePlugin. siteID = sampleSiteID
1645+ activePlugin. active = true
1646+
1647+ let inactivePlugin = storage. insertNewObject ( ofType: SystemPlugin . self)
1648+ inactivePlugin. plugin = " jetpack/jetpack.php "
1649+ inactivePlugin. siteID = sampleSiteID
1650+ inactivePlugin. active = false
1651+
1652+ // When
1653+ let foundPlugin = storage. loadSystemPlugin ( siteID: sampleSiteID, fileNameWithoutExtension: " woocommerce " , active: nil )
1654+
1655+ // Then
1656+ XCTAssertNotNil ( foundPlugin)
1657+ XCTAssertEqual ( foundPlugin, activePlugin)
1658+ }
1659+
1660+ func test_loadSystemPlugin_by_fileNameWithoutExtension_returns_nil_when_active_state_does_not_match( ) {
1661+ // Given
1662+ let activePlugin = storage. insertNewObject ( ofType: SystemPlugin . self)
1663+ activePlugin. plugin = " woocommerce/woocommerce.php "
1664+ activePlugin. siteID = sampleSiteID
1665+ activePlugin. active = true
1666+
1667+ // When
1668+ let foundPlugin = storage. loadSystemPlugin ( siteID: sampleSiteID, fileNameWithoutExtension: " woocommerce " , active: false )
1669+
1670+ // Then
1671+ XCTAssertNil ( foundPlugin)
1672+ }
1673+
1674+ // MARK: - `loadSystemPlugins(siteID:matchingPaths:)`
1675+
15411676 func test_loadSystemPlugins_by_siteID_matching_paths( ) {
15421677 // Given
15431678 let systemPlugin1 = storage. insertNewObject ( ofType: SystemPlugin . self)
0 commit comments