WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/02/2014 09:47:25 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Add unit tests for get_blog_details().

props jeremyfelt.
fixes #29845.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ms.php

    r29818 r29824  
    14361436
    14371437    /**
     1438     * @ticket 29845
     1439     */
     1440    function test_get_blog_details() {
     1441        $network_ids = array(
     1442            'wordpress.org/'         => array( 'domain' => 'wordpress.org', 'path' => '/' ),
     1443            'make.wordpress.org/'    => array( 'domain' => 'make.wordpress.org', 'path' => '/' ),
     1444        );
     1445
     1446        foreach ( $network_ids as &$id ) {
     1447            $id = $this->factory->network->create( $id );
     1448        }
     1449        unset( $id );
     1450
     1451        $ids = array(
     1452            'wordpress.org/'              => array( 'domain' => 'wordpress.org',      'path' => '/',         'title' => 'Test 1', 'site_id' => $network_ids['wordpress.org/'] ),
     1453            'wordpress.org/foo/'          => array( 'domain' => 'wordpress.org',      'path' => '/foo/',     'title' => 'Test 2', 'site_id' => $network_ids['wordpress.org/'] ),
     1454            'wordpress.org/foo/bar/'      => array( 'domain' => 'wordpress.org',      'path' => '/foo/bar/', 'title' => 'Test 3', 'site_id' => $network_ids['wordpress.org/'] ),
     1455            'make.wordpress.org/'         => array( 'domain' => 'make.wordpress.org', 'path' => '/',         'title' => 'Test 4', 'site_id' => $network_ids['make.wordpress.org/'] ),
     1456            'make.wordpress.org/foo/'     => array( 'domain' => 'make.wordpress.org', 'path' => '/foo/',     'title' => 'Test 5', 'site_id' => $network_ids['make.wordpress.org/'] ),
     1457        );
     1458
     1459        foreach ( $ids as &$id ) {
     1460            $id = $this->factory->blog->create( $id );
     1461        }
     1462        unset( $id );
     1463
     1464        // Retrieve site details by passing only a blog ID.
     1465        $site = get_blog_details( $ids['wordpress.org/'] );
     1466        $this->assertEquals( $ids['wordpress.org/'], $site->blog_id );
     1467        $this->assertEquals( 'Test 1', $site->blogname );
     1468
     1469        $site = get_blog_details( $ids['wordpress.org/foo/'] );
     1470        $this->assertEquals( $ids['wordpress.org/foo/'], $site->blog_id );
     1471        $this->assertEquals( 'Test 2', $site->blogname );
     1472
     1473        $site = get_blog_details( 999 );
     1474        $this->assertFalse( $site );
     1475
     1476        // Retrieve site details by passing an array containing blog_id.
     1477        $site = get_blog_details( array( 'blog_id' => $ids['wordpress.org/foo/bar/'] ) );
     1478        $this->assertEquals( $ids['wordpress.org/foo/bar/'], $site->blog_id );
     1479        $this->assertEquals( 'Test 3', $site->blogname );
     1480
     1481        $site = get_blog_details( array( 'blog_id' => $ids['make.wordpress.org/'] ) );
     1482        $this->assertEquals( $ids['make.wordpress.org/'], $site->blog_id );
     1483        $this->assertEquals( 'Test 4', $site->blogname );
     1484
     1485        $site = get_blog_details( array( 'blog_id' => 999 ) );
     1486        $this->assertFalse( $site );
     1487
     1488        // Retrieve site details by passing an array containing domain and path.
     1489        $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/' ) );
     1490        $this->assertEquals( $ids['wordpress.org/'], $site->blog_id );
     1491        $this->assertEquals( 'Test 1', $site->blogname );
     1492
     1493        $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/foo/' ) );
     1494        $this->assertEquals( $ids['wordpress.org/foo/'], $site->blog_id );
     1495        $this->assertEquals( 'Test 2', $site->blogname );
     1496
     1497        $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/foo/bar/' ) );
     1498        $this->assertEquals( $ids['wordpress.org/foo/bar/'], $site->blog_id );
     1499        $this->assertEquals( 'Test 3', $site->blogname );
     1500
     1501        $site = get_blog_details( array( 'domain' => 'make.wordpress.org', 'path' => '/' ) );
     1502        $this->assertEquals( $ids['make.wordpress.org/'], $site->blog_id );
     1503        $this->assertEquals( 'Test 4', $site->blogname );
     1504
     1505        $site = get_blog_details( array( 'domain' => 'make.wordpress.org', 'path' => '/foo/' ) );
     1506        $this->assertEquals( $ids['make.wordpress.org/foo/'], $site->blog_id );
     1507        $this->assertEquals( 'Test 5', $site->blogname );
     1508
     1509        $site = get_blog_details( array( 'domain' => 'wordpress.org', 'path' => '/zxy/' ) );
     1510        $this->assertFalse( $site );
     1511    }
     1512
     1513    /**
    14381514     * @ticket 27884
    14391515     */
Note: See TracChangeset for help on using the changeset viewer.