public function testCanSaveIconWithCroppingCoordinates()
{
$service = $this->createService();
$file = new \ElggFile();
$file->owner_guid = 1;
$file->setFilename('600x300.jpg');
$file->mimetype = 'image/jpeg';
$service->saveIconFromElggFile($this->entity, $file);
// original file should stay where it is
$this->assertTrue($file->exists());
$this->assertTrue($service->hasIcon($this->entity, 'master'));
$this->assertTrue($service->hasIcon($this->entity, 'large'));
$this->assertTrue($service->hasIcon($this->entity, 'medium'));
$this->assertTrue($service->hasIcon($this->entity, 'small'));
$this->assertTrue($service->hasIcon($this->entity, 'tiny'));
$this->assertTrue($service->hasIcon($this->entity, 'topbar'));
$master = $service->getIcon($this->entity, 'master');
$master_bytes = file_get_contents($master->getFilenameOnFilestore());
$medium = $service->getIcon($this->entity, 'medium');
$medium_bytes = file_get_contents($medium->getFilenameOnFilestore());
// recrop from master with coordinates
$service->saveIconFromElggFile($this->entity, $master, 'icon', ['x1' => 10, 'y1' => 10, 'x2' => 110, 'y2' => 110]);
// original file should stay where it is
$this->assertTrue($file->exists());
$this->assertTrue($service->hasIcon($this->entity, 'master'));
$this->assertTrue($service->hasIcon($this->entity, 'large'));
$this->assertTrue($service->hasIcon($this->entity, 'medium'));
$this->assertTrue($service->hasIcon($this->entity, 'small'));
$this->assertTrue($service->hasIcon($this->entity, 'tiny'));
$this->assertTrue($service->hasIcon($this->entity, 'topbar'));
// master should remain the same
$this->assertEquals($master_bytes, file_get_contents($service->getIcon($this->entity, 'master')->getFilenameOnFilestore()));
// medium should have been cropped
$this->assertNotEquals($medium_bytes, file_get_contents($service->getIcon($this->entity, 'medium')->getFilenameOnFilestore()));
}