| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: image_gallery.test,v 1.3 2009/08/08 13:32:53 joachim Exp $ 3 4 class ImageGalleryTest extends DrupalTestCase { 5 6 protected $web_user; 7 8 function get_info() { 9 return array('name' => t('Image Gallery tests'), 'desc' => t('Test Image Gallery module functionality.'), 'group' => 'Image'); 10 } 11 12 function setUp() { 13 parent::setUp(); 14 15 // User to create image galleries. 16 $this->web_user = $this->drupalCreateUserRolePerm(array('create images', 'view original images', 'edit own images', 'edit any images', 'administer image galleries')); 17 $this->drupalGet('logout'); 18 $this->drupalLoginUser($this->web_user); 19 } 20 21 function testBasic() { 22 $galleries_count = 2; 23 $images_count = 5; 24 $galleries = array(); 25 $images = array(); 26 $this->drupalVariableSet('image_images_per_page', $images_count); 27 28 $vid = _image_gallery_get_vid(); 29 30 // Create several galleries. 31 for ($i = 0; $i < $galleries_count; $i++) { 32 $galleries[] = $this->createGallery(); 33 } 34 35 // Create images for galleries. 36 $images_misc = file_scan_directory('misc', '.png'); 37 shuffle($images_misc); 38 $images_files = array_slice($images_misc, 0, $images_count); 39 for ($i = 0; $i < $images_count; $i++) { 40 $tid = $galleries[array_rand($galleries)]; 41 $edit = array( 42 'taxonomy[' . $vid . ']' => $tid, 43 'files[image]' => realpath($images_files[$i]->filename), 44 ); 45 $images[] = array( 46 'tid' => $tid, 47 'node' => $this->createImage($edit), 48 ); 49 } 50 51 // Test view the gallery. 52 foreach ($galleries as $tid) { 53 $this->drupalGet('image/tid/' . $tid); 54 foreach ($images as $image) { 55 if ($image['tid'] == $tid) { 56 $this->assertWantedRaw($image['node']->title, 'Gallery '. $tid .': image ' . $image['node']->title . ' displayed. %s'); 57 } 58 else { 59 $this->assertNoUnwantedRaw($image['node']->title, 'Gallery '. $tid .': image ' . $images['node']->title . ' not displayed. %s'); 60 } 61 } 62 } 63 64 // Delete the gallery. 65 // This don't work, so use general taxonomy function: 66 // $this->drupalPost('admin/content/image/edit/' . $terms[0]->tid, array(), 'Delete'); 67 foreach ($galleries as $tid) { 68 taxonomy_del_term($tid); 69 } 70 } 71 72 function createGallery($edit = array()) { 73 $defaults = array( 74 'name' => $this->randomName(), 75 'parent[0]' => 0, 76 ); 77 $edit = $edit + $defaults; 78 $this->drupalPost('admin/content/image/add', $edit, 'Submit'); 79 $this->assertWantedRaw(t('Created new gallery %term.', array('%term' => $edit['name'])), 'Image gallery created. %s'); 80 $terms = taxonomy_get_term_by_name($edit['name']); 81 return $terms[0]->tid; 82 } 83 84 function createImage($edit = array()) { 85 $defaults = array( 86 'title' => $this->randomName(), 87 'body' => $this->randomName(), 88 'files[image]' => realpath('misc' . DIRECTORY_SEPARATOR . 'druplicon.png'), 89 ); 90 $edit = $edit + $defaults; 91 $this->drupalPost('node/add/image', $edit, 'Save'); 92 $this->assertWantedRaw(t('@type %title has been created.', array('@type' => 'Image', '%title' => $edit['title'])), 'Image created. %s'); 93 if ($node = node_load(array('title' => $edit['title']))) { 94 $this->assertNotNull($node, 'Image found in database. %s'); 95 return $node; 96 } 97 return FALSE; 98 } 99 100 }
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 |