link.attribute.test 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. <?php
  2. /**
  3. * @file
  4. * Basic simpletests to test options on link module.
  5. */
  6. class LinkAttributeCrudTest extends DrupalWebTestCase {
  7. private $zebra;
  8. public $permissions = array(
  9. 'access content',
  10. 'administer content types',
  11. 'administer nodes',
  12. 'administer filters',
  13. 'access comments',
  14. 'post comments',
  15. 'skip comment approval',
  16. 'access administration pages',
  17. );
  18. public static function getInfo() {
  19. return array(
  20. 'name' => 'Link Attribute Tests',
  21. 'description' => 'Tests the field attributes, making sure they appear in various displayed situations.',
  22. 'group' => 'Link',
  23. );
  24. }
  25. function setup() {
  26. $this->zebra = 0;
  27. parent::setup('field_ui', 'link'); // was 'views'
  28. //$this->loginWithPermissions($this->permissions);
  29. // Create and login user.
  30. $account = $this->drupalCreateUser(array('administer content types'));
  31. $this->drupalLogin($account);
  32. }
  33. function createLink($url, $title, $attributes = array()) {
  34. return array(
  35. 'url' => $url,
  36. 'title' => $title,
  37. 'attributes' => $attributes,
  38. );
  39. }
  40. private function assertLinkOnNode($field_name, $link_value, $message = '', $group = 'Other') {
  41. $this->zebra++;
  42. $zebra_string = ($this->zebra % 2 == 0) ? 'even' : 'odd';
  43. $cssFieldLocator = 'field-'. str_replace('_', '-', $field_name);
  44. $this->assertPattern('@<div class="field field-type-link '. $cssFieldLocator .'".*<div class="field-item '. $zebra_string .'">\s*'. $link_value .'\s*</div>@is',
  45. $message,
  46. $group);
  47. }
  48. /**
  49. * A simple test that just creates a new node type, adds a link field to it, creates a new node of that type, and makes sure
  50. * that the node is being displayed.
  51. */
  52. function testBasic() {
  53. /*$this->acquireContentTypes(1);
  54. variable_set('node_options_'. $this->content_types[0]->name, array('status', 'promote'));*/
  55. $content_type_friendly = $this->randomName(20);
  56. $content_type_machine = strtolower($this->randomName(10));
  57. $title = $this->randomName(20);
  58. $this->drupalGet('admin/structure/types');
  59. // Create the content type.
  60. $this->clickLink(t('Add content type'));
  61. $edit = array (
  62. 'name' => $content_type_friendly,
  63. 'type' => $content_type_machine,
  64. );
  65. $this->drupalPost(NULL, $edit, t('Save and add fields'));
  66. $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
  67. // Now add a singleton field.
  68. $single_field_name_friendly = $this->randomName(20);
  69. $single_field_name_machine = strtolower($this->randomName(10));
  70. $single_field_name = 'field_'. $single_field_name_machine;
  71. $edit = array (
  72. 'fields[_add_new_field][label]' => $single_field_name_friendly,
  73. 'fields[_add_new_field][field_name]' => $single_field_name_machine,
  74. 'fields[_add_new_field][type]' => 'link_field',
  75. 'fields[_add_new_field][widget_type]' => 'link_field',
  76. );
  77. $this->drupalPost(NULL, $edit, t('Save'));
  78. // We'll go with the default settings for this run-through.
  79. $this->drupalPost(NULL, array(), t('Save field settings'));
  80. // Using all the default settings, so press the button.
  81. $this->drupalPost(NULL, array(), t('Save settings'));
  82. $this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
  83. // Somehow clicking "save" isn't enough, and we have to do a
  84. // node_types_rebuild().
  85. node_types_rebuild();
  86. menu_rebuild();
  87. $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
  88. $this->assertTrue($type_exists, 'The new content type has been created in the database.');
  89. $permission = 'create ' . $content_type_machine . ' content';
  90. $permission_edit = 'edit ' . $content_type_machine . ' content';
  91. // Reset the permissions cache.
  92. $this->checkPermissions(array($permission), TRUE);
  93. // Now that we have a new content type, create a user that has privileges
  94. // on the content type.
  95. $permissions = array_merge($this->permissions, array($permission));
  96. $account = $this->drupalCreateUser($permissions);
  97. $this->drupalLogin($account);
  98. // Go to page.
  99. $this->drupalGet('node/add/'. $content_type_machine);
  100. // Add a node.
  101. $edit = array(
  102. 'title' => $title,
  103. 'field_'. $single_field_name_machine. '[und][0][title]' => 'Link',
  104. 'field_'. $single_field_name_machine. '[und][0][url]' => 'http://www.drupal.org/',
  105. );
  106. $this->drupalPost(NULL, $edit, t('Save'));
  107. $this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title)));
  108. /*$field_settings = array(
  109. 'type' => 'link',
  110. 'widget_type' => 'link',
  111. 'type_name' => $this->content_types[0]->name,
  112. 'attributes' => array(), // <-- This is needed or we have an error.
  113. );
  114. $field = $this->createField($field_settings, 0);
  115. //$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
  116. $field_db_info = content_database_info($field);*/
  117. //$this->acquireNodes(2);
  118. /*$node = $this->drupalCreateNode(array('type' => $content_type_machine,
  119. 'promote' => 1));
  120. $test_nid = $node->nid;*/
  121. //$node = node_load($this->nodes[0]->nid);
  122. //$node->promote = 1; // We want this to show on front page for the teaser test.
  123. /*$this->assert('debug', print_r($node, TRUE), 'Debug');
  124. $node->{$single_field_name}['und'][0] = $this->createLink('http://www.example.com', 'Test Link');
  125. node_save($node);
  126. $this->assert('debug', print_r($node, TRUE), 'Debug');*/
  127. //$this->drupalGet('node/'. $test_nid .'/edit');
  128. $this->drupalGet('node/add/'. $content_type_machine);
  129. // lets add a node:
  130. $edit = array(
  131. 'title' => $title,
  132. 'field_' . $single_field_name_machine . '[und][0][url]' => 'http://www.example.com/',
  133. 'field_' . $single_field_name_machine . '[und][0][title]' => 'Display',
  134. );
  135. // Now we can fill in the second item in the multivalue field and save.
  136. $this->drupalPost(NULL, $edit, t('Save'));
  137. $this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $title)));
  138. $this->assertText('Display');
  139. //$this->assertText('http://www.example.com/');
  140. $this->assertLinkByHref('http://www.example.com');
  141. }
  142. private function createNodeType($content_type_machine, $content_type_friendly) {
  143. $this->drupalGet('admin/structure/types');
  144. // Create the content type.
  145. $this->clickLink(t('Add content type'));
  146. $edit = array (
  147. 'name' => $content_type_friendly,
  148. 'type' => $content_type_machine,
  149. );
  150. $this->drupalPost(NULL, $edit, t('Save and add fields'));
  151. $this->assertText(t('The content type @name has been added.', array('@name' => $content_type_friendly)));
  152. }
  153. private function createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine) {
  154. $edit = array (
  155. 'fields[_add_new_field][label]' => $single_field_name_friendly,
  156. 'fields[_add_new_field][field_name]' => $single_field_name_machine,
  157. 'fields[_add_new_field][type]' => 'link_field',
  158. 'fields[_add_new_field][widget_type]' => 'link_field',
  159. );
  160. $this->drupalPost(NULL, $edit, t('Save'));
  161. // We'll go with the default settings for this run-through.
  162. $this->drupalPost(NULL, array(), t('Save field settings'));
  163. // Using all the default settings, so press the button.
  164. $this->drupalPost(NULL, array(), t('Save settings'));
  165. $this->assertText(t('Saved @name configuration.', array('@name' => $single_field_name_friendly)));
  166. // Somehow clicking "save" isn't enough, and we have to do a
  167. // node_types_rebuild().
  168. node_types_rebuild();
  169. menu_rebuild();
  170. $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $content_type_machine))->fetchField();
  171. $this->assertTrue($type_exists, 'The new content type has been created in the database.');
  172. }
  173. function createNodeTypeUser($content_type_machine) {
  174. $permission = 'create ' . $content_type_machine . ' content';
  175. $permission_edit = 'edit ' . $content_type_machine . ' content';
  176. // Reset the permissions cache.
  177. $this->checkPermissions(array($permission), TRUE);
  178. // Now that we have a new content type, create a user that has privileges
  179. // on the content type.
  180. $permissions = array_merge($this->permissions, array($permission));
  181. $account = $this->drupalCreateUser($permissions);
  182. $this->drupalLogin($account);
  183. }
  184. function createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $title, $url, $node_title = '') {
  185. // Go to page.
  186. $this->drupalGet('node/add/'. $content_type_machine);
  187. if (!$node_title) {
  188. $node_title = $this->randomName(20);
  189. }
  190. $edit = array(
  191. 'title' => $node_title,
  192. );
  193. if ($url) {
  194. $edit['field_' . $single_field_name_machine . '[und][0][url]'] = $url;
  195. }
  196. if ($title) {
  197. $edit['field_' . $single_field_name_machine . '[und][0][title]'] = $title;
  198. }
  199. // Now we can fill in the second item in the multivalue field and save.
  200. $this->drupalPost(NULL, $edit, t('Save'));
  201. $this->assertText(t('@content_type_friendly @title has been created', array('@content_type_friendly' => $content_type_friendly, '@title' => $node_title)));
  202. }
  203. function testFormatterPlain() {
  204. $content_type_friendly = $this->randomName(20);
  205. $content_type_machine = strtolower($this->randomName(10));
  206. $this->createNodeType($content_type_machine, $content_type_friendly);
  207. // Now add a singleton field.
  208. $single_field_name_friendly = $this->randomName(20);
  209. $single_field_name_machine = strtolower($this->randomName(10));
  210. //$single_field_name = 'field_'. $single_field_name_machine;
  211. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  212. // Okay, now we want to make sure this display is changed:
  213. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  214. $edit = array(
  215. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  216. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
  217. );
  218. $this->drupalPost(NULL, $edit, t('Save'));
  219. $this->createNodeTypeUser($content_type_machine);
  220. $link_text = 'Display';
  221. $link_url = 'http://www.example.com/';
  222. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  223. $this->assertText($link_url);
  224. $this->assertNoText($link_text);
  225. $this->assertNoLinkByHref($link_url);
  226. }
  227. function testFormatterPlainWithQuerystring() {
  228. $content_type_friendly = $this->randomName(20);
  229. $content_type_machine = strtolower($this->randomName(10));
  230. $this->createNodeType($content_type_machine, $content_type_friendly);
  231. // Now add a singleton field.
  232. $single_field_name_friendly = $this->randomName(20);
  233. $single_field_name_machine = strtolower($this->randomName(10));
  234. //$single_field_name = 'field_'. $single_field_name_machine;
  235. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  236. // Okay, now we want to make sure this display is changed:
  237. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  238. $edit = array(
  239. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  240. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
  241. );
  242. $this->drupalPost(NULL, $edit, t('Save'));
  243. $this->createNodeTypeUser($content_type_machine);
  244. $link_text = 'Display';
  245. $link_url = 'http://www.example.com/?q=test';
  246. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  247. $this->assertText($link_url);
  248. $this->assertNoText($link_text);
  249. $this->assertNoLinkByHref($link_url);
  250. }
  251. function testFormatterPlainWithFragment() {
  252. $content_type_friendly = $this->randomName(20);
  253. $content_type_machine = strtolower($this->randomName(10));
  254. $this->createNodeType($content_type_machine, $content_type_friendly);
  255. // Now add a singleton field.
  256. $single_field_name_friendly = $this->randomName(20);
  257. $single_field_name_machine = strtolower($this->randomName(10));
  258. //$single_field_name = 'field_'. $single_field_name_machine;
  259. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  260. // Okay, now we want to make sure this display is changed:
  261. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  262. $edit = array(
  263. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  264. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_plain',
  265. );
  266. $this->drupalPost(NULL, $edit, t('Save'));
  267. $this->createNodeTypeUser($content_type_machine);
  268. $link_text = 'Display';
  269. $link_url = 'http://www.example.com/#test';
  270. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  271. $this->assertText($link_url);
  272. $this->assertNoText($link_text);
  273. $this->assertNoLinkByHref($link_url);
  274. }
  275. function testFormatterURL() {
  276. $content_type_friendly = $this->randomName(20);
  277. $content_type_machine = strtolower($this->randomName(10));
  278. $this->createNodeType($content_type_machine, $content_type_friendly);
  279. // Now add a singleton field.
  280. $single_field_name_friendly = $this->randomName(20);
  281. $single_field_name_machine = strtolower($this->randomName(10));
  282. //$single_field_name = 'field_'. $single_field_name_machine;
  283. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  284. // Okay, now we want to make sure this display is changed:
  285. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  286. $edit = array(
  287. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  288. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
  289. );
  290. $this->drupalPost(NULL, $edit, t('Save'));
  291. $this->createNodeTypeUser($content_type_machine);
  292. $link_text = 'Display';
  293. $link_url = 'http://www.example.com/';
  294. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  295. $this->assertNoText($link_text);
  296. $this->assertLinkByHref($link_url);
  297. }
  298. function testFormatterURLWithQuerystring() {
  299. $content_type_friendly = $this->randomName(20);
  300. $content_type_machine = strtolower($this->randomName(10));
  301. $this->createNodeType($content_type_machine, $content_type_friendly);
  302. // Now add a singleton field.
  303. $single_field_name_friendly = $this->randomName(20);
  304. $single_field_name_machine = strtolower($this->randomName(10));
  305. //$single_field_name = 'field_'. $single_field_name_machine;
  306. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  307. // Okay, now we want to make sure this display is changed:
  308. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  309. $edit = array(
  310. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  311. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
  312. );
  313. $this->drupalPost(NULL, $edit, t('Save'));
  314. $this->createNodeTypeUser($content_type_machine);
  315. $link_text = 'Display';
  316. $link_url = 'http://www.example.com/?q=test';
  317. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  318. $this->assertNoText($link_text);
  319. $this->assertLinkByHref($link_url);
  320. }
  321. function testFormatterURLWithAnchor() {
  322. $content_type_friendly = $this->randomName(20);
  323. $content_type_machine = strtolower($this->randomName(10));
  324. $this->createNodeType($content_type_machine, $content_type_friendly);
  325. // Now add a singleton field.
  326. $single_field_name_friendly = $this->randomName(20);
  327. $single_field_name_machine = strtolower($this->randomName(10));
  328. //$single_field_name = 'field_'. $single_field_name_machine;
  329. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  330. // Okay, now we want to make sure this display is changed:
  331. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  332. $edit = array(
  333. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  334. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_url',
  335. );
  336. $this->drupalPost(NULL, $edit, t('Save'));
  337. $this->createNodeTypeUser($content_type_machine);
  338. $link_text = 'Display';
  339. $link_url = 'http://www.example.com/#test';
  340. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  341. $this->assertNoText($link_text);
  342. $this->assertLinkByHref($link_url);
  343. }
  344. function testFormatterShort() {
  345. $content_type_friendly = $this->randomName(20);
  346. $content_type_machine = strtolower($this->randomName(10));
  347. $this->createNodeType($content_type_machine, $content_type_friendly);
  348. // Now add a singleton field.
  349. $single_field_name_friendly = $this->randomName(20);
  350. $single_field_name_machine = strtolower($this->randomName(10));
  351. //$single_field_name = 'field_'. $single_field_name_machine;
  352. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  353. // Okay, now we want to make sure this display is changed:
  354. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  355. $edit = array(
  356. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  357. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
  358. );
  359. $this->drupalPost(NULL, $edit, t('Save'));
  360. $this->createNodeTypeUser($content_type_machine);
  361. $link_text = 'Display';
  362. $link_url = 'http://www.example.com/';
  363. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  364. $this->assertText('Link');
  365. $this->assertNoText($link_text);
  366. $this->assertLinkByHref($link_url);
  367. }
  368. function testFormatterShortWithQuerystring() {
  369. $content_type_friendly = $this->randomName(20);
  370. $content_type_machine = strtolower($this->randomName(10));
  371. $this->createNodeType($content_type_machine, $content_type_friendly);
  372. // Now add a singleton field.
  373. $single_field_name_friendly = $this->randomName(20);
  374. $single_field_name_machine = strtolower($this->randomName(10));
  375. //$single_field_name = 'field_'. $single_field_name_machine;
  376. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  377. // Okay, now we want to make sure this display is changed:
  378. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  379. $edit = array(
  380. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  381. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
  382. );
  383. $this->drupalPost(NULL, $edit, t('Save'));
  384. $this->createNodeTypeUser($content_type_machine);
  385. $link_text = 'Display';
  386. $link_url = 'http://www.example.com/?q=test';
  387. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  388. $this->assertText('Link');
  389. $this->assertNoText($link_text);
  390. $this->assertLinkByHref($link_url);
  391. }
  392. function testFormatterShortWithFragment() {
  393. $content_type_friendly = $this->randomName(20);
  394. $content_type_machine = strtolower($this->randomName(10));
  395. $this->createNodeType($content_type_machine, $content_type_friendly);
  396. // Now add a singleton field.
  397. $single_field_name_friendly = $this->randomName(20);
  398. $single_field_name_machine = strtolower($this->randomName(10));
  399. //$single_field_name = 'field_'. $single_field_name_machine;
  400. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  401. // Okay, now we want to make sure this display is changed:
  402. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  403. $edit = array(
  404. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  405. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_short',
  406. );
  407. $this->drupalPost(NULL, $edit, t('Save'));
  408. $this->createNodeTypeUser($content_type_machine);
  409. $link_text = 'Display';
  410. $link_url = 'http://www.example.com/#test';
  411. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  412. $this->assertText('Link');
  413. $this->assertNoText($link_text);
  414. $this->assertLinkByHref($link_url);
  415. }
  416. function testFormatterLabel() {
  417. $content_type_friendly = $this->randomName(20);
  418. $content_type_machine = strtolower($this->randomName(10));
  419. $this->createNodeType($content_type_machine, $content_type_friendly);
  420. // Now add a singleton field.
  421. $single_field_name_friendly = $this->randomName(20);
  422. $single_field_name_machine = strtolower($this->randomName(10));
  423. //$single_field_name = 'field_'. $single_field_name_machine;
  424. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  425. // Okay, now we want to make sure this display is changed:
  426. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  427. $edit = array(
  428. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  429. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
  430. );
  431. $this->drupalPost(NULL, $edit, t('Save'));
  432. $this->createNodeTypeUser($content_type_machine);
  433. $link_text = 'Display';
  434. $link_url = 'http://www.example.com/';
  435. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  436. $this->assertNoText($link_text);
  437. $this->assertText($single_field_name_friendly);
  438. $this->assertLinkByHref($link_url);
  439. }
  440. function testFormatterLabelWithQuerystring() {
  441. $content_type_friendly = $this->randomName(20);
  442. $content_type_machine = strtolower($this->randomName(10));
  443. $this->createNodeType($content_type_machine, $content_type_friendly);
  444. // Now add a singleton field.
  445. $single_field_name_friendly = $this->randomName(20);
  446. $single_field_name_machine = strtolower($this->randomName(10));
  447. //$single_field_name = 'field_'. $single_field_name_machine;
  448. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  449. // Okay, now we want to make sure this display is changed:
  450. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  451. $edit = array(
  452. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  453. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
  454. );
  455. $this->drupalPost(NULL, $edit, t('Save'));
  456. $this->createNodeTypeUser($content_type_machine);
  457. $link_text = 'Display';
  458. $link_url = 'http://www.example.com/?q=test';
  459. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  460. $this->assertNoText($link_text);
  461. $this->assertText($single_field_name_friendly);
  462. $this->assertLinkByHref($link_url);
  463. }
  464. function testFormatterLabelWithFragment() {
  465. $content_type_friendly = $this->randomName(20);
  466. $content_type_machine = strtolower($this->randomName(10));
  467. $this->createNodeType($content_type_machine, $content_type_friendly);
  468. // Now add a singleton field.
  469. $single_field_name_friendly = $this->randomName(20);
  470. $single_field_name_machine = strtolower($this->randomName(10));
  471. //$single_field_name = 'field_'. $single_field_name_machine;
  472. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  473. // Okay, now we want to make sure this display is changed:
  474. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  475. $edit = array(
  476. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  477. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_label',
  478. );
  479. $this->drupalPost(NULL, $edit, t('Save'));
  480. $this->createNodeTypeUser($content_type_machine);
  481. $link_text = 'Display';
  482. $link_url = 'http://www.example.com/#test';
  483. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  484. $this->assertNoText($link_text);
  485. $this->assertText($single_field_name_friendly);
  486. $this->assertLinkByHref($link_url);
  487. }
  488. function testFormatterSeparate() {
  489. $content_type_friendly = $this->randomName(20);
  490. $content_type_machine = strtolower($this->randomName(10));
  491. $this->createNodeType($content_type_machine, $content_type_friendly);
  492. // Now add a singleton field.
  493. $single_field_name_friendly = $this->randomName(20);
  494. $single_field_name_machine = strtolower($this->randomName(10));
  495. //$single_field_name = 'field_'. $single_field_name_machine;
  496. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  497. // Okay, now we want to make sure this display is changed:
  498. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  499. $edit = array(
  500. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  501. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
  502. );
  503. $this->drupalPost(NULL, $edit, t('Save'));
  504. $this->createNodeTypeUser($content_type_machine);
  505. $link_text = $this->randomName(20);
  506. $link_url = 'http://www.example.com/';
  507. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  508. $this->assertText($link_text);
  509. $this->assertLink($link_url);
  510. $this->assertLinkByHref($link_url);
  511. }
  512. function testFormatterSeparateWithQuerystring() {
  513. $content_type_friendly = $this->randomName(20);
  514. $content_type_machine = strtolower($this->randomName(10));
  515. $this->createNodeType($content_type_machine, $content_type_friendly);
  516. // Now add a singleton field.
  517. $single_field_name_friendly = $this->randomName(20);
  518. $single_field_name_machine = strtolower($this->randomName(10));
  519. //$single_field_name = 'field_'. $single_field_name_machine;
  520. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  521. // Okay, now we want to make sure this display is changed:
  522. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  523. $edit = array(
  524. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  525. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
  526. );
  527. $this->drupalPost(NULL, $edit, t('Save'));
  528. $this->createNodeTypeUser($content_type_machine);
  529. $link_text = $this->randomName(20);
  530. $link_url = 'http://www.example.com/?q=test';
  531. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  532. $this->assertText($link_text);
  533. $this->assertLink('http://www.example.com/');
  534. $this->assertLinkByHref($link_url);
  535. }
  536. function testFormatterSeparateWithFragment() {
  537. $content_type_friendly = $this->randomName(20);
  538. $content_type_machine = strtolower($this->randomName(10));
  539. $this->createNodeType($content_type_machine, $content_type_friendly);
  540. // Now add a singleton field.
  541. $single_field_name_friendly = $this->randomName(20);
  542. $single_field_name_machine = strtolower($this->randomName(10));
  543. //$single_field_name = 'field_'. $single_field_name_machine;
  544. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  545. // Okay, now we want to make sure this display is changed:
  546. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  547. $edit = array(
  548. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  549. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_separate',
  550. );
  551. $this->drupalPost(NULL, $edit, t('Save'));
  552. $this->createNodeTypeUser($content_type_machine);
  553. $link_text = $this->randomName(20);
  554. $link_url = 'http://www.example.com/#test';
  555. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  556. $this->assertText($link_text);
  557. $this->assertLink('http://www.example.com/');
  558. $this->assertLinkByHref($link_url);
  559. }
  560. function testFormatterPlainTitle() {
  561. $content_type_friendly = $this->randomName(20);
  562. $content_type_machine = strtolower($this->randomName(10));
  563. $this->createNodeType($content_type_machine, $content_type_friendly);
  564. // Now add a singleton field.
  565. $single_field_name_friendly = $this->randomName(20);
  566. $single_field_name_machine = strtolower($this->randomName(10));
  567. //$single_field_name = 'field_'. $single_field_name_machine;
  568. $this->createSimpleLinkField($single_field_name_machine, $single_field_name_friendly, $content_type_machine);
  569. // Okay, now we want to make sure this display is changed:
  570. $this->drupalGet('admin/structure/types/manage/'. $content_type_machine .'/display');
  571. $edit = array(
  572. 'fields[field_'. $single_field_name_machine .'][label]' => 'above',
  573. 'fields[field_'. $single_field_name_machine .'][type]' => 'link_title_plain',
  574. );
  575. $this->drupalPost(NULL, $edit, t('Save'));
  576. $this->createNodeTypeUser($content_type_machine);
  577. $link_text = 'Display';
  578. $link_url = 'http://www.example.com/';
  579. $this->createNodeForTesting($content_type_machine, $content_type_friendly, $single_field_name_machine, $link_text, $link_url);
  580. $this->assertText($link_text);
  581. $this->assertNoText($link_url);
  582. $this->assertNoLinkByHref($link_url);
  583. }
  584. /**
  585. * This test sees that we can create a link field with a defined class, and make sure
  586. * that class displays properly when the link is displayed.
  587. */
  588. /*function testLinkWithClassOnField() {
  589. $this->acquireContentTypes(1);
  590. $field_settings = array(
  591. 'type' => 'link',
  592. 'widget_type' => 'link',
  593. 'type_name' => $this->content_types[0]->name,
  594. 'attributes' => array(
  595. 'class' => 'test-class',
  596. 'target' => 'default',
  597. 'rel' => FALSE,
  598. ),
  599. );
  600. $field = $this->createField($field_settings, 0);
  601. //$this->pass('<pre>'. print_r($field, TRUE) .'</pre>');
  602. $field_db_info = content_database_info($field);
  603. $this->acquireNodes(2);
  604. $node = node_load($this->nodes[0]->nid);
  605. $node->promote = 1; // We want this to show on front page for the teaser test.
  606. $node->{$field['field_name']}[0] = $this->createLink('http://www.example.com', 'Test Link');
  607. node_save($node);
  608. // Does this display on the node page?
  609. $this->drupalGet('node/'. $this->nodes[0]->nid);
  610. //$this->outputScreenContents('Link field with class', 'link_');
  611. $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
  612. // Does this display on the front page?
  613. $this->drupalGet('<front>');
  614. // reset the zebra!
  615. $this->zebra = 0;
  616. $this->assertLinkOnNode($field['field_name'], l('Test Link', 'http://www.example.com', array('attributes' => array('class' => 'test-class'))));
  617. }*/
  618. }