| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: image_attach.test,v 1.1 2010/01/10 17:33:50 joachim Exp $ 3 4 /** 5 * Test image functionality. 6 */ 7 class ImageAttachTestCase extends DrupalWebTestCase { 8 9 protected $user_admin; 10 protected $user_no_attach; 11 protected $user_no_create; 12 13 function getInfo() { 14 return array( 15 'name' => t('Image attach functionality'), 16 'description' => t('Test Image attach module functionality.'), 17 'group' => t('Image'), 18 ); 19 } 20 21 function setUp() { 22 parent::setUp('image', 'node', 'image_attach'); 23 24 // Enable attaching on story nodes 25 variable_set('image_attach_story', TRUE); 26 27 // User to create nodes etc. 28 $this->user_admin = $this->drupalCreateUser(array( 29 'create images', 'view original images', 'edit own images', 30 'create story content', 'edit any story content', 31 'administer content types', 32 'attach images', 33 )); 34 $this->drupalLogin($this->user_admin); 35 36 // Uploadable image. 37 $this->image = 'misc/druplicon.png'; 38 } 39 40 /** 41 * Verify that the module's settings appear in the correct places. 42 */ 43 function testSettings() { 44 $this->drupalGet('admin/content/node-type/story'); 45 $this->assertText(t('Image Attach settings'), t('Image attach settings displayed on the story type settings page.')); 46 47 $this->drupalGet('admin/content/node-type/image'); 48 $this->assertNoText(t('Image Attach settings'), t('Image attach settings are not available on the image type settings page.')); 49 } 50 51 /** 52 * Verify that on the form for new nodes the image attach form component is 53 * presented in the correct way (or indeed not at all) for the various 54 * combinations of permissions. 55 */ 56 function testAddNodeAttaching() { 57 // Create an image. 58 $edit = array( 59 'title' => $this->randomName(), 60 'body' => $this->randomName(), 61 'files[image]' => realpath($this->image), 62 ); 63 $this->drupalPost('node/add/image', $edit, t('Save')); 64 65 // Check existing image nodes either show or don't show as potential attachments, 66 // depending on the setting. 67 variable_set('image_attach_existing', FALSE); 68 $this->drupalGet('node/add/story'); 69 $this->assertNoFieldById('edit-iids', '', t("With 'Attached existing images' DISABLED, existing images selection box is NOT shown on a new node form.")); 70 71 variable_set('image_attach_existing', TRUE); 72 $this->drupalGet('node/add/story'); 73 $this->assertFieldById('edit-iids', '', t("With 'Attached existing images' enabled, existing images selection box is shown on a new node form.")); 74 75 // Check that a user who may attach images but not create them cannot see 76 // the upload part of the form 77 $this->user_no_create = $this->drupalCreateUser(array( 78 'attach images', 79 'create story content', 'edit any story content', 80 )); 81 $this->drupalLogin($this->user_no_create); 82 // ... with existing images disabled, no part of the form should be visible. 83 variable_set('image_attach_existing', FALSE); 84 $this->drupalGet('node/add/story'); 85 $this->assertNoText(t('Attached images'), t("With existing images DISABLED, a user without the 'create images' permission can NOT attach images at all.")); 86 87 // ... with exiting images enabled, they still can't upload. 88 variable_set('image_attach_existing', TRUE); 89 $this->drupalGet('node/add/story'); 90 $this->assertNoFieldById('edit-image', '', t("A user without the 'create images' permission can NOT upload a new image to attach.")); 91 92 // Check that a user who may not attach images cannot see 93 // any part of the form. 94 $this->user_no_attach = $this->drupalCreateUser(array( 95 'create story content', 'edit any story content', 96 )); 97 $this->drupalLogin($this->user_no_attach); 98 $this->drupalGet('node/add/story'); 99 $this->assertNoText(t('Attached images'), t("A user without the 'attach images' permission can NOT attach images at all.")); 100 } 101 102 /** 103 * Verify that on the form for existing nodes the image attach form component is 104 * presented in the correct way (or indeed not at all) for the various 105 * combinations of permissions. 106 */ 107 function testEditNodeAttaching() { 108 variable_set('image_attach_existing', TRUE); 109 110 // Create an image. 111 $edit = array( 112 'title' => $this->randomName(), 113 'body' => $this->randomName(), 114 'files[image]' => realpath($this->image), 115 ); 116 $this->drupalPost('node/add/image', $edit, t('Save')); 117 $attached_image_node = node_load(array('title' => $edit['title'])); 118 119 // Create a story, attaching the existing image node. 120 $edit = array( 121 'title' => $this->randomName(), 122 'body' => $this->randomName(), 123 'iids[]' => array($attached_image_node->nid), 124 ); 125 $this->drupalPost('node/add/story', $edit, t('Save')); 126 $story_node = node_load(array('title' => $edit['title'])); 127 128 // file_put_contents('DEBUGstory.html', $this->drupalGetContent()); 129 /* 130 // TODO: test images are attached properly whether existing or new files. 131 $this->drupalGet('node/' . $story_node->nid); 132 $this->assertPattern('@<img[^>]+?' . $image_node->images['thumbnail'] . '[^>]+?>@', t('Image thumbnail displayed on the story node page.')); 133 */ 134 135 // Check that with existing images disabled 136 variable_set('image_attach_existing', FALSE); 137 // Create an UNATTACHED image. 138 $edit = array( 139 'title' => $this->randomName(), 140 'body' => $this->randomName(), 141 'files[image]' => realpath($this->image), 142 ); 143 $this->drupalPost('node/add/image', $edit, t('Save')); 144 $free_image_node = node_load(array('title' => $edit['title'])); 145 146 // TODO: test that only attached nodes are presented in the field -- ie that 147 // $free_image_node is not available as an option. 148 // NO IDEA how to do this in simpletest. 149 /* 150 $this->drupalGet('node/' . $story_node->nid); 151 $this->assertFalse($this->setField('iids[]', $free_image_node->title)); 152 */ 153 } 154 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |