diff --git a/phpunit/block-template-utils-test.php b/phpunit/block-template-utils-test.php deleted file mode 100644 index 4b10e33deee93..0000000000000 --- a/phpunit/block-template-utils-test.php +++ /dev/null @@ -1,251 +0,0 @@ - true, - 'show_in_rest' => true, - ) - ); - register_taxonomy( 'book_type', 'custom_book' ); - } - - public function tear_down() { - unregister_post_type( 'custom_book' ); - unregister_taxonomy( 'book_type' ); - parent::tear_down(); - } - - public function test_get_template_hierarchy() { - $hierarchy = get_template_hierarchy( 'front-page' ); - $this->assertEquals( array( 'front-page', 'home', 'index' ), $hierarchy ); - // Custom templates. - $hierarchy = get_template_hierarchy( 'whatever-slug', true ); - $this->assertEquals( array( 'page', 'singular', 'index' ), $hierarchy ); - // Single slug templates(ex. page, tag, author, etc.. - $hierarchy = get_template_hierarchy( 'page' ); - $this->assertEquals( array( 'page', 'singular', 'index' ), $hierarchy ); - $hierarchy = get_template_hierarchy( 'tag' ); - $this->assertEquals( array( 'tag', 'archive', 'index' ), $hierarchy ); - $hierarchy = get_template_hierarchy( 'author' ); - $this->assertEquals( array( 'author', 'archive', 'index' ), $hierarchy ); - $hierarchy = get_template_hierarchy( 'date' ); - $this->assertEquals( array( 'date', 'archive', 'index' ), $hierarchy ); - $hierarchy = get_template_hierarchy( 'taxonomy' ); - $this->assertEquals( array( 'taxonomy', 'archive', 'index' ), $hierarchy ); - $hierarchy = get_template_hierarchy( 'attachment' ); - $this->assertEquals( - array( - 'attachment', - 'single', - 'singular', - 'index', - ), - $hierarchy - ); - $hierarchy = get_template_hierarchy( 'singular' ); - $this->assertEquals( array( 'singular', 'index' ), $hierarchy ); - $hierarchy = get_template_hierarchy( 'single' ); - $this->assertEquals( array( 'single', 'singular', 'index' ), $hierarchy ); - $hierarchy = get_template_hierarchy( 'archive' ); - $this->assertEquals( array( 'archive', 'index' ), $hierarchy ); - $hierarchy = get_template_hierarchy( 'index' ); - $this->assertEquals( array( 'index' ), $hierarchy ); - - // Taxonomies. - $hierarchy = get_template_hierarchy( 'taxonomy-book_type', false ); - $this->assertEquals( array( 'taxonomy-book_type', 'taxonomy', 'archive', 'index' ), $hierarchy ); - - $hierarchy = get_template_hierarchy( 'taxonomy-books', false, 'taxonomy-books' ); - $this->assertEquals( array( 'taxonomy-books', 'taxonomy', 'archive', 'index' ), $hierarchy ); - // Single word category. - $hierarchy = get_template_hierarchy( 'category-fruits', false ); - $this->assertEquals( - array( - 'category-fruits', - 'category', - 'archive', - 'index', - ), - $hierarchy - ); - - $hierarchy = get_template_hierarchy( 'category-fruits', false, 'category' ); - $this->assertEquals( - array( - 'category-fruits', - 'category', - 'archive', - 'index', - ), - $hierarchy - ); - // Multi word category. - $hierarchy = get_template_hierarchy( 'category-fruits-yellow', false ); - $this->assertEquals( - array( - 'category-fruits-yellow', - 'category', - 'archive', - 'index', - ), - $hierarchy - ); - - $hierarchy = get_template_hierarchy( 'category-fruits-yellow', false, 'category' ); - $this->assertEquals( - array( - 'category-fruits-yellow', - 'category', - 'archive', - 'index', - ), - $hierarchy - ); - // Single word taxonomy. - $hierarchy = get_template_hierarchy( 'taxonomy-books-action', false, 'taxonomy-books' ); - $this->assertEquals( - array( - 'taxonomy-books-action', - 'taxonomy-books', - 'taxonomy', - 'archive', - 'index', - ), - $hierarchy - ); - - $hierarchy = get_template_hierarchy( 'taxonomy-book_type-adventure', false ); - $this->assertEquals( array( 'taxonomy-book_type-adventure', 'taxonomy-book_type', 'taxonomy', 'archive', 'index' ), $hierarchy ); - - $hierarchy = get_template_hierarchy( 'taxonomy-books-action-adventure', false, 'taxonomy-books' ); - $this->assertEquals( - array( - 'taxonomy-books-action-adventure', - 'taxonomy-books', - 'taxonomy', - 'archive', - 'index', - ), - $hierarchy - ); - // Multi word taxonomy/terms. - $hierarchy = get_template_hierarchy( 'taxonomy-greek-books-action-adventure', false, 'taxonomy-greek-books' ); - $this->assertEquals( - array( - 'taxonomy-greek-books-action-adventure', - 'taxonomy-greek-books', - 'taxonomy', - 'archive', - 'index', - ), - $hierarchy - ); - // Post types. - $hierarchy = get_template_hierarchy( 'single-book', false, 'single-book' ); - $this->assertEquals( - array( - 'single-book', - 'single', - 'singular', - 'index', - ), - $hierarchy - ); - $hierarchy = get_template_hierarchy( 'single-art-project', false, 'single-art-project' ); - $this->assertEquals( - array( - 'single-art-project', - 'single', - 'singular', - 'index', - ), - $hierarchy - ); - $hierarchy = get_template_hierarchy( 'single-art-project-imagine', false, 'single-art-project' ); - $this->assertEquals( - array( - 'single-art-project-imagine', - 'single-art-project', - 'single', - 'singular', - 'index', - ), - $hierarchy - ); - - $hierarchy = get_template_hierarchy( 'single-custom_book', false ); - $this->assertEquals( - array( - 'single-custom_book', - 'single', - 'singular', - 'index', - ), - $hierarchy - ); - - $hierarchy = get_template_hierarchy( 'single-custom_book-book-1', false ); - $this->assertEquals( - array( - 'single-custom_book-book-1', - 'single-custom_book', - 'single', - 'singular', - 'index', - ), - $hierarchy - ); - - $hierarchy = get_template_hierarchy( 'page-hi', false, 'page' ); - $this->assertEquals( - array( - 'page-hi', - 'page', - 'singular', - 'index', - ), - $hierarchy - ); - $hierarchy = get_template_hierarchy( 'page-hi', false ); - $this->assertEquals( - array( - 'page-hi', - 'page', - 'singular', - 'index', - ), - $hierarchy - ); - // Authors. - $hierarchy = get_template_hierarchy( 'author-rigas', false, 'author' ); - $this->assertEquals( - array( - 'author-rigas', - 'author', - 'archive', - 'index', - ), - $hierarchy - ); - // Archive post types. - $hierarchy = get_template_hierarchy( 'archive-book', false ); - $this->assertEquals( - array( - 'archive-book', - 'archive', - 'index', - ), - $hierarchy - ); - } -} diff --git a/phpunit/class-block-context-test.php b/phpunit/class-block-context-test.php deleted file mode 100644 index 49bbb560e8022..0000000000000 --- a/phpunit/class-block-context-test.php +++ /dev/null @@ -1,199 +0,0 @@ - 'example', - 'post_excerpt' => '', - ); - - $post = $this->factory()->post->create_and_get( $args ); - setup_postdata( $post ); - } - - /** - * Tear down each test method. - */ - public function tear_down() { - parent::tear_down(); - - while ( ! empty( $this->registered_block_names ) ) { - $block_name = array_pop( $this->registered_block_names ); - unregister_block_type( $block_name ); - } - } - - /** - * Registers a block type. - * - * @param string|WP_Block_Type $name Block type name including namespace, or alternatively a - * complete WP_Block_Type instance. In case a WP_Block_Type - * is provided, the $args parameter will be ignored. - * @param array $args { - * Optional. Array of block type arguments. Any arguments may be defined, however the - * ones described below are supported by default. Default empty array. - * - * @type callable $render_callback Callback used to render blocks of this block type. - * } - */ - protected function register_block_type( $name, $args ) { - register_block_type( $name, $args ); - - $this->registered_block_names[] = $name; - } - - /** - * Tests that a block which provides context makes that context available to - * its inner blocks. - */ - public function test_provides_block_context() { - $provided_context = array(); - - $this->register_block_type( - 'gutenberg/test-context-provider', - array( - 'attributes' => array( - 'contextWithAssigned' => array( - 'type' => 'number', - ), - 'contextWithDefault' => array( - 'type' => 'number', - 'default' => 0, - ), - 'contextWithoutDefault' => array( - 'type' => 'number', - ), - 'contextNotRequested' => array( - 'type' => 'number', - ), - ), - 'provides_context' => array( - 'gutenberg/contextWithAssigned' => 'contextWithAssigned', - 'gutenberg/contextWithDefault' => 'contextWithDefault', - 'gutenberg/contextWithoutDefault' => 'contextWithoutDefault', - 'gutenberg/contextNotRequested' => 'contextNotRequested', - ), - ) - ); - - $this->register_block_type( - 'gutenberg/test-context-consumer', - array( - 'uses_context' => array( - 'gutenberg/contextWithDefault', - 'gutenberg/contextWithAssigned', - 'gutenberg/contextWithoutDefault', - ), - 'render_callback' => static function ( $attributes, $content, $block ) use ( &$provided_context ) { - $provided_context[] = $block->context; - - return ''; - }, - ) - ); - - $parsed_blocks = parse_blocks( - '' . - '' . - '' - ); - - render_block( $parsed_blocks[0] ); - - $this->assertEquals( - array( - 'gutenberg/contextWithDefault' => 0, - 'gutenberg/contextWithAssigned' => 10, - ), - $provided_context[0] - ); - } - - /** - * Tests that a block can receive default-provided context through - * render_block. - */ - public function test_provides_default_context() { - global $post; - - $provided_context = array(); - - $this->register_block_type( - 'gutenberg/test-context-consumer', - array( - 'uses_context' => array( 'postId', 'postType' ), - 'render_callback' => static function ( $attributes, $content, $block ) use ( &$provided_context ) { - $provided_context[] = $block->context; - - return ''; - }, - ) - ); - - $parsed_blocks = parse_blocks( '' ); - - render_block( $parsed_blocks[0] ); - - $this->assertEquals( - array( - 'postId' => $post->ID, - 'postType' => $post->post_type, - ), - $provided_context[0] - ); - } - - /** - * Tests that default block context can be filtered. - */ - public function test_default_context_is_filterable() { - $provided_context = array(); - - $this->register_block_type( - 'gutenberg/test-context-consumer', - array( - 'uses_context' => array( 'example' ), - 'render_callback' => static function ( $attributes, $content, $block ) use ( &$provided_context ) { - $provided_context[] = $block->context; - - return ''; - }, - ) - ); - - $filter_block_context = static function ( $context ) { - $context['example'] = 'ok'; - return $context; - }; - - $parsed_blocks = parse_blocks( '' ); - - add_filter( 'render_block_context', $filter_block_context ); - - render_block( $parsed_blocks[0] ); - - remove_filter( 'render_block_context', $filter_block_context ); - - $this->assertEquals( array( 'example' => 'ok' ), $provided_context[0] ); - } -} diff --git a/phpunit/class-gutenberg-rest-block-patterns-controller-test.php b/phpunit/class-gutenberg-rest-block-patterns-controller-test.php deleted file mode 100644 index 3ca6d45627abb..0000000000000 --- a/phpunit/class-gutenberg-rest-block-patterns-controller-test.php +++ /dev/null @@ -1,221 +0,0 @@ -user->create( array( 'role' => 'administrator' ) ); - - // Setup an empty testing instance of `WP_Block_Patterns_Registry` and save the original. - self::$orig_registry = WP_Block_Patterns_Registry::get_instance(); - self::$registry_instance_property = new ReflectionProperty( 'WP_Block_Patterns_Registry', 'instance' ); - self::$registry_instance_property->setAccessible( true ); - $test_registry = new WP_Block_Pattern_Categories_Registry(); - self::$registry_instance_property->setValue( $test_registry ); - - // Register some patterns in the test registry. - $test_registry->register( - 'test/one', - array( - 'title' => 'Pattern One', - 'categories' => array( 'test' ), - 'viewportWidth' => 1440, - 'content' => '
Two
', - 'templateTypes' => array( 'single' ), - ) - ); - - $test_registry->register( - 'test/three', - array( - 'title' => 'Pattern Three', - 'categories' => array( 'test', 'buttons', 'query' ), - 'content' => 'Three
', - 'templateTypes' => array( '404' ), - ) - ); - } - - public static function wpTearDownAfterClass() { - self::delete_user( self::$admin_id ); - - // Restore the original registry instance. - self::$registry_instance_property->setValue( self::$orig_registry ); - self::$registry_instance_property->setAccessible( false ); - self::$registry_instance_property = null; - self::$orig_registry = null; - } - - public function set_up() { - parent::set_up(); - switch_theme( 'emptytheme' ); - } - - public function test_get_items_migrate_pattern_categories() { - wp_set_current_user( self::$admin_id ); - - $request = new WP_REST_Request( 'GET', static::REQUEST_ROUTE ); - $request['_fields'] = 'name,categories'; - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - - $this->assertIsArray( $data, 'WP_REST_Block_Patterns_Controller::get_items() should return an array' ); - $this->assertGreaterThanOrEqual( 3, count( $data ), 'WP_REST_Block_Patterns_Controller::get_items() should return at least 3 items' ); - $this->assertSame( - array( - 'name' => 'test/one', - 'categories' => array( 'test' ), - ), - $data[0], - 'WP_REST_Block_Patterns_Controller::get_items() should return test/one' - ); - $this->assertSame( - array( - 'name' => 'test/two', - 'categories' => array( 'test' ), - ), - $data[1], - 'WP_REST_Block_Patterns_Controller::get_items() should return test/two' - ); - $this->assertSame( - array( - 'name' => 'test/three', - 'categories' => array( 'test', 'call-to-action', 'posts' ), - ), - $data[2], - 'WP_REST_Block_Patterns_Controller::get_items() should return test/three' - ); - } - - /** - * Abstract methods that we must implement. - * - * @doesNotPerformAssertions - */ - public function test_register_routes() { - // Controller does not implement this method. - } - - public function test_get_items() { - wp_set_current_user( self::$admin_id ); - - $expected_names = array( 'test/one', 'test/two', 'test/three' ); - $expected_fields = array( 'name', 'content', 'template_types' ); - - $request = new WP_REST_Request( 'GET', '/wp/v2/block-patterns/patterns' ); - $request['_fields'] = 'name,content,template_types'; - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - - $this->assertCount( count( $expected_names ), $data ); - foreach ( $data as $idx => $item ) { - $this->assertEquals( $expected_names[ $idx ], $item['name'] ); - $this->assertEquals( $expected_fields, array_keys( $item ) ); - } - } - - /** - * @doesNotPerformAssertions - */ - public function test_context_param() { - // Controller does not implement this method. - } - - /** - * @doesNotPerformAssertions - */ - public function test_get_item() { - // Controller does not implement this method. - } - - /** - * @doesNotPerformAssertions - */ - public function test_create_item() { - // Controller does not implement this method. - } - - /** - * @doesNotPerformAssertions - */ - public function test_update_item() { - // Controller does not implement this method. - } - - /** - * @doesNotPerformAssertions - */ - public function test_delete_item() { - // Controller does not implement this method. - } - - /** - * @doesNotPerformAssertions - */ - public function test_prepare_item() { - // Controller does not implement this method. - } - - /** - * @doesNotPerformAssertions - */ - public function test_get_item_schema() { - // Controller does not implement this method. - } -} diff --git a/phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php b/phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php deleted file mode 100644 index 0132bc53015e6..0000000000000 --- a/phpunit/class-gutenberg-rest-navigation-fallback-controller-test.php +++ /dev/null @@ -1,233 +0,0 @@ -user->create( array( 'role' => 'administrator' ) ); - - self::$editor_user = $factory->user->create( array( 'role' => 'editor' ) ); - } - - public function set_up() { - parent::set_up(); - - wp_set_current_user( self::$admin_user ); - } - - /** - * @covers WP_REST_Navigation_Fallback_Controller::register_routes - * - * @since 6.3.0 Added Navigation Fallbacks endpoint. - */ - public function test_register_routes() { - $routes = rest_get_server()->get_routes(); - - $this->assertArrayHasKey( '/wp-block-editor/v1/navigation-fallback', $routes, 'Fallback route should be registered.' ); - } - - /** - * @covers WP_REST_Navigation_Fallback_Controller - * - * @since 6.3.0 Added Navigation Fallbacks endpoint. - */ - public function test_should_not_return_menus_for_users_without_permissions() { - - wp_set_current_user( self::$editor_user ); - - $request = new WP_REST_Request( 'GET', '/wp-block-editor/v1/navigation-fallback' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 403, $response->get_status(), 'Response should indicate user does not have permission.' ); - - $this->assertEquals( 'rest_cannot_create', $data['code'], 'Response should indicate user cannot create.' ); - - $this->assertEquals( 'Sorry, you are not allowed to create Navigation Menus as this user.', $data['message'], 'Response should indicate failed request status.' ); - } - - /** - * @covers WP_REST_Navigation_Fallback_Controller - * - * @since 6.3.0 Added Navigation Fallbacks endpoint. - */ - public function test_get_item() { - - $request = new WP_REST_Request( 'GET', '/wp-block-editor/v1/navigation-fallback' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status(), 'Status should indicate successful request.' ); - - $this->assertIsArray( $data, 'Response should be of correct type.' ); - - $this->assertArrayHasKey( 'id', $data, 'Response should contain expected fields.' ); - - $this->assertEquals( 'wp_navigation', get_post_type( $data['id'] ), '"id" field should represent a post of type "wp_navigation"' ); - - // Check that only a single Navigation fallback was created. - $navs_in_db = $this->get_navigations_in_database(); - - $this->assertCount( 1, $navs_in_db, 'Only a single Navigation menu should be present in the database.' ); - } - - /** - * @covers WP_REST_Navigation_Fallback_Controller - * - * @since 6.3.0 Added Navigation Fallbacks endpoint. - */ - public function test_get_item_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wp-block-editor/v1/navigation-fallback' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - - $this->assertEquals( 200, $response->get_status(), 'Status should indicate successful request.' ); - - $this->assertArrayHasKey( 'schema', $data, '"schema" key should exist in response.' ); - - $schema = $data['schema']; - - $this->assertEquals( 'object', $schema['type'], 'The schema type should match the expected type.' ); - - $this->assertArrayHasKey( 'id', $schema['properties'], 'Schema should have an "id" property.' ); - $this->assertEquals( 'integer', $schema['properties']['id']['type'], 'Schema "id" property should be an integer.' ); - $this->assertTrue( $schema['properties']['id']['readonly'], 'Schema "id" property should be readonly.' ); - } - - /** - * @covers WP_REST_Navigation_Fallback_Controller - * - * @since 6.3.0 Added Navigation Fallbacks endpoint. - */ - public function test_adds_links() { - $request = new WP_REST_Request( 'GET', '/wp-block-editor/v1/navigation-fallback' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - - $navigation_post_id = $data['id']; - - $links = $response->get_links(); - - $this->assertNotEmpty( $links, 'Response should contain links.' ); - - $this->assertArrayHasKey( 'self', $links, 'Response should contain a "self" link.' ); - - $this->assertStringContainsString( 'wp/v2/navigation/' . $navigation_post_id, $links['self'][0]['href'], 'Self link should reference the correct Navigation Menu post resource url.' ); - - $this->assertTrue( $links['self'][0]['attributes']['embeddable'], 'Self link should be embeddable.' ); - } - - private function get_navigations_in_database() { - $navs_in_db = new WP_Query( - array( - 'post_type' => 'wp_navigation', - 'post_status' => 'publish', - 'posts_per_page' => -1, - 'orderby' => 'date', - 'order' => 'DESC', - ) - ); - - return $navs_in_db->posts ? $navs_in_db->posts : array(); - } - - /** - * @doesNotPerformAssertions - */ - public function test_prepare_item() { - // Covered by the core test. - } - - /** - * Tests that the correct filters are applied to the context parameter. - * - * By default, the REST response for the Posts Controller will not return all fields - * when the context is set to 'embed'. Assert that correct additional fields are added - * to the embedded Navigation Post, when the navigation fallback endpoint - * is called with the `_embed` param. - * - * @covers wp_add_fields_to_navigation_fallback_embedded_links - */ - public function test_embedded_navigation_post_contains_required_fields() { - // First we'll use the navigation fallback to get a link to the navigation endpoint. - $request = new WP_REST_Request( 'GET', '/wp-block-editor/v1/navigation-fallback' ); - $response = rest_get_server()->dispatch( $request ); - $links = $response->get_links(); - - // Extract the navigation endpoint URL from the response. - $embedded_navigation_href = $links['self'][0]['href']; - preg_match( '/\?rest_route=(.*)/', $embedded_navigation_href, $matches ); - $navigation_endpoint = $matches[1]; - - // Fetch the "linked" navigation post from the endpoint, with the context parameter set to 'embed' to simulate fetching embedded links. - $request = new WP_REST_Request( 'GET', $navigation_endpoint ); - $request->set_param( 'context', 'embed' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - - // Verify that the additional status field is present. - $this->assertArrayHasKey( 'status', $data, 'Response title should contain a "status" field.' ); - - // Verify that the additional content fields are present. - $this->assertArrayHasKey( 'content', $data, 'Response should contain a "content" field.' ); - $this->assertArrayHasKey( 'raw', $data['content'], 'Response content should contain a "raw" field.' ); - $this->assertArrayHasKey( 'rendered', $data['content'], 'Response content should contain a "rendered" field.' ); - $this->assertArrayHasKey( 'block_version', $data['content'], 'Response should contain a "block_version" field.' ); - - // Verify that the additional title.raw field is present. - $this->assertArrayHasKey( 'raw', $data['title'], 'Response title should contain a "raw" key.' ); - } - - /** - * @doesNotPerformAssertions - */ - public function test_context_param() { - // Covered by the core test. - } - - /** - * @doesNotPerformAssertions - */ - public function test_get_items() { - // Covered by the core test. - } - - /** - * @doesNotPerformAssertions - */ - public function test_create_item() { - // Controller does not implement create_item(). - } - - /** - * @doesNotPerformAssertions - */ - public function test_update_item() { - // Controller does not implement update_item(). - } - - /** - * @doesNotPerformAssertions - */ - public function test_delete_item() { - // Controller does not implement delete_item(). - } -} diff --git a/phpunit/class-gutenberg-rest-templates-controller-test.php b/phpunit/class-gutenberg-rest-templates-controller-test.php deleted file mode 100644 index bbb588fd583ea..0000000000000 --- a/phpunit/class-gutenberg-rest-templates-controller-test.php +++ /dev/null @@ -1,276 +0,0 @@ -user->create( - array( - 'role' => 'administrator', - ) - ); - - // Set up template post. - $args = array( - 'post_type' => 'wp_template', - 'post_name' => 'my_template', - 'post_title' => 'My Template', - 'post_content' => 'Content', - 'post_excerpt' => 'Description of my template.', - 'tax_input' => array( - 'wp_theme' => array( - get_stylesheet(), - ), - ), - ); - self::$post = self::factory()->post->create_and_get( $args ); - wp_set_post_terms( self::$post->ID, get_stylesheet(), 'wp_theme' ); - } - - public function test_register_routes() { - $routes = rest_get_server()->get_routes(); - $this->assertArrayHasKey( - '/wp/v2/templates/lookup', - $routes, - 'Get template fallback content route does not exist' - ); - } - - public function test_get_template_fallback() { - wp_set_current_user( self::$admin_id ); - $request = new WP_REST_Request( 'GET', '/wp/v2/templates/lookup' ); - // Should fallback to `category.html`. - $request->set_param( 'slug', 'category-fruits' ); - $request->set_param( 'is_custom', false ); - $request->set_param( 'template_prefix', 'category' ); - $response = rest_get_server()->dispatch( $request ); - $this->assertSame( 'category', $response->get_data()['slug'], 'Should fallback to `category.html`.' ); - // Should fallback to `singular.html`. - $request->set_param( 'slug', 'page-hello' ); - $request->set_param( 'is_custom', false ); - $request->set_param( 'template_prefix', 'page' ); - $response = rest_get_server()->dispatch( $request ); - $this->assertSame( 'singular', $response->get_data()['slug'], 'Should fallback to `singular.html`.' ); - // Should fallback to `index.html`. - $request->set_param( 'slug', 'author' ); - $request->set_param( 'ignore_empty', true ); - $request->set_param( 'is_custom', false ); - $response = rest_get_server()->dispatch( $request ); - $this->assertSame( 'index', $response->get_data()['slug'], 'Should fallback to `index.html`.' ); - // Should fallback to `index.html`. - $request->set_param( 'slug', 'tag-rigas' ); - $request->set_param( 'is_custom', false ); - $request->set_param( 'template_prefix', 'tag' ); - $response = rest_get_server()->dispatch( $request ); - $this->assertSame( 'index', $response->get_data()['slug'], 'Should fallback to `index.html`.' ); - } - - /** - * @covers WP_REST_Templates_Controller::get_item_schema - */ - public function test_get_item_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/templates' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - $properties = $data['schema']['properties']; - $this->assertCount( 17, $properties ); - $this->assertArrayHasKey( 'id', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'slug', $properties ); - $this->assertArrayHasKey( 'theme', $properties ); - $this->assertArrayHasKey( 'type', $properties ); - $this->assertArrayHasKey( 'source', $properties ); - $this->assertArrayHasKey( 'origin', $properties ); - $this->assertArrayHasKey( 'content', $properties ); - $this->assertArrayHasKey( 'title', $properties ); - $this->assertArrayHasKey( 'description', $properties ); - $this->assertArrayHasKey( 'status', $properties ); - $this->assertArrayHasKey( 'wp_id', $properties ); - $this->assertArrayHasKey( 'has_theme_file', $properties ); - $this->assertArrayHasKey( 'is_custom', $properties ); - $this->assertArrayHasKey( 'author', $properties ); - $this->assertArrayHasKey( 'modified', $properties ); - } - - /** - * @covers WP_REST_Templates_Controller::get_item - */ - public function test_get_item() { - wp_set_current_user( self::$admin_id ); - $request = new WP_REST_Request( 'GET', '/wp/v2/templates/emptytheme//my_template' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - unset( $data['content'] ); - unset( $data['_links'] ); - - $this->assertSame( - array( - 'id' => 'emptytheme//my_template', - 'theme' => 'emptytheme', - 'slug' => 'my_template', - 'source' => 'custom', - 'origin' => null, - 'type' => 'wp_template', - 'description' => 'Description of my template.', - 'title' => array( - 'raw' => 'My Template', - 'rendered' => 'My Template', - ), - 'status' => 'publish', - 'wp_id' => self::$post->ID, - 'has_theme_file' => false, - 'is_custom' => true, - 'author' => 0, - 'modified' => mysql_to_rfc3339( self::$post->post_modified ), - 'author_text' => 'Test Blog', - 'original_source' => 'site', - ), - $data - ); - } - - /** - * @covers WP_REST_Templates_Controller::get_items - */ - public function test_get_items() { - wp_set_current_user( self::$admin_id ); - $request = new WP_REST_Request( 'GET', '/wp/v2/templates' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - - $this->assertSame( - array( - 'id' => 'emptytheme//my_template', - 'theme' => 'emptytheme', - 'slug' => 'my_template', - 'source' => 'custom', - 'origin' => null, - 'type' => 'wp_template', - 'description' => 'Description of my template.', - 'title' => array( - 'raw' => 'My Template', - 'rendered' => 'My Template', - ), - 'status' => 'publish', - 'wp_id' => self::$post->ID, - 'has_theme_file' => false, - 'is_custom' => true, - 'author' => 0, - 'modified' => mysql_to_rfc3339( self::$post->post_modified ), - 'author_text' => 'Test Blog', - 'original_source' => 'site', - ), - $this->find_and_normalize_template_by_id( $data, 'emptytheme//my_template' ) - ); - } - - /** - * @covers WP_REST_Templates_Controller::update_item - */ - public function test_update_item() { - wp_set_current_user( self::$admin_id ); - $request = new WP_REST_Request( 'PUT', '/wp/v2/templates/emptytheme//my_template' ); - $request->set_body_params( - array( - 'title' => 'My new Index Title', - ) - ); - - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - $this->assertSame( 'My new Index Title', $data['title']['raw'] ); - $this->assertSame( 'custom', $data['source'] ); - $this->assertIsString( $data['modified'] ); - } - - /** - * @covers WP_REST_Templates_Controller::create_item - */ - public function test_create_item() { - wp_set_current_user( self::$admin_id ); - $request = new WP_REST_Request( 'POST', '/wp/v2/templates' ); - $request->set_body_params( - array( - 'slug' => 'my_custom_template', - 'description' => 'Just a description', - 'title' => 'My Template', - 'content' => 'Content', - 'author' => self::$admin_id, - ) - ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - unset( $data['_links'] ); - unset( $data['wp_id'] ); - - $author_name = get_user_by( 'id', self::$admin_id )->get( 'display_name' ); - - $this->assertSame( - array( - 'id' => 'emptytheme//my_custom_template', - 'theme' => 'emptytheme', - 'content' => array( - 'raw' => 'Content', - ), - 'slug' => 'my_custom_template', - 'source' => 'custom', - 'origin' => null, - 'type' => 'wp_template', - 'description' => 'Just a description', - 'title' => array( - 'raw' => 'My Template', - 'rendered' => 'My Template', - ), - 'status' => 'publish', - 'has_theme_file' => false, - 'is_custom' => true, - 'author' => self::$admin_id, - 'modified' => $data['modified'], - 'author_text' => $author_name, - 'original_source' => 'user', - ), - $data - ); - } - - /** - * @doesNotPerformAssertions - */ - public function test_context_param() {} - - /** - * @doesNotPerformAssertions - */ - public function test_delete_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_prepare_item() {} -} diff --git a/phpunit/class-wp-get-block-css-selectors-test.php b/phpunit/class-wp-get-block-css-selectors-test.php deleted file mode 100644 index 8f43d9df6d95e..0000000000000 --- a/phpunit/class-wp-get-block-css-selectors-test.php +++ /dev/null @@ -1,292 +0,0 @@ -test_block_name = null; - } - - public function tear_down() { - unregister_block_type( $this->test_block_name ); - $this->test_block_name = null; - parent::tear_down(); - } - - private function register_test_block( $name, $selectors = null, $supports = null ) { - $this->test_block_name = $name; - - return register_block_type( - $this->test_block_name, - array( - 'api_version' => 2, - 'attributes' => array(), - 'selectors' => $selectors, - 'supports' => $supports, - ) - ); - } - - public function test_get_root_selector_via_selectors_api() { - $block_type = self::register_test_block( - 'test/block-with-selectors', - array( 'root' => '.wp-custom-block-class' ) - ); - - $selector = wp_get_block_css_selector( $block_type ); - $this->assertEquals( '.wp-custom-block-class', $selector ); - } - - public function test_get_root_selector_via_experimental_property() { - $block_type = self::register_test_block( - 'test/block-without-selectors', - null, - array( '__experimentalSelector' => '.experimental-selector' ) - ); - - $selector = wp_get_block_css_selector( $block_type ); - $this->assertEquals( '.experimental-selector', $selector ); - } - - public function test_default_root_selector_generation_for_core_block() { - $block_type = self::register_test_block( - 'core/without-selectors-or-supports', - null, - null - ); - - $selector = wp_get_block_css_selector( $block_type ); - $this->assertEquals( '.wp-block-without-selectors-or-supports', $selector ); - } - - public function test_default_root_selector_generation() { - $block_type = self::register_test_block( - 'test/without-selectors-or-supports', - null, - null - ); - - $selector = wp_get_block_css_selector( $block_type ); - $this->assertEquals( '.wp-block-test-without-selectors-or-supports', $selector ); - } - - public function test_get_feature_selector_via_selectors_api() { - $block_type = self::register_test_block( - 'test/feature-selector', - array( 'typography' => array( 'root' => '.typography' ) ), - null - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography' ); - $this->assertEquals( '.typography', $selector ); - } - - public function test_get_feature_selector_via_selectors_api_shorthand_property() { - $block_type = self::register_test_block( - 'test/shorthand-feature-selector', - array( 'typography' => '.typography' ), - null - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography' ); - $this->assertEquals( '.typography', $selector ); - } - - public function test_no_feature_level_selector_via_selectors_api() { - $block_type = self::register_test_block( - 'test/null-feature-selector', - array( 'root' => '.fallback-root-selector' ), - null - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography' ); - $this->assertEquals( null, $selector ); - } - - public function test_fallback_feature_level_selector_via_selectors_api_to_generated_class() { - $block_type = self::register_test_block( - 'test/fallback-feature-selector', - array(), - null - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography', true ); - $this->assertEquals( '.wp-block-test-fallback-feature-selector', $selector ); - } - - - public function test_fallback_feature_level_selector_via_selectors_api() { - $block_type = self::register_test_block( - 'test/fallback-feature-selector', - array( 'root' => '.fallback-root-selector' ), - null - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography', true ); - $this->assertEquals( '.fallback-root-selector', $selector ); - } - - public function test_get_feature_selector_via_experimental_property() { - $block_type = self::register_test_block( - 'test/experimental-feature-selector', - null, - array( - 'typography' => array( - '__experimentalSelector' => '.experimental-typography', - ), - ) - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography' ); - $this->assertEquals( '.wp-block-test-experimental-feature-selector .experimental-typography', $selector ); - } - - public function test_fallback_feature_selector_via_experimental_property() { - $block_type = self::register_test_block( - 'test/fallback-feature-selector', - null, - array() - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography', true ); - $this->assertEquals( '.wp-block-test-fallback-feature-selector', $selector ); - } - - public function test_no_feature_selector_via_experimental_property() { - $block_type = self::register_test_block( - 'test/null-experimental-feature-selector', - null, - array() - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography' ); - $this->assertEquals( null, $selector ); - } - - public function test_get_subfeature_selector_via_selectors_api() { - $block_type = self::register_test_block( - 'test/subfeature-selector', - array( - 'typography' => array( - 'textDecoration' => '.root .typography .text-decoration', - ), - ), - null - ); - - $selector = wp_get_block_css_selector( - $block_type, - array( 'typography', 'textDecoration' ) - ); - - $this->assertEquals( '.root .typography .text-decoration', $selector ); - } - - public function test_fallback_subfeature_selector_via_selectors_api() { - $block_type = self::register_test_block( - 'test/subfeature-selector', - array( - 'typography' => array( 'root' => '.root .typography' ), - ), - null - ); - - $selector = wp_get_block_css_selector( - $block_type, - array( 'typography', 'textDecoration' ), - true - ); - - $this->assertEquals( '.root .typography', $selector ); - } - - public function test_no_subfeature_level_selector_via_selectors_api() { - $block_type = self::register_test_block( - 'test/null-subfeature-selector', - array(), - null - ); - - $selector = wp_get_block_css_selector( $block_type, array( 'typography', 'fontSize' ) ); - $this->assertEquals( null, $selector ); - } - - public function test_fallback_subfeature_selector_via_experimental_property() { - $block_type = self::register_test_block( - 'test/fallback-subfeature-selector', - null, - array() - ); - - $selector = wp_get_block_css_selector( - $block_type, - array( 'typography', 'fontSize' ), - true - ); - $this->assertEquals( '.wp-block-test-fallback-subfeature-selector', $selector ); - } - - public function test_no_subfeature_selector_via_experimental_property() { - $block_type = self::register_test_block( - 'test/null-experimental-subfeature-selector', - null, - array() - ); - - $selector = wp_get_block_css_selector( - $block_type, - array( 'typography', 'fontSize' ) - ); - $this->assertEquals( null, $selector ); - } - - public function test_empty_target_returns_null() { - $block_type = self::register_test_block( - 'test/null-experimental-subfeature-selector', - null, - array() - ); - - $selector = wp_get_block_css_selector( $block_type, array() ); - $this->assertEquals( null, $selector ); - - $selector = wp_get_block_css_selector( $block_type, '' ); - $this->assertEquals( null, $selector ); - } - - public function test_string_targets_for_features() { - $block_type = self::register_test_block( - 'test/target-types-for-features', - array( 'typography' => '.found' ), - null - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography' ); - $this->assertEquals( '.found', $selector ); - - $selector = wp_get_block_css_selector( $block_type, array( 'typography' ) ); - $this->assertEquals( '.found', $selector ); - } - - public function test_string_targets_for_subfeatures() { - $block_type = self::register_test_block( - 'test/target-types-for-features', - array( - 'typography' => array( 'fontSize' => '.found' ), - ), - null - ); - - $selector = wp_get_block_css_selector( $block_type, 'typography.fontSize' ); - $this->assertEquals( '.found', $selector ); - - $selector = wp_get_block_css_selector( $block_type, array( 'typography', 'fontSize' ) ); - $this->assertEquals( '.found', $selector ); - } -} diff --git a/phpunit/class-wp-rest-block-pattern-categories-controller-test.php b/phpunit/class-wp-rest-block-pattern-categories-controller-test.php deleted file mode 100644 index d4fb4e1b08842..0000000000000 --- a/phpunit/class-wp-rest-block-pattern-categories-controller-test.php +++ /dev/null @@ -1,117 +0,0 @@ -user->create( array( 'role' => 'administrator' ) ); - - // Setup an empty testing instance of `WP_Block_Pattern_Categories_Registry` and save the original. - $reflection = new ReflectionClass( 'WP_Block_Pattern_Categories_Registry' ); - $instance_property = $reflection->getProperty( 'instance' ); - $instance_property->setAccessible( true ); - self::$original_instance_value = $instance_property->getValue( null ); - - $test_registry = new WP_Block_Pattern_Categories_Registry(); - $instance_property->setValue( $test_registry ); - - // Register some categories in the test registry. - $test_registry->register( 'test', array( 'label' => 'Test' ) ); - $test_registry->register( 'query', array( 'label' => 'Query' ) ); - } - - public static function wpTearDownAfterClass() { - // Delete the test user. - self::delete_user( self::$admin_id ); - - // Restore the original registry instance. - $reflection = new ReflectionClass( 'WP_Block_Pattern_Categories_Registry' ); - $instance_property = $reflection->getProperty( 'instance' ); - $instance_property->setAccessible( true ); - $instance_property->setValue( self::$original_instance_value ); - $instance_property->setAccessible( false ); - } - - public function test_register_routes() { - $routes = rest_get_server()->get_routes(); - $this->assertArrayHasKey( - '/wp/v2/block-patterns/categories', - $routes, - 'The categories route does not exist' - ); - } - - public function test_get_items() { - wp_set_current_user( self::$admin_id ); - - $expected_names = array( 'test', 'query' ); - $expected_fields = array( 'name', 'label' ); - - $request = new WP_REST_Request( 'GET', '/wp/v2/block-patterns/categories' ); - $request['_fields'] = 'name,label'; - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - - $this->assertCount( count( $expected_names ), $data ); - foreach ( $data as $idx => $item ) { - $this->assertEquals( $expected_names[ $idx ], $item['name'] ); - $this->assertEquals( $expected_fields, array_keys( $item ) ); - } - } - - /** - * Abstract methods that we must implement. - * - * @doesNotPerformAssertions - */ - public function test_context_param() {} - - /** - * @doesNotPerformAssertions - */ - public function test_get_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_create_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_update_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_delete_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_prepare_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_get_item_schema() {} -} diff --git a/phpunit/class-wp-test-rest-users-controller.php b/phpunit/class-wp-test-rest-users-controller.php deleted file mode 100644 index 522c4d763c563..0000000000000 --- a/phpunit/class-wp-test-rest-users-controller.php +++ /dev/null @@ -1,267 +0,0 @@ -user->create( - array( - 'role' => 'administrator', - 'user_login' => 'superadmin', - ) - ); - self::$user = $factory->user->create( - array( - 'role' => 'administrator', - ) - ); - self::$editor = $factory->user->create( - array( - 'role' => 'editor', - 'user_email' => 'editor@example.com', - ) - ); - self::$draft_editor = $factory->user->create( - array( - 'role' => 'editor', - 'user_email' => 'draft-editor@example.com', - ) - ); - self::$subscriber = $factory->user->create( - array( - 'role' => 'subscriber', - 'display_name' => 'subscriber', - 'user_email' => 'subscriber@example.com', - ) - ); - - foreach ( array( true, false ) as $show_in_rest ) { - foreach ( array( true, false ) as $public ) { - $post_type_name = 'r_' . json_encode( $show_in_rest ) . '_p_' . json_encode( $public ); - register_post_type( - $post_type_name, - array( - 'public' => $public, - 'show_in_rest' => $show_in_rest, - 'tests_no_auto_unregister' => true, - ) - ); - self::$authors[ $post_type_name ] = $factory->user->create( - array( - 'role' => 'editor', - 'user_email' => 'author_' . $post_type_name . '@example.com', - ) - ); - self::$posts[ $post_type_name ] = $factory->post->create( - array( - 'post_type' => $post_type_name, - 'post_author' => self::$authors[ $post_type_name ], - ) - ); - } - } - - self::$posts['post'] = $factory->post->create( - array( - 'post_type' => 'post', - 'post_author' => self::$editor, - ) - ); - self::$posts['r_true_p_true_DRAFT'] = $factory->post->create( - array( - 'post_type' => 'r_true_p_true', - 'post_author' => self::$draft_editor, - 'post_status' => 'draft', - ) - ); - - if ( is_multisite() ) { - self::$site = $factory->blog->create( - array( - 'domain' => 'rest.wordpress.org', - 'path' => '/', - ) - ); - update_site_option( 'site_admins', array( 'superadmin' ) ); - } - - // Set up users for pagination tests. - for ( $i = 0; $i < self::$total_users - 10; $i++ ) { - self::$user_ids[] = $factory->user->create( - array( - 'role' => 'contributor', - 'display_name' => "User {$i}", - ) - ); - } - } - - public static function wpTearDownAfterClass() { - self::delete_user( self::$user ); - self::delete_user( self::$editor ); - self::delete_user( self::$draft_editor ); - - foreach ( self::$posts as $post ) { - wp_delete_post( $post, true ); - } - - foreach ( self::$authors as $author ) { - self::delete_user( $author ); - } - - _unregister_post_type( 'r_true_p_true' ); - _unregister_post_type( 'r_true_p_false' ); - _unregister_post_type( 'r_false_p_true' ); - _unregister_post_type( 'r_false_p_false' ); - - if ( is_multisite() ) { - wp_delete_site( self::$site ); - } - - // Remove users for pagination tests. - foreach ( self::$user_ids as $user_id ) { - self::delete_user( $user_id ); - } - } - - /** - * This function is run before each method - */ - public function set_up() { - parent::set_up(); - $this->endpoint = new WP_REST_Users_Controller(); - } - - /** - * The following methods are implemented in core and tested. - * We need to define them here because they exist in the abstract parent. - * - * @doesNotPerformAssertions - */ - public function test_register_routes() {} - - /** - * @doesNotPerformAssertions - */ - public function test_context_param() {} - - /** - * @doesNotPerformAssertions - */ - public function test_get_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_prepare_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_create_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_update_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_delete_item() {} - - /** - * @doesNotPerformAssertions - */ - public function test_get_items() {} - - /** - * @doesNotPerformAssertions - */ - public function test_get_item_schema() {} - - public function test_registered_query_params() { - $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); - $keys = array_keys( $data['endpoints'][0]['args'] ); - sort( $keys ); - $this->assertSame( - array( - 'context', - 'exclude', - 'has_published_posts', - 'include', - 'offset', - 'order', - 'orderby', - 'page', - 'per_page', - 'roles', - 'search', - 'slug', - 'who', - ), - $keys - ); - } - - /** - * Test the has_published_posts param. - */ - public function test_get_items_has_published_posts_query() { - wp_set_current_user( self::$superadmin ); - - // Test all users who have authored a post. - $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); - $request->set_param( 'has_published_posts', true ); - $response = rest_get_server()->dispatch( $request ); - // Make sure the response status is successful. - $this->assertSame( 200, $response->get_status() ); - // Make sure we have 3 authors. - $this->assertCount( 3, $response->get_data() ); - // Make sure we have the right author IDs. - $this->assertSame( 4, $response->get_data()[0]['id'] ); - $this->assertSame( 7, $response->get_data()[1]['id'] ); - $this->assertSame( 8, $response->get_data()[2]['id'] ); - - // Test users for a specific post-type. - $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); - $request->set_param( 'has_published_posts', array( 'r_true_p_true' ) ); - $response = rest_get_server()->dispatch( $request ); - // Make sure the response status is successful. - $this->assertSame( 200, $response->get_status() ); - // Make sure we only have 1 author. - $this->assertCount( 1, $response->get_data() ); - // Make sure we got the correct author. - $this->assertSame( 7, $response->get_data()[0]['id'] ); - - // Test invalid post-type. - $request = new WP_REST_Request( 'GET', '/wp/v2/users' ); - $request->set_param( 'has_published_posts', array( 'dummy' ) ); - $response = rest_get_server()->dispatch( $request ); - // Make sure the response has a status of 400. - $this->assertSame( 400, $response->get_status() ); - } -} diff --git a/phpunit/tests/blocks/renderHookedBlocks.php b/phpunit/tests/blocks/renderHookedBlocks.php deleted file mode 100644 index 5e9abd4d8ba05..0000000000000 --- a/phpunit/tests/blocks/renderHookedBlocks.php +++ /dev/null @@ -1,168 +0,0 @@ - -Foo
- -Foo
- -Foo
- -Foo
- -