DuplicatingTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A should_duplicate_the_source_post_meta_to_the_destination_post() 0 45 3
1
<?php
2
3
namespace lloc\Msls\ContentImport\Importers\PostMeta;
4
5
6
use lloc\Msls\ContentImport\TestCase;
7
8
class DuplicatingTest extends TestCase {
9
	/**
10
	 * It should duplicate the source post meta to the destination post
11
	 *
12
	 * @test
13
	 */
14
	public function should_duplicate_the_source_post_meta_to_the_destination_post() {
15
		list( $import_coordinates, $logger, $relations, $dest_post_data ) = $this->setup_source_and_dest();
16
		$source_post_id = $import_coordinates->source_post_id;
17
		$dest_post_id   = $import_coordinates->dest_post_id;
18
19
		$obj = new Duplicating( $import_coordinates, $logger->reveal(), $relations->reveal() );
20
21
		switch_to_blog( $import_coordinates->source_blog_id );
22
		update_post_meta( $source_post_id, 'foo', 'bar' );
23
		update_post_meta( $source_post_id, 'bar', [ 23, 89 ] );
24
		add_post_meta( $source_post_id, 'multi', 'one' );
25
		add_post_meta( $source_post_id, 'multi', 'two' );
26
		$source_post_meta = get_post_meta( $source_post_id );
27
		switch_to_blog( $import_coordinates->dest_blog_id );
28
		update_post_meta( $dest_post_id, 'foo', 'not-bar' );
29
		update_post_meta( $dest_post_id, 'multi', 'another-value' );
30
		$dest_post_meta = get_post_meta( $import_coordinates->dest_post_id );
31
		add_filter( 'msls_content_import_post_meta_blacklist', function ( array $meta ) {
32
			$meta[] = 'foo';
33
34
			return $meta;
35
		} );
36
37
		restore_current_blog();
38
39
		$imported_fields    = $obj->filter_post_meta( $source_post_meta );
40
		$meta_to_import     = array_intersect_key( $source_post_meta, $imported_fields );
41
		$meta_not_to_import = array_diff_key( $dest_post_meta, $imported_fields );
42
43
		$mutated_data = $obj->import( $dest_post_data );
44
45
		$this->assertEqualSets( $dest_post_data, $mutated_data );
46
47
		switch_to_blog( $import_coordinates->dest_blog_id );
48
		$mutated_meta = get_post_meta( $import_coordinates->dest_post_id );
49
		restore_current_blog();
50
51
		foreach ( $meta_to_import as $field => $value ) {
52
			$this->assertEquals( $value, $mutated_meta[ $field ] );
53
		}
54
55
		foreach ( $meta_not_to_import as $field => $value ) {
56
			$this->assertEquals( $dest_post_meta[ $field ], $mutated_meta[ $field ] );
57
		}
58
	}
59
}
60