I've created tests for Simpletest for Image Attach contrib module.

Comments

vladimir.dolgopolov’s picture

Status: Active » Needs review

There is a problem: Can't upload attached images

There are 2 patches in Fix bugs in hook_nodeapi for image_attach:

  1. static variable
  2. no static variable

The first patch works, the second fails the test.

vladimir.dolgopolov’s picture

Forgot the test.

drewish’s picture

Status: Needs review » Needs work

still haven't gotten the test attached :(

vladimir.dolgopolov’s picture

Strange enough. I cannpt attach the test file.
So I put it here.


class ImageAttachTest extends DrupalTestCase {
  protected $web_user;
  protected $image;

  function get_info() {
    return array('name' => t('Image Attach tests'), 'desc' => t('Test Image Attach module functionality.'), 'group' => 'Image');
  }

  function setUp() {
    parent::setUp();

    // User to create images and pages.
    $this->web_user = $this->drupalCreateUserRolePerm(array('create images', 'view original images', 'edit own images', 'edit images', 'create page content', 'edit own page content'));
    $this->drupalGet('logout');
    $this->drupalLoginUser($this->web_user);
    
    // Uploadable image
    $this->image = 'misc' . DIRECTORY_SEPARATOR . 'druplicon.png';
    
    // Enable attach images to Page.
    $this->drupalVariableSet('image_attach_page', 1);
    $this->drupalVariableSet('image_attach_size_body_page', 'thumbnail');
    $this->drupalVariableSet('image_attach_size_teaser_page', 'thumbnail');
    $this->drupalVariableSet('image_attach_weight_body_page', 0);
    $this->drupalVariableSet('image_attach_weight_teaser_page', 0);
  }

  function testAttachExistingImage() {
    $this->drupalVariableSet('image_attach_existing', 1);
    
    // Create an image.
    $edit_image = array(
      'title' => $this->randomName(),
      'body' => $this->randomName(),
      'files[image]' => realpath($this->image),
    );
    $this->drupalPost('node/add/image', $edit_image, 'Save');
    $this->assertWantedRaw(t('@type %title has been created.', array('@type' => 'Image', '%title' => $edit_image['title'])), 'Image created. %s');
    $node_image = node_load(array('title' => $edit_image['title']));
    $this->assertNotNull($node_image, 'Image found in database. %s');
    
    // Create a Page
    $edit_page = array(
      'title' => $this->randomName(),
      'body' => $this->randomName(),
      'iid' => $node_image->nid,
    );
    $this->drupalPost('node/add/page', $edit_page, 'Save');
    $this->assertWantedRaw(t('!post %title has been created.', array ('!post' => 'Page', '%title' => $edit_page['title'])), 'Page created');
    $node_page = node_load(array('title' => $edit_page['title']));
    $this->assertNotNull($node_page, 'Page found in database.');

    // Display an image.
    $this->assertWantedPattern('|<img[^>]+?' . $node_image->images['thumbnail'] . '[^>]+?'.'>|', $this->drupalGetContent(), 'Image is on the page. %s');
    $this->assertTrue(file_exists($node_image->images['thumbnail']), 'Image thumbnail exists. %s');
  }
  
  function testAttachUploadImage() {
    // Create a Page
    $edit_page = array(
      'title' => $this->randomName(),
      'body' => $this->randomName(),
      'files[image]' => realpath($this->image),
      'image_title' => $this->randomName(),    
    );
    $this->drupalPost('node/add/page', $edit_page, 'Save');
    $this->assertWantedRaw(t('!post %title has been created.', array ('!post' => 'Page', '%title' => $edit_page['title'])), 'Page created');
    $node_page = node_load(array('title' => $edit_page['title']));
    $this->assertNotNull($node_page, 'Page found in database.');

    $node_image = node_load($node_page->iid);
    $this->assertNotNull($node_image, 'Image found in database.');
    
    // Display an image.
    $this->assertWantedPattern('|<img[^>]+?' . $node_image->images['thumbnail'] . '[^>]+?'.'>|', $this->drupalGetContent(), 'Image is on the page. %s');
    $this->assertTrue(file_exists($node_image->images['thumbnail']), 'Image thumbnail exists. %s');
  }
}
drewish’s picture

Tried running that and got:
Image thumbnail exists. Expected true, got [Boolean: false] at [/Users/amorton/Sites/d6/sites/all/modules/image/tests/image_attach.test line 77]

sun’s picture

Status: Needs work » Closed (won't fix)

Bummer. I would have loved to see some tests for Image Attach module.

Sorry, without further information this issue can only be marked as won't fix.

random_’s picture

vladimir, what does drewish's output mean?