This repository was archived by the owner on Jan 5, 2018. It is now read-only.
  
  
  - 
                Notifications
    You must be signed in to change notification settings 
- Fork 13
added tests for replacing on image directly #9
          
     Open
      
      
            tassilogroeper
  wants to merge
  1
  commit into
  drupal-media:8.x-2.x
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
tassilogroeper:8.x-2.x
  
      
      
   
  
    
  
  
  
 
  
      
    base: 8.x-2.x
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -97,6 +97,33 @@ public function testReplaceFile() { | |
| // Test that Upload widget does not appear for non-local file. | ||
| $this->drupalGet('file/' . $file2->id() . '/edit'); | ||
| $this->assertNoFieldByName('files[replace_upload]'); | ||
| } | ||
|  | ||
| public function testReplaceImageFile() { | ||
| // Select the first image test file to use. | ||
| $original = $this->files['image'][1]; | ||
| $this->assertEqual($original->getFilename(), 'image-test-transparent-indexed.gif'); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add meaningful assert messages. This applies to the entire PR. | ||
|  | ||
| // Create a user with file edit permissions. | ||
| $user = $this->drupalCreateUser(array('bypass file access')); | ||
| $this->drupalLogin($user); | ||
|  | ||
| // Get the next text file to use as a replacement. | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that file is an image, not text. | ||
| $replacement = $this->files['image'][4]; | ||
| $this->assertEqual($replacement->getFilename(), 'image-test-no-transparency.gif'); | ||
|  | ||
| // Test that the file saves when uploading a replacement file. | ||
| $edit = array(); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally prefer short array syntax, but I am not strongly opposing old format either. :) | ||
| $edit['files[replace_upload]'] = drupal_realpath($replacement->getFileUri()); | ||
| $this->drupalPostForm('file/' . $original->id() . '/edit', $edit, t('Save')); | ||
| $this->assertText(t('@file has been updated.', array('@file' => $original->getFilename()))/*, 'File was updated with file upload.'*/); | ||
|  | ||
| // Re-load the file from the database. | ||
| /** @var \Drupal\file\FileInterface $file */ | ||
| $file = File::load($original->id()); | ||
|  | ||
| // Test how file properties changed after the file has been replaced. | ||
| $this->assertNotEqual($file->getSize(), $original->getSize(), 'Updated file size changed from previous file.'); | ||
| $this->assertEqual($file->getSize(), $replacement->getSize(), 'Updated file size does match the new file.'); | ||
| } | ||
| } | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a PHPDoc block.