Elgg\EntityIconServiceTest::testEmptySizeConfigSavesUnmodifiedVersion PHP Метод

testEmptySizeConfigSavesUnmodifiedVersion() публичный Метод

    function testEmptySizeConfigSavesUnmodifiedVersion()
    {
        $this->hooks->registerHandler('entity:cover:sizes', 'object', array($this, 'getCoverSizes'));
        $service = $this->createService();
        $file = new \ElggFile();
        $file->owner_guid = 1;
        $file->setFilename('600x300.jpg');
        $file->mimetype = 'image/jpeg';
        $service->saveIconFromElggFile($this->entity, $file, 'cover');
        // original file should stay where it is
        $this->assertTrue($file->exists());
        $this->assertTrue($service->hasIcon($this->entity, 'medium', 'cover'));
        $this->assertTrue($service->hasIcon($this->entity, 'original', 'cover'));
        $medium = $service->getIcon($this->entity, 'original', 'cover');
        $medium_bytes = file_get_contents($medium->getFilenameOnFilestore());
        $source_bytes = file_get_contents($file->getFilenameOnFilestore());
        // crop with coordinates
        $service->saveIconFromElggFile($this->entity, $file, 'cover', ['x1' => 10, 'y1' => 10, 'x2' => 110, 'y2' => 110]);
        // source file should stay where it is
        $this->assertTrue($file->exists());
        $this->assertTrue($service->hasIcon($this->entity, 'medium', 'cover'));
        $this->assertTrue($service->hasIcon($this->entity, 'original', 'cover'));
        // original should remain the same
        $this->assertEquals($source_bytes, file_get_contents($service->getIcon($this->entity, 'original', 'cover')->getFilenameOnFilestore()));
        // medium should have been cropped
        $this->assertNotEquals($medium_bytes, file_get_contents($service->getIcon($this->entity, 'medium', 'cover')->getFilenameOnFilestore()));
    }