Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions tests/integration/tests/test-add-network-existing-site.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
/**
* Tests for adding a network with an existing site as root site.
*
* @since NEXT
*/

class WPMN_Tests_AddNetworkExistingSite extends WPMN_UnitTestCase {

/**
* Test adding a network with an existing site as root site.
*
* @since NEXT
*/
public function test_add_network_with_existing_site() {

// Create a test user.
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
grant_super_admin( $user_id );

// Create a site to use as the existing root site.
$site_id = $this->factory->blog->create(
array(
'domain' => 'existing-site.example.com',
'path' => '/',
)
);

// Create a network using the existing site.
$network_id = add_network(
array(
'domain' => 'existing-site.example.com',
'path' => '/',
'site_name' => 'Existing Site',
'network_name' => 'Test Network',
'user_id' => $user_id,
'network_admin_id' => $user_id,
'existing_blog_id' => $site_id,
)
);

// Verify network was created successfully.
$this->assertNotWPError( $network_id, 'Network should be created successfully' );
$this->assertIsInt( $network_id, 'Network ID should be an integer' );

// Verify the site was moved to the new network.
$site = get_site( $site_id );
$this->assertEquals( $network_id, (int) $site->network_id, 'Site should be in the new network' );

// Verify the site is the main site of the new network.
$main_site_id = get_network_option( $network_id, 'main_site' );
$this->assertEquals( $site_id, (int) $main_site_id, 'Site should be the main site of the new network' );
}

/**
* Test adding a network with a nonexistent site returns an error.
*
* @since NEXT
*/
public function test_add_network_with_nonexistent_site() {

// Create a test user.
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
grant_super_admin( $user_id );

// Attempt to create a network with a nonexistent site ID.
$result = add_network(
array(
'domain' => 'nonexistent.example.com',
'path' => '/',
'site_name' => 'Test Site',
'network_name' => 'Test Network',
'user_id' => $user_id,
'network_admin_id' => $user_id,
'existing_blog_id' => 999999,
)
);

$this->assertWPError( $result, 'Should return WP_Error for nonexistent site' );
$this->assertEquals( 'blog_not_exist', $result->get_error_code(), 'Error code should be blog_not_exist' );
}

/**
* Test adding a network with a main site of another network returns an error.
*
* @since NEXT
*/
public function test_add_network_with_main_site() {

// Create a test user.
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
grant_super_admin( $user_id );

// Create a network with add_network() so it has a real main site.
$first_network_id = add_network(
array(
'domain' => 'first-network.example.com',
'path' => '/',
'site_name' => 'First Network Site',
'network_name' => 'First Network',
'user_id' => $user_id,
'network_admin_id' => $user_id,
)
);

// Get the main site of the first network.
$main_site_id = get_main_site_id( $first_network_id );

// Attempt to create a second network using the main site.
$result = add_network(
array(
'domain' => 'second-network.example.com',
'path' => '/',
'site_name' => 'Test Site',
'network_name' => 'Second Network',
'user_id' => $user_id,
'network_admin_id' => $user_id,
'existing_blog_id' => $main_site_id,
)
);

$this->assertWPError( $result, 'Should return WP_Error when using a main site' );
$this->assertEquals( 'blog_is_main_site', $result->get_error_code(), 'Error code should be blog_is_main_site' );
}

/**
* Test adding a network without existing_blog_id creates a new site.
*
* @since NEXT
*/
public function test_add_network_without_existing_site() {

// Create a test user.
$user_id = $this->factory->user->create(
array(
'role' => 'administrator',
)
);
grant_super_admin( $user_id );

// Create a network without existing_blog_id.
$network_id = add_network(
array(
'domain' => 'site-test.example.com',
'path' => '/',
'site_name' => 'Test Site',
'network_name' => 'Test Network',
'user_id' => $user_id,
'network_admin_id' => $user_id,
)
);

// Verify network was created successfully.
$this->assertNotWPError( $network_id, 'Network should be created successfully' );
$this->assertIsInt( $network_id, 'Network ID should be an integer' );

// Verify a new site was created as the main site.
$main_site_id = get_network_option( $network_id, 'main_site' );
$this->assertNotEmpty( $main_site_id, 'A main site should have been created' );

$main_site = get_site( $main_site_id );
$this->assertNotNull( $main_site, 'Main site should exist' );
$this->assertEquals( 'site-test.example.com', $main_site->domain, 'Main site should have the network domain' );
}
}
20 changes: 18 additions & 2 deletions wp-multi-network/assets/css/wp-multi-network-rtl.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
th.column-title {
width: 35%;
}

th.column-path {
width: 15%;
}

th.column-blogs {
width: 10%;
}

td.column-domain {
white-space: nowrap;
overflow: hidden;
Expand Down Expand Up @@ -123,6 +126,7 @@ table.assign-sites td.column-available {
table.assign-sites td.column-assigned {
padding-right: 0;
}

table.assign-sites td.column-available,
table.assign-sites td.column-assigned {
width: 42%;
Expand All @@ -135,8 +139,8 @@ table.assign-sites td.column-assigned {
div.network-delete {
background: #fff;
border-right: 4px solid #dc3232;
-webkit-box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 );
box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 );
-webkit-box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
margin: 5px 0 2px;
padding: 1px 12px;
}
Expand All @@ -154,3 +158,15 @@ ul.delete-sites {
ul.delete-sites li {
margin: 0;
}

#root-site-toggle {
margin-top: 12px;
}

#root-site-toggle label {
margin-left: 16px;
}

.root-site-existing {
display: none;
}
2 changes: 1 addition & 1 deletion wp-multi-network/assets/css/wp-multi-network-rtl.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions wp-multi-network/assets/css/wp-multi-network.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
th.column-title {
width: 35%;
}

th.column-path {
width: 15%;
}

th.column-blogs {
width: 10%;
}

td.column-domain {
white-space: nowrap;
overflow: hidden;
Expand Down Expand Up @@ -123,6 +126,7 @@ table.assign-sites td.column-available {
table.assign-sites td.column-assigned {
padding-left: 0;
}

table.assign-sites td.column-available,
table.assign-sites td.column-assigned {
width: 42%;
Expand All @@ -135,8 +139,8 @@ table.assign-sites td.column-assigned {
div.network-delete {
background: #fff;
border-left: 4px solid #dc3232;
-webkit-box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 );
box-shadow: 0 1px 1px 0 rgba( 0, 0, 0, 0.1 );
-webkit-box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
margin: 5px 0 2px;
padding: 1px 12px;
}
Expand All @@ -154,3 +158,15 @@ ul.delete-sites {
ul.delete-sites li {
margin: 0;
}

#root-site-toggle {
margin-top: 12px;
}

#root-site-toggle label {
margin-right: 16px;
}

.root-site-existing {
display: none;
}
2 changes: 1 addition & 1 deletion wp-multi-network/assets/css/wp-multi-network.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions wp-multi-network/assets/js/wp-multi-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ jQuery( document ).ready( function ( $ ) {
move( 'to', 'from' );
} );

/* Toggle root site option between new and existing */
$( 'input[name=root_site_option]' ).on( 'change', function () {
if ( $( this ).val() === 'existing' ) {
$( '.root-site-new' ).hide();
$( '.root-site-existing' ).show();
$( '#wpmn-edit-network-details' ).hide();
} else {
$( '.root-site-new' ).show();
$( '.root-site-existing' ).hide();
$( '#wpmn-edit-network-details' ).show();
}
} );

/* Select all sites in "selected" box when submitting */
$( '#edit-network-form' ).submit( function () {
$( '#to' ).children( 'option:enabled' ).attr( 'selected', true );
Expand Down
2 changes: 1 addition & 1 deletion wp-multi-network/assets/js/wp-multi-network.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading