- <?php
- * @file
- * Test case for testing the Node Hooks Example module.
- *
- * This file contains the test cases to check if module is performing as
- * expected.
- */
-
- * Functional tests for the Node Hooks Example module.
- *
- * @ingroup nodeapi_example
- */
- class NodeHooksExampleTestCase extends BackdropWebTestCase {
-
- * User object to perform site browsing.
- *
- * @var object
- */
- protected $webUser;
-
-
- * Content type to attach the rating system.
- *
- * @var string
- */
- protected $type;
-
-
- * Enables modules and creates users with specific permissions.
- */
- public function setUp() {
- parent::setUp('nodeapi_example');
- module_disable(array('path'));
-
-
-
- $this->webUser = $this->backdropCreateUser(array(
-
- 'administer nodes',
- 'administer content types',
- 'administer fields',
- 'bypass node access',
- 'view revisions',
- 'revert revisions',
- ));
-
- $this->backdropLogin($this->webUser);
- }
-
-
- * Logs the user in, creates an example node, and uses the rating system.
- */
- public function testNodeExampleBasic() {
- $this->backdropLogin($this->webUser);
- $content_type = $this->backdropCreateContentType();
- $type = $content_type->type;
- $this->backdropGet('admin/structure/types/manage/' . $type);
- $this->assertResponse(200);
-
-
- $this->assertText(t('Node Hooks Example rating'), 'Rating options found in the content type.');
- $this->assertFieldByName('node_hooks_example_node_type', 1, 'The rating is disabled by default.');
-
-
- $content_settings = array(
- 'nodeapi_example_node_type' => 0,
- );
- $this->backdropPost('admin/structure/types/manage/' . $type, $content_settings, t('Save content type'));
- $this->assertResponse(200);
- $this->assertRaw(' has been updated.', 'Settings have been successfully modified for the content type.');
-
-
- $edit = array(
- "title" => $this->randomName(),
- );
- $this->backdropPost('node/add/' . $type, $edit, t('Save'));
- $this->assertResponse(200);
-
-
- $this->assertNoRaw('Rating: <em>', 'Extended rating information is not shown.');
-
-
- $node_url = $this->getUrl();
-
-
- $content_settings = array(
- 'nodeapi_example_node_type' => TRUE,
- );
- $this->backdropPost('admin/structure/types/manage/' . $type, $content_settings, t('Save content type'));
- $this->assertResponse(200);
- $this->assertRaw(' has been updated.', 'Settings hav been successfully modified for the content type.');
-
-
- $this->backdropGet($node_url);
- $this->assertResponse(200);
- $this->assertRaw(t('Rating: %rating', array('%rating' => t('Unrated'))), 'The content is not rated.');
-
-
- $rate = array(
- 'nodeapi_example_rating' => 4,
- );
- $this->backdropPost($node_url . '/edit', $rate, t('Save'));
- $this->assertResponse(200);
-
-
- $this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), 'The content has been successfully rated.');
- }
-
-
- * Tests revisions of ratings.
- *
- * Logs user in, creates an example node, and tests rating functionality with
- * a node using revisions.
- */
- public function testNodeExampleRevision() {
- $this->backdropLogin($this->webUser);
- $content_type = $this->backdropCreateContentType();
- $type = $content_type->type;
- $this->backdropGet('admin/structure/types/manage/' . $type);
- $this->assertResponse(200);
-
-
- $this->assertText(t('Node Hooks Example rating'), 'Rating options found in the content type.');
- $this->assertFieldByName('node_hooks_example_node_type', 1, 'The rating is disabled by default.');
-
-
- $content_settings = array(
- 'nodeapi_example_node_type' => 0,
- );
- $this->backdropPost('admin/structure/types/manage/' . $type, $content_settings, t('Save content type'));
- $this->assertResponse(200);
- $this->assertRaw(' has been updated.', 'Settings have been successfully modified for the content type.');
-
-
- $edit = array(
- "title" => $this->randomName(),
- );
- $this->backdropPost('node/add/' . $type, $edit, t('Save'));
- $this->assertResponse(200);
-
-
- $this->assertNoRaw('Rating: <em>', 'The extended rating information is not shown.');
-
-
- $node_url = $this->getUrl();
-
-
- $content_settings = array(
- 'nodeapi_example_node_type' => TRUE,
- );
- $this->backdropPost('admin/structure/types/manage/' . $type, $content_settings, t('Save content type'));
- $this->assertResponse(200);
- $this->assertRaw(' has been updated.', 'Settings has been successfully modified for the content type.');
-
-
- $this->backdropGet($node_url);
- $this->assertResponse(200);
- $this->assertRaw(t('Rating: %rating', array('%rating' => t('Unrated'))), 'The content is not rated.');
-
-
- $rate = array(
- 'node_hooks_example_rating' => 4,
- );
- $this->backdropPost($node_url . '/edit', $rate, t('Save'));
- $this->assertResponse(200);
-
-
- $this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), 'The content has been successfully rated.');
-
-
- $rate = array(
- 'nodeapi_example_rating' => 1,
- 'revision' => 1,
- );
- $this->backdropPost($node_url . '/edit', $rate, t('Save'));
- $this->assertResponse(200);
-
-
- $this->assertRaw(t('Rating: %rating', array('%rating' => t('Poor'))), 'The content has been successfully rated.');
-
-
- $this->backdropGet($node_url . '/revisions');
-
- $this->clickLink('Revert');
- $revert_form = $this->getUrl();
- $this->backdropPost($revert_form, array(), t('Revert'));
-
-
- $this->backdropGet($node_url);
- $this->assertResponse(200);
-
-
- $this->assertRaw(t('Rating: %rating', array('%rating' => t('Good'))), 'The content rating matches the reverted revision.');
- }
-
- }