Skip to content

Commit 997b402

Browse files
committed
test(renamer): cover composer.json author replacements
Add test coverage for: - Author name and homepage replacements in composer.json - Saltus contributor injection when flag is set - Saltus contributor omission when flag is unset
1 parent 30887eb commit 997b402

1 file changed

Lines changed: 104 additions & 1 deletion

File tree

tests/Plugin/Renamer/PluginRenamerTest.php

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,109 @@ public function test_package_name_trims_leading_trailing_dashes(): void {
168168
$this->remove_dir( $source );
169169
}
170170

171+
public function test_build_zip_replaces_composer_author_and_homepage(): void {
172+
$source = $this->make_source_fixture( true );
173+
$output = tempnam( sys_get_temp_dir(), 'renamer-' );
174+
$identity = PluginIdentity::from_request(
175+
array_merge(
176+
PluginIdentity::defaults(),
177+
array(
178+
'plugin_name' => 'Acme Library',
179+
'plugin_slug' => 'acme-library',
180+
'main_file' => 'acme-library.php',
181+
'namespace_segment' => 'AcmeLibrary',
182+
'author' => 'Acme Inc',
183+
'author_uri' => 'https://acme.dev/',
184+
'prefix' => 'acme_library',
185+
)
186+
)
187+
);
188+
189+
$renamer = new PluginRenamer( $source );
190+
$renamer->build_zip( $identity, $output );
191+
192+
$zip = new ZipArchive();
193+
self::assertTrue( true === $zip->open( $output ) );
194+
195+
$contents = $zip->getFromName( 'acme-library/composer.json' );
196+
self::assertIsString( $contents );
197+
self::assertStringContainsString( '"name": "Acme Inc"', $contents );
198+
self::assertStringContainsString( '"homepage": "https://acme.dev/', $contents );
199+
self::assertStringNotContainsString( '"name": "Saltus"', $contents );
200+
self::assertStringNotContainsString( '"homepage": "https://saltus.dev', $contents );
201+
202+
$zip->close();
203+
@unlink( $output );
204+
$this->remove_dir( $source );
205+
}
206+
207+
public function test_build_zip_adds_saltus_contributor_when_flag_set(): void {
208+
$source = $this->make_source_fixture( true );
209+
$output = tempnam( sys_get_temp_dir(), 'renamer-' );
210+
$identity = PluginIdentity::from_request(
211+
array_merge(
212+
PluginIdentity::defaults(),
213+
array(
214+
'plugin_name' => 'Acme Library',
215+
'plugin_slug' => 'acme-library',
216+
'main_file' => 'acme-library.php',
217+
'namespace_segment' => 'AcmeLibrary',
218+
'author' => 'Acme Inc',
219+
'prefix' => 'acme_library',
220+
'saltus_contributor' => '1',
221+
)
222+
)
223+
);
224+
225+
$renamer = new PluginRenamer( $source );
226+
$renamer->build_zip( $identity, $output );
227+
228+
$zip = new ZipArchive();
229+
self::assertTrue( true === $zip->open( $output ) );
230+
231+
$contents = $zip->getFromName( 'acme-library/composer.json' );
232+
self::assertIsString( $contents );
233+
self::assertStringContainsString( '"name": "Saltus"', $contents );
234+
self::assertStringContainsString( '"name": "Acme Inc"', $contents );
235+
self::assertStringContainsString( '"email": "web@saltus.dev"', $contents );
236+
237+
$zip->close();
238+
@unlink( $output );
239+
$this->remove_dir( $source );
240+
}
241+
242+
public function test_build_zip_omits_saltus_contributor_when_flag_unset(): void {
243+
$source = $this->make_source_fixture( true );
244+
$output = tempnam( sys_get_temp_dir(), 'renamer-' );
245+
$identity = PluginIdentity::from_request(
246+
array_merge(
247+
PluginIdentity::defaults(),
248+
array(
249+
'plugin_name' => 'Acme Library',
250+
'plugin_slug' => 'acme-library',
251+
'main_file' => 'acme-library.php',
252+
'namespace_segment' => 'AcmeLibrary',
253+
'author' => 'Acme Inc',
254+
'prefix' => 'acme_library',
255+
)
256+
)
257+
);
258+
259+
$renamer = new PluginRenamer( $source );
260+
$renamer->build_zip( $identity, $output );
261+
262+
$zip = new ZipArchive();
263+
self::assertTrue( true === $zip->open( $output ) );
264+
265+
$contents = $zip->getFromName( 'acme-library/composer.json' );
266+
self::assertIsString( $contents );
267+
self::assertStringNotContainsString( '"name": "Saltus"', $contents );
268+
269+
$zip->close();
270+
@unlink( $output );
271+
$this->remove_dir( $source );
272+
}
273+
171274
public function test_package_name_falls_back_to_local_when_author_has_no_ascii(): void {
172275
$source = $this->make_source_fixture( true );
173276
$output = tempnam( sys_get_temp_dir(), 'renamer-' );
@@ -231,7 +334,7 @@ private function make_source_fixture( bool $with_composer = false ): string {
231334
if ( $with_composer ) {
232335
file_put_contents(
233336
$source . '/composer.json',
234-
"{\n\t\"name\": \"saltus/framework-demo\",\n\t\"type\": \"wordpress-plugin\"\n}\n"
337+
"{\n\t\"name\": \"saltus/framework-demo\",\n\t\"type\": \"wordpress-plugin\",\n\t\"homepage\": \"https://saltus.dev/\",\n\t\"authors\": [\n\t\t{\n\t\t\t\"name\": \"Saltus\",\n\t\t\t\"email\": \"web@saltus.dev\",\n\t\t\t\"homepage\": \"https://saltus.dev\"\n\t\t}\n\t]\n}\n"
235338
);
236339
}
237340

0 commit comments

Comments
 (0)