|
22 | 22 |
|
23 | 23 | namespace App\Tests\Controller;
|
24 | 24 |
|
| 25 | +use App\Entity\Parts\Part; |
| 26 | +use App\Entity\BulkInfoProviderImportJob; |
| 27 | +use App\Entity\BulkImportJobStatus; |
25 | 28 | use App\Entity\UserSystem\User;
|
26 | 29 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
27 | 30 | use Symfony\Component\HttpFoundation\Response;
|
@@ -111,6 +114,86 @@ public function testAccessControlForManage(): void
|
111 | 114 | );
|
112 | 115 | }
|
113 | 116 |
|
| 117 | + public function testStep2TemplateRendering(): void |
| 118 | + { |
| 119 | + $client = static::createClient(); |
| 120 | + $this->loginAsUser($client, 'admin'); |
| 121 | + |
| 122 | + $entityManager = $client->getContainer()->get('doctrine')->getManager(); |
| 123 | + |
| 124 | + // Use an existing part from test fixtures (ID 1 should exist) |
| 125 | + $partRepository = $entityManager->getRepository(Part::class); |
| 126 | + $part = $partRepository->find(1); |
| 127 | + |
| 128 | + if (!$part) { |
| 129 | + $this->markTestSkipped('Test part with ID 1 not found in fixtures'); |
| 130 | + } |
| 131 | + |
| 132 | + // Get the admin user for the createdBy field |
| 133 | + $userRepository = $entityManager->getRepository(User::class); |
| 134 | + $user = $userRepository->findOneBy(['name' => 'admin']); |
| 135 | + |
| 136 | + if (!$user) { |
| 137 | + $this->markTestSkipped('Admin user not found in fixtures'); |
| 138 | + } |
| 139 | + |
| 140 | + // Create a test job with search results that include source_field and source_keyword |
| 141 | + $job = new BulkInfoProviderImportJob(); |
| 142 | + $job->setCreatedBy($user); |
| 143 | + $job->setPartIds([$part->getId()]); |
| 144 | + $job->setStatus(BulkImportJobStatus::IN_PROGRESS); |
| 145 | + $job->setSearchResults([ |
| 146 | + [ |
| 147 | + 'part_id' => $part->getId(), |
| 148 | + 'search_results' => [ |
| 149 | + [ |
| 150 | + 'dto' => [ |
| 151 | + 'provider_key' => 'test_provider', |
| 152 | + 'provider_id' => 'TEST123', |
| 153 | + 'name' => 'Test Component', |
| 154 | + 'description' => 'Test component description', |
| 155 | + 'manufacturer' => 'Test Manufacturer', |
| 156 | + 'mpn' => 'TEST-MPN-123', |
| 157 | + 'provider_url' => 'https://example.com/test', |
| 158 | + 'preview_image_url' => null, |
| 159 | + '_source_field' => 'test_field', |
| 160 | + '_source_keyword' => 'test_keyword' |
| 161 | + ], |
| 162 | + 'localPart' => null |
| 163 | + ] |
| 164 | + ], |
| 165 | + 'errors' => [] |
| 166 | + ] |
| 167 | + ]); |
| 168 | + |
| 169 | + $entityManager->persist($job); |
| 170 | + $entityManager->flush(); |
| 171 | + |
| 172 | + // Test that step2 renders correctly with the search results |
| 173 | + $client->request('GET', '/tools/bulk-info-provider-import/step2/' . $job->getId()); |
| 174 | + |
| 175 | + // Follow any redirects (like locale redirects) |
| 176 | + if ($client->getResponse()->isRedirect()) { |
| 177 | + $client->followRedirect(); |
| 178 | + } |
| 179 | + |
| 180 | + $this->assertResponseStatusCodeSame(Response::HTTP_OK); |
| 181 | + |
| 182 | + // Verify the template rendered the source_field and source_keyword correctly |
| 183 | + $content = $client->getResponse()->getContent(); |
| 184 | + $this->assertStringContainsString('test_field', $content); |
| 185 | + $this->assertStringContainsString('test_keyword', $content); |
| 186 | + |
| 187 | + // Clean up - find by ID to avoid detached entity issues |
| 188 | + $jobId = $job->getId(); |
| 189 | + $entityManager->clear(); // Clear all entities |
| 190 | + $jobToRemove = $entityManager->find(BulkInfoProviderImportJob::class, $jobId); |
| 191 | + if ($jobToRemove) { |
| 192 | + $entityManager->remove($jobToRemove); |
| 193 | + $entityManager->flush(); |
| 194 | + } |
| 195 | + } |
| 196 | + |
114 | 197 | private function loginAsUser($client, string $username): void
|
115 | 198 | {
|
116 | 199 | $entityManager = $client->getContainer()->get('doctrine')->getManager();
|
|
0 commit comments