- <?php
- * @file
- * An example of simpletest tests.
- */
-
- * The SimpleTestExampleTestCase is a functional test case, meaning that it
- * actually exercises a particular sequence of actions through the web UI.
- * The majority of core test cases are done this way, but the SimpleTest suite
- * also provides unit tests as demonstrated in the unit test case example later
- * in this file.
- *
- * Functional test cases are far slower to execute than unit test cases because
- * they require a complete Backdrop install to be done for each test.
- *
- * @see BackdropWebTestCase
- * @see SimpleTestUnitTestExampleTestCase
- *
- * @ingroup simpletest_example
- */
- class SimpleTestExampleTestCase extends BackdropWebTestCase {
-
- protected $privilegedUser;
-
-
- * Set up the test environment.
- *
- * This method is called once per test method, before the test is executed.
- * It gives you a chance to control the setup of the test environment.
- *
- * If you need a different test environment, then you should create another
- * test class which overloads BackdropWebTestCase::setUp() differently.
- *
- * @see BackdropWebTestCase::setUp()
- */
- public function setUp() {
-
-
- parent::setUp('simpletest_example');
-
-
-
- $this->privilegedUser = $this->backdropCreateUser(array('create simpletest_example content', 'extra special edit any simpletest_example'));
- $this->backdropLogin($this->privilegedUser);
- }
-
-
- * Create a simpletest_example node using the node form.
- */
- public function testSimpleTestExampleCreate() {
-
- $edit = array();
- $edit['title'] = $this->randomName(8);
- $edit["body[und][0][value]"] = $this->randomName(16);
- $this->backdropPost('node/add/simpletest-example', $edit, t('Save'));
- $this->assertText(t('SimpleTest Example Node Type @title has been created.', array('@title' => $edit['title'])));
- }
-
-
- * Create a simpletest_example node and then see if our user can edit it.
- */
- public function testSimpleTestExampleEdit() {
- $settings = array(
- 'type' => 'simpletest_example',
- 'title' => $this->randomName(32),
- 'body' => array(LANGUAGE_NONE => array(array($this->randomName(64)))),
- );
- $node = $this->backdropCreateNode($settings);
-
-
-
- $this->verbose('Node created: ' . var_export($node, TRUE));
-
-
-
- if (!$this->runningOnTestbot()) {
-
-
-
- debug('We are not running on the PIFR testing server, so will go ahead and catch the failure.');
- $this->backdropGet("node/{$node->nid}/edit");
-
- $this->assertResponse(200, 'User is allowed to edit the content.');
-
-
-
- $this->assertText(t("@title", array('@title' => $settings['title'])), "Found title in edit form");
- }
- }
-
-
- * Detect if we're running on PIFR testbot.
- *
- * Skip intentional failure in that case. It happens that on the testbot the
- * site under test is in a directory named 'checkout' or 'site_under_test'.
- *
- * @return bool
- * TRUE if running on testbot.
- */
- public function runningOnTestbot() {
- return (file_exists("../checkout") || file_exists("../site_under_test"));
- }
- }
-
-
- * Although most core test cases are based on BackdropWebTestCase and are
- * functional tests (exercising the web UI) we also have BackdropUnitTestCase,
- * which executes much faster because a Backdrop install does not have to be
- * one. No environment is provided to a test case based on BackdropUnitTestCase;
- * it must be entirely self-contained.
- *
- * @see BackdropUnitTestCase
- *
- * @ingroup simpletest_example
- */
- class SimpleTestUnitTestExampleTestCase extends BackdropUnitTestCase {
-
-
- * Set up the test environment.
- *
- * Note that we use backdrop_load() instead of passing our module dependency
- * to parent::setUp(). That's because we're using BackdropUnitTestCase, and
- * thus we don't want to install the module, only load its code.
- *
- * Also, BackdropUnitTestCase can't actually install modules. This is by
- * design.
- */
- public function setUp() {
- backdrop_load('module', 'simpletest_example');
- parent::setUp();
- }
-
-
- * Test simpletest_example_empty_mysql_date().
- *
- * Note that no environment is provided; we're just testing the correct
- * behavior of a function when passed specific arguments.
- */
- public function testSimpleTestUnitTestExampleFunction() {
- $result = simpletest_example_empty_mysql_date(NULL);
-
-
- $message = 'A NULL value should return TRUE.';
- $this->assertTrue($result, $message);
-
- $result = simpletest_example_empty_mysql_date('');
- $message = 'An empty string should return TRUE.';
- $this->assertTrue($result, $message);
-
- $result = simpletest_example_empty_mysql_date('0000-00-00');
- $message = 'An "empty" MySQL DATE should return TRUE.';
- $this->assertTrue($result, $message);
-
- $result = simpletest_example_empty_mysql_date(date('Y-m-d'));
- $message = 'A valid date should return FALSE.';
- $this->assertFalse($result, $message);
- }
- }
-
- * SimpleTestExampleMockModuleTestCase allows us to demonstrate how you can
- * use a mock module to aid in functional testing in Backdrop.
- *
- * If you have some functionality that's not intrinsic to the code under test,
- * you can add a special mock module that only gets installed during test
- * time. This allows you to implement APIs created by your module, or otherwise
- * exercise the code in question.
- *
- * This test case class is very similar to SimpleTestExampleTestCase. The main
- * difference is that we enable the simpletest_example_test module in the
- * setUp() method. Then we can test for behaviors provided by that module.
- *
- * @see SimpleTestExampleTestCase
- *
- * @ingroup simpletest_example
- */
- class SimpleTestExampleMockModuleTestCase extends BackdropWebTestCase {
-
-
- * Set up the test environment.
- *
- * Note that we're enabling both the simpletest_example and
- * simpletest_example_test modules.
- */
- public function setUp() {
-
- parent::setUp('simpletest_example', 'simpletest_example_test');
- }
-
-
- * Test modifications made by our mock module.
- *
- * We create a simpletest_example node and then see if our submodule
- * operated on it.
- */
- public function testSimpleTestExampleMockModule() {
-
- $test_user = $this->backdropCreateUser(array('access content'));
-
- $this->backdropLogin($test_user);
-
- $settings = array(
- 'type' => 'simpletest_example',
- 'title' => $this->randomName(32),
- 'body' => array(LANGUAGE_NONE => array(array($this->randomName(64)))),
- );
-
- $node = $this->backdropCreateNode($settings);
-
- $this->backdropGet("node/{$node->nid}");
-
- $this->assertText(t('The test module did its thing.'), "Found evidence of test module.");
- }
-
- }