Then we create a new instance of our custom demo_block with no value inside the Who field and assert that a successful confirmation message is printed as a result.Test Driven Development ( TDD) facilitates clean and stable code. */ public function testCustomPageExists ( ) įor this test we need another user that also has the permission to administer blocks. * Tests that the 'demo/' path returns the right content We can start by testing the custom page callback: /** Keep in mind that each needs to start with the prefix test in order for Simpletest to run them automatically. Additionally, the user is created just so we can make sure this permission is respected.įor the three bullet points we identified above, we will now create three test methods. Here we have a simple test class which for every test it runs, will enable the modules in the $modules property and create a new user stored inside the $user property (by virtue of running the setUp() method).įor our purposes, we need to enable the demo module because that is what we are testing, the block module because we have a custom block plugin we need to test and the node module because our logic uses the access content permission defined by this module. Inside a file called DemoTest.php located in the src/Tests/ folder, we can start by adding the following: user = $this -> drupalCreateUser ( array ( 'access content' ) ) } } However, you should probably group yours into multiple classes depending on what they are actually responsible for. The custom menu link we defined inside the could also be tested but that should already work out of the box so I prefer not to.įor the sake of brevity and the fact that we don’t have too much we need to test, I will include all of our testing methods into one single class.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |