forked from GNUsocial/gnu-social
[TESTS] Move Media fixtures to their own file, for organization
This commit is contained in:
parent
74d1874991
commit
53f89ade85
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace App\DataFixtures;
|
namespace App\DataFixtures;
|
||||||
|
|
||||||
use App\Core\DB\DB;
|
|
||||||
use App\Core\GSFile;
|
|
||||||
use App\Core\VisibilityScope;
|
use App\Core\VisibilityScope;
|
||||||
use App\Entity\GroupInbox;
|
use App\Entity\GroupInbox;
|
||||||
use App\Entity\GSActor;
|
use App\Entity\GSActor;
|
||||||
@ -12,7 +10,6 @@ use App\Entity\LocalUser;
|
|||||||
use App\Entity\Note;
|
use App\Entity\Note;
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\Persistence\ObjectManager;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
use Symfony\Component\HttpFoundation\File\File;
|
|
||||||
|
|
||||||
class CoreFixtures extends Fixture
|
class CoreFixtures extends Fixture
|
||||||
{
|
{
|
||||||
@ -44,13 +41,5 @@ class CoreFixtures extends Fixture
|
|||||||
|
|
||||||
$manager->persist(GroupInbox::create(['group_id' => $local_entities['taken_group']->getGroupId(), 'activity_id' => $note->getId()]));
|
$manager->persist(GroupInbox::create(['group_id' => $local_entities['taken_group']->getGroupId(), 'activity_id' => $note->getId()]));
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
|
|
||||||
DB::setManager($manager);
|
|
||||||
$filepath = INSTALLDIR . '/tests/Media/sample-uploads/image.jpeg';
|
|
||||||
$copy_filepath = $filepath . '.copy';
|
|
||||||
copy($filepath, $copy_filepath);
|
|
||||||
$file = new File($copy_filepath, checkPath: true);
|
|
||||||
GSFile::sanitizeAndStoreFileAsAttachment($file);
|
|
||||||
$manager->flush();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/DataFixtures/MediaFixtures.php
Normal file
27
src/DataFixtures/MediaFixtures.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DataFixtures;
|
||||||
|
|
||||||
|
use App\Core\DB\DB;
|
||||||
|
use App\Core\GSFile;
|
||||||
|
use App\Util\Common;
|
||||||
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
use Symfony\Component\HttpFoundation\File\File;
|
||||||
|
|
||||||
|
class MediaFixtures extends Fixture
|
||||||
|
{
|
||||||
|
public function load(ObjectManager $manager)
|
||||||
|
{
|
||||||
|
DB::setManager($manager);
|
||||||
|
$actor = DB::findOneBy('local_user', ['nickname' => 'taken_user']);
|
||||||
|
$store = function (string $filepath, string $title) use ($actor) {
|
||||||
|
$copy_filepath = $filepath . '.copy';
|
||||||
|
copy($filepath, $copy_filepath);
|
||||||
|
$file = new File($copy_filepath, checkPath: true);
|
||||||
|
GSFile::validateAndStoreFileAsAttachment($file, dest_dir: Common::config('attachments', 'dir') . 'test/', title: $title, actor_id: $actor->getId());
|
||||||
|
};
|
||||||
|
$store(INSTALLDIR . '/tests/Media/sample-uploads/image.jpeg', '1x1 JPEG image title');
|
||||||
|
$manager->flush();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user