/[drupal]/contributions/modules/weblinks/weblinks.test
ViewVC logotype

Contents of /contributions/modules/weblinks/weblinks.test

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Mon Jul 20 16:52:34 2009 UTC (4 months, 1 week ago) by nancyw
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +138 -0 lines
File MIME type: text/x-php
Update HEAD to start 7.x
1 <?php
2 // $Id: weblinks.test,v 1.1.2.6 2009/06/30 22:57:20 nancyw Exp $
3 /**
4 * @file
5 * Define test cases for the Web Links module
6 */
7 class WeblinksTestCase extends DrupalWebTestCase {
8 /**
9 * Implementation of getInfo().
10 */
11 public static function getInfo() {
12 return array(
13 // 'name' should start with what is being tested (menu item) followed by what
14 // about it is being tested (creation/deletion).
15 'name' => t('Weblinks tests'),
16 // 'description' should be one or more complete sentences
17 // explaining the test.
18 'description' => t('Test Weblinks module.'),
19 // 'group' should be a logical grouping of test cases, like a category.
20 // Suggestion: Use the name of the module to be tested.
21 'group' => t('Weblinks'),
22 );
23 }
24
25 /**
26 * Implementation of setUp().
27 */
28 function setUp() {
29 // This installs the Weblinks module, which is the module this suite is testing.
30 parent::setUp('weblinks', 'help');
31 // module_disable(array('taxonomy'));
32
33 // Make sure "Powered by" and "Navigation" blocks are turned off for performance.
34 db_query("UPDATE {blocks} SET status=0 WHERE (module='system' AND delta=0) OR (module='user' AND delta=1)");
35
36 // Turn off "submitted by."
37 $theme_settings = variable_get('theme_settings', array());
38 $theme_settings['toggle_node_info_weblinks'] = 0;
39 variable_set('theme_settings', $theme_settings);
40 }
41
42 /**
43 * Implementation of tearDown().
44 */
45 function tearDown() {
46 // Perform any clean-up tasks.
47
48 // The last thing a tearDown() method should always do is call its parent tearDown() method.
49 parent::tearDown();
50 }
51
52 /**
53 * One-sentence description of test.
54 */
55 function testWeblinksCreate() {
56 // Prepare a user to do the stuff.
57 $user = $this->drupalCreateUser(array('access content', 'access web links', 'create weblinks', 'edit own weblinks'));
58 $this->drupalLogin($user);
59
60 $settings = array(
61 'type' => 'weblinks',
62 'title' => 'A sample link',
63 'url' => 'http://www.example.com',
64 'weight' => 0,
65 'promote' => 1,
66 'status' => 1,
67 );
68 $link1 = $this->drupalCreateNode($settings);
69 $settings = array(
70 'type' => 'weblinks',
71 'title' => 'Drupal Community',
72 'url' => 'http://drupal.org',
73 'weight' => 0,
74 'promote' => 0,
75 'status' => 0,
76 );
77 $link2 = $this->drupalCreateNode($settings);
78 $count_nodes = db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE type='weblinks'"));
79 $this->assertEqual($count_nodes, 2, t('Nodes found in the database.'), 'Basic');
80 $count_links = db_result(db_query("SELECT COUNT(nid) FROM {weblinks}"));
81 $this->assertEqual($count_links, 2, t('Links found in the database.'), 'Basic');
82 $count_unpub = db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE type='weblinks' AND status=0"));
83 $this->assertEqual($count_unpub, 1, t('Unpublished links found in the database.'), 'Basic');
84
85 // Now do a list.
86 $content = $this->drupalGet('node');
87 // $this->pass(check_plain($content));
88 $this->assertText($link1->title, t('Node is promoted to the home page.'), 'Basic');
89
90 // Now do a list.
91 $content = $this->drupalGet('weblinks');
92 // $this->pass(check_plain($content));
93 $this->assertEqual($link1->is_new, 1, t('Link node created.'), 'Basic');
94 $this->assertText($link1->title, t('Node title appears on the list.'), 'Basic');
95 $this->assertNoText($link2->title, t('Unpublished node does not appear on the list.'), 'Basic');
96 $this->assertNoText(t('There are no weblinks to display yet.'), t('No empty list message.'), 'Basic');
97 $this->assertNoText(t('Weblinks settings'), t('Settings link not displayed.'), 'Basic');
98 $this->assertText(t('Add a new link'), t('"Add new" link displayed.'), 'Basic');
99 $this->assertText(t('Unclassified'), t('Unclassified group displayed.'), 'Basic');
100 $this->assertText($user->name, t('User name displayed.'), 'Basic');
101 $link1_shouldbe = '<a href="http://www.example.com" target="_blank" title="A sample link">http://www.example.com</a>';
102 $this->assertRaw($link1_shouldbe, t('URL displayed in URL mode.'), 'Basic');
103
104 // Switch mode to "redirect."
105 variable_set('weblinks_redirect', TRUE);
106 $link1_shouldbe = '<a href="/weblinks/goto/'. $link1->nid .'" target="_blank" title="A sample link">http://www.example.com</a>';
107 $content = $this->drupalGet('weblinks');
108 // $this->pass(check_plain($content));
109 $this->assertRaw($link1_shouldbe, t('URL displayed in Redirect mode.'), 'Basic');
110
111 $check = db_result(db_query("SELECT url FROM {weblinks} WHERE nid=%d", $link1->nid));
112 $this->assertEqual($link1->url, $check, t('URL successfully stored.'), 'Basic');
113
114 // Let's look at the settings.
115 // First let's make sure the current user can't admin.
116 $this->drupalGet('admin/settings/weblinks');
117 $this->assertResponse(403, t('Access is denied on the administration page.'), 'Basic');
118
119 // Prepare a user to do the stuff.
120 $user = $this->drupalCreateUser(array('access content', 'access web links', 'administer weblinks'));
121 $this->drupalLogin($user);
122
123 // Make sure the settings link shows up now.
124 $this->drupalGet('weblinks');
125 $this->assertText(t('Weblinks settings'), t('Settings link available.'), 'Basic');
126
127 // Group settings need to show at least unclassified and unpublished.
128 $this->drupalGet('admin/settings/weblinks/group');
129 $this->assertResponse(200, t('Access is granted on the administration page.'), 'Settings');
130 $this->assertText('Show Unclassified', t('Group settings includes "Unclassified".'), 'Settings');
131 $this->assertText('Show Unpublished', t('Group settings includes "Unpublished".'), 'Settings');
132
133 // Check settings should be turned off.
134 $this->drupalGet('admin/settings/weblinks/checker');
135 $this->assertFieldByName('weblinks_checker_enabled', 0, t('Checker disabled.'), 'Settings');
136 }
137
138 }

  ViewVC Help
Powered by ViewVC 1.1.2