Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permalink return 404 #5

Open
g-kanoufi opened this issue Aug 8, 2019 · 1 comment
Open

Permalink return 404 #5

g-kanoufi opened this issue Aug 8, 2019 · 1 comment

Comments

@g-kanoufi
Copy link

Hey i am using a fork of your docker-wp-browser, which is awesome, i do have a small issue where any frontend page(/pagename) is giving me a 404 treatment, being not that qualified in docker, i would presume it comes from mod_rewrite not beign enabled.

On my fork, i have added:

a2enmod rewrite
service apache2 restart

in the entrypoint file, but i can't seem to resolve my issue.

If you have any idea that could help that will be very welcome of course.

Thank you,

--
Guillaume

@ryanshoover
Copy link
Owner

@g-kanoufi We've run into this when we didn't have rewrite rules in place in our DB. Have you set up rewrite rules for your site?

For example, in our tests/_support/FunctionalTester.php file we have a setup function we can call that looks like below.

Once our rewrite rules are in place, we've successfully written functional and acceptance tests calling to URLs like http://localhost/post-1/

tests/_support/FunctionalTester.php

class FunctionalTester extends \Codeception\Actor
{
	use _generated\FunctionalTesterActions;

	/**
	 * Add our permalink structure and setup rewrite rules
	 *
	 * @link https://github.com/lucatume/wp-browser/issues/190
	 */
	public function haveRewriteRules() {
		$this->haveOptionInDatabase(
			'permalink_structure',
			'/blog/%postname%/'
		);
		$this->loginAsAdmin();
		$this->amOnAdminPage( 'options-permalink.php' );
		$this->seeOptionInDatabase(
			[
				'option_name' => 'rewrite_rules',
			]
		);
	}
}

tests/functional/PostTypesCest.php

class PostTypes_Cest {

	/**
	 * Set up the pages before we run our tests.
	 *
	 * @param FunctionalTester $I Instance of FunctionalTester.
	 */
	public function _before( FunctionalTester $I ) {
		$I->haveRewriteRules();
	}

	public function blogPostRenders( FunctionalTester $I ) {
		$this->check( $I, true, 'post', 'blog' );
	}

	/**
	 * Check whether a post type renders correctly (or doesn't)
	 *
	 * @param FunctionalTester $I         Instance of the Functional Tester.
	 * @param boolean          $shouldSee Whether the post type should render.
	 * @param string           $post_type The post type we are testing.
	 * @param string           $path      The rewrite path of the post type.
	 */
	protected function check( FunctionalTester $I, bool $shouldSee, $post_type, $path = '' ) {
		$path       = $path ?: $post_type;
		$post_title = $this->faker->words( 3, true );
		$post_name  = strtolower( str_replace( ' ', '-', $post_title ) );
		$I->havePostInDatabase(
			[
				'post_title'  => $post_title,
				'post_name'   => $post_name,
				'post_type'   => $post_type,
				'post_status' => 'publish',
			]
		);
		$I->amOnPage( "/$path/$post_name/" );
		if ( $shouldSee ) {
			$I->see( $post_title );
		} else {
			$I->seeResponseCodeIs( '404' );
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants