You are here

function ImageGalleryTest::testBasic in Image 7

Same name and namespace in other branches
  1. 6 contrib/image_gallery/tests/image_gallery.test \ImageGalleryTest::testBasic()

File

contrib/image_gallery/tests/image_gallery.test, line 20

Class

ImageGalleryTest

Code

function testBasic() {
  $galleries_count = 2;
  $images_count = 5;
  $galleries = array();
  $images = array();
  $this
    ->drupalVariableSet('image_images_per_page', $images_count);
  $vid = _image_gallery_get_vid();

  // Create several galleries.
  for ($i = 0; $i < $galleries_count; $i++) {
    $galleries[] = $this
      ->createGallery();
  }

  // Create images for galleries.
  $images_misc = file_scan_directory('misc', '.png');
  shuffle($images_misc);
  $images_files = array_slice($images_misc, 0, $images_count);
  for ($i = 0; $i < $images_count; $i++) {
    $tid = $galleries[array_rand($galleries)];
    $edit = array(
      'taxonomy[' . $vid . ']' => $tid,
      'files[image]' => realpath($images_files[$i]->filename),
    );
    $images[] = array(
      'tid' => $tid,
      'node' => $this
        ->createImage($edit),
    );
  }

  // Test view the gallery.
  foreach ($galleries as $tid) {
    $this
      ->drupalGet('image/tid/' . $tid);
    foreach ($images as $image) {
      if ($image['tid'] == $tid) {
        $this
          ->assertWantedRaw($image['node']->title, 'Gallery ' . $tid . ': image ' . $image['node']->title . ' displayed. %s');
      }
      else {
        $this
          ->assertNoUnwantedRaw($image['node']->title, 'Gallery ' . $tid . ': image ' . $images['node']->title . ' not displayed. %s');
      }
    }
  }

  // Delete the gallery.
  // This don't work, so use general taxonomy function:
  // $this->drupalPost('admin/content/image/edit/' . $terms[0]->tid, array(), 'Delete');
  foreach ($galleries as $tid) {
    taxonomy_del_term($tid);
  }
}