? .DS_Store ? simpletest ? simpletest_upload_tests.patch ? tmp.patch ? tracker_tests.patch ? tests/.DS_Store ? tests/functional/.DS_Store Index: drupal_test_case.php =================================================================== RCS file: /cvs/drupal/contributions/modules/simpletest/drupal_test_case.php,v retrieving revision 1.78 diff -u -p -r1.78 drupal_test_case.php --- drupal_test_case.php 30 Mar 2008 21:43:29 -0000 1.78 +++ drupal_test_case.php 1 Apr 2008 16:22:40 -0000 @@ -85,6 +85,22 @@ class DrupalTestCase extends UnitTestCas } /** + * Creates many nodes + * + * @param $count + * The number of nodes to create + * @param $settings + * The settings to pass in to drupalCreateNode + */ + function drupalCreateNodes($count = 4, $settings = array()) { + $nodes = array(); + for ($i = 0; $i < $count; $i++) { + $nodes[] = $this->drupalCreateNode($settings); + } + return $nodes; + } + + /** * Creates a custom content type based on default settings. * * @param settings Index: tests/functional/tracker.test =================================================================== RCS file: tests/functional/tracker.test diff -N tests/functional/tracker.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/functional/tracker.test 1 Apr 2008 16:22:40 -0000 @@ -0,0 +1,242 @@ + 'Tracker Tests', + 'group' => 'Tracker tests', + 'description' => 'Tests for the tracker module', + ); + } + + function testTrackerAllPostsNodes() { + // Enable the comment and tracker modules + $this->drupalModuleEnable('comment'); + $this->drupalModuleEnable('tracker'); + // Create some nodes, a user, etc. + $nodes = $this->trackerPostNodes(); + // Fetch the tracker page + $this->drupalGet('tracker/all'); + // Iterate through all nodes + foreach ($nodes['nodes'] as $node) { + // Assert the title is on the tracker page + $this->assertText($node->title, t('The node %title appears on the tracker page', array('%title' => $node->title))); + } + } + + function testTrackerMyRecentPostsComments() { + // Enable the comment and tracker modules + $this->drupalModuleEnable('comment'); + $this->drupalModuleEnable('tracker'); + // Create some nodes + $data = $this->trackerPostNodeComments(); + // Fetch the user's tracker page + $this->drupalGet('user/'. $data['user']->uid .'/track'); + // Iterate through all nodes with posts in them + foreach ($data['post'] as $node) { + $this->assertText($node->title, t('The node %title appears on the tracker page', array('%title' => $node->title))); + } + // Iterate through all nodes that don't have comments + foreach ($data['no_post'] as $node) { + $this->assertNoText($node->title, t('The node %title does not appear on the tracker page', array('%title' => $node->title))); + } + // Create some node authored by this user (not someone else) + $nodes = $this->drupalCreateNodes(); + // Reload the page + $this->drupalGet('user/'. $data['user']->uid .'/track'); + // Iterate through all of the nodes + foreach ($nodes as $node) { + $this->assertNoText($node->title, t('The node %title appears on the tracker page', array('%title' => $node->title))); + } + } + + function testTrackerNew() { + // Enable the comment and tracker modules + $this->drupalModuleEnable('comment'); + $this->drupalModuleEnable('tracker'); + // Create some nodes, a user, etc. + $data = $this->trackerPostNodes(); + $this->drupalGet('tracker'); + if (!$this->parse()) { + $this->fail(t('Could not parse')); + return; + } + $rows = $this->elements->xpath('//div[@id="tracker"]//tr/td[2]'); + foreach ($rows as $row) { + $this->assertTrue(isset($row->span), t('%title was marked as new', array('%title' => $this->xpathValue($row->xpath('./a'))))); + $this->trackerFetch((string)$row->a['href']); + } + $this->drupalGet('tracker'); + if (!$this->parse()) { + $this->fail(t('Could not parse')); + return; + } + $rows = $this->elements->xpath('//div[@id="tracker"]//tr/td[2]'); + foreach ($rows as $row) { + $this->assertFalse(isset($row->span), t('%title was not marked as new', array('%title' => $this->xpathValue($row->xpath('./a'))))); + } + $user = $this->createTrackerUser($data['type']); + $this->drupalLogin($user); + $this->drupalGet('user/'. $user->uid .'/track'); + if (!$this->parse()) { + $this->fail(t('Could not parse')); + return; + } + $rows = $this->elements->xpath('//div[@id="tracker"]//tr/td[2]'); + $i = 0; + $clicked_links = array(); + foreach ($rows as $row) { + $this->assertEqual($row->span, t('New'), t('%title was marked as new, for a different user', array('%title' => (string) $this->xpathValue($row->xpath('./a'))))); + if ($i % 2 == 1) { + $link = (string) $row->a['href']; + $this->trackerFetch($link); + $clicked_links[] = $link; + } + $i++; + } + $this->drupalGet('tracker'); + if (!$this->parse()) { + $this->fail(t('Could not parse')); + return; + } + $rows = $this->elements->xpath('//div[@id="tracker"]//tr/td[2]'); + foreach ($rows as $row) { + $link = (string) $row->a['href']; + if (in_array($link, $clicked_links)) { + $this->assertFalse((bool)$row->xpath('./span'), t('%title was not marked as new', array('%title' => $this->xpathValue($row->xpath('./a'))))); + } + else { + $this->assertTrue((bool)$row->xpath('./span'), t('%title was still marked as new', array('%title' => $this->xpathValue($row->xpath('./a'))))); + } + } + } + + function testTrackerNewComments() { + // Enable the comment and tracker modules + $this->drupalModuleEnable('comment'); + $this->drupalModuleEnable('tracker'); + // Create some nodes, a user, etc. + $data = $this->trackerPostNodes(); + $this->drupalGet('user/'. $data['user']->uid .'/track'); + if (!$this->parse()) { + $this->fail(t('Could not parse')); + return; + } + $rows = $this->elements->xpath('//div[@id="tracker"]//tr/td[2]'); + foreach ($rows as $row) { + $this->assertTrue((bool)$row->xpath('./span'), t('%title was marked as new', array('%title' => $this->xpathValue($row->xpath('./a'))))); + $this->trackerFetch((string) $row->a['href']); + } + $posted_nodes = $this->trackerPostComments($data['nodes'], $data['type']); + $node_titles = array(); + foreach ($posted_nodes['post'] as $node) { + $node_titles[$node->title] = TRUE; + } + foreach ($posted_nodes['no_post'] as $node) { + $node_titles[$node->title] = FALSE; + } + $this->drupalLogin($data['user']); + $this->drupalGet('tracker'); + if (!$this->parse()) { + $this->fail(t('Could not parse')); + return; + } + $rows = $this->elements->xpath('//div[@id="tracker"]//tr/td[1]/..'); + foreach ($rows as $row) { + $title = (string)$row->td[1]->a; + if (in_array($title, $node_titles)) { + if ($node_titles[$title] == TRUE) { + $this->assertTrue(isset($row->td[3]->a), t('%title has new replies', array('%title' => $title))); + $this->trackerFetch((string)$row->td[1]->a['href']); + } + else { + $this->assertFalse(isset($row->td[3]->a), t('%title doesn\'t have new replies', array('%title' => $title))); + } + } + } + + $this->drupalGet('tracker'); + if (!$this->parse()) { + $this->fail(t('Could not parse')); + return; + } + $rows = $this->elements->xpath('//div[@id="tracker"]//tr/td[1]/..'); + foreach ($rows as $row) { + + $this->assertFalse(isset($row->td[3]->a), t('%title doesn\'t have new replies', array('%title' => (string) $row->td[1]->a))); + } + } + + function trackerPostNodes($number = 4) { + // Create a content type + $type = $this->drupalCreateContentType(); + // Disable comment previews + $this->drupalVariableSet('comment_preview_'. $type->type, 0); + // Create a user + $user = $this->createTrackerUser($type); + // Log the user in + $this->drupalLogin($user); + // Create four nodes + $nodes = $this->drupalCreateNodes($number, array('type' => $type->type, 'uid' => $user->uid)); + // Return the nodes + return array('user' => $user, 'nodes' => $nodes, 'type' => $type); + } + + function trackerPostNodeComments() { + // Create some nodes + $nodes = $this->trackerPostNodes(10); + // Post comments on those nodes + return $this->trackerPostComments($nodes['nodes'], $nodes['type']); + } + + function trackerPostComments($nodes, $type, $separate_user = TRUE) { + // Set up a data array + $data = array(); + + if ($separate_user) { + // Set up a user in the data array + $data['user'] = $this->createTrackerUser($type); + // Log the user in + $this->drupalLogin($data['user']); + } + // Post comments on every other node + foreach ($nodes as $i => $node) { + // If $i is odd + if ($i % 2 == 1) { + // Post a comment + $this->drupalPost('comment/reply/'. $node->nid, array( + 'subject' => $this->randomName(8), + 'comment' => $this->randomName(8), + ), t('Save')); + // We posted a comment, so add it to $data['post'] + $data['post'][] = $node; + } + else { + // We didn't post a comemnt + $data['no_post'][] = $node; + } + } + return $data; + } + + function createTrackerUser($type) { + // Creates a user with the proper permissions to use the tracker + return $this->drupalCreateUser(array('access content', 'access comments', 'post comments', 'post comments without approval', 'create new '. $type->type .' content')); + } + + function trackerFetch($url) { + return $this->curlExec(array(CURLOPT_URL => 'http://'. $_SERVER['HTTP_HOST'] . (string) $url)); + } + + function xpathValue($xpath) { + if ($xpath) { + return (string) $xpath[0]['value']; + } + return NULL; + } + + function tearDown() { + parent::tearDown(); + } +} +