1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace lloc\Msls\ContentImport; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use lloc\Msls\MslsOptions; |
7
|
|
|
use Prophecy\Argument; |
8
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
9
|
|
|
|
10
|
|
|
class RelationsTest extends \Msls_UnitTestCase { |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var \lloc\Msls\ContentImport\ImportCoordinates |
14
|
|
|
*/ |
15
|
|
|
public $import_coordinates; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @test |
19
|
|
|
* it should be instantiatable |
20
|
|
|
*/ |
21
|
|
|
public function it_should_be_instantiatable() { |
22
|
|
|
$sut = $this->make_instance(); |
23
|
|
|
|
24
|
|
|
$this->assertInstanceOf( Relations::class, $sut ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return Relations |
29
|
|
|
*/ |
30
|
|
|
private function make_instance() { |
31
|
|
|
return new Relations( $this->import_coordinates->reveal() ); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function test_merge() { |
35
|
|
|
$creator = $this->prophesize( MslsOptions::class ); |
36
|
|
|
$dest_lang = 'de_DE'; |
37
|
|
|
$obj_1 = $this->make_instance(); |
38
|
|
|
$obj_2 = $this->make_instance(); |
39
|
|
|
|
40
|
|
|
$obj_1->should_create( $creator->reveal(), $dest_lang, $this->factory->post->create() ); |
41
|
|
|
$obj_1->should_create( $creator->reveal(), $dest_lang, $this->factory->post->create() ); |
42
|
|
|
$obj_1->should_create( $creator->reveal(), $dest_lang, $this->factory->post->create() ); |
43
|
|
|
|
44
|
|
|
$this->assertCount( 3, $obj_1->get_data() ); |
45
|
|
|
|
46
|
|
|
$obj_2->should_create( $creator->reveal(), $dest_lang, $this->factory->post->create() ); |
47
|
|
|
$obj_2->should_create( $creator->reveal(), $dest_lang, $this->factory->post->create() ); |
48
|
|
|
$obj_2->should_create( $creator->reveal(), $dest_lang, $this->factory->post->create() ); |
49
|
|
|
|
50
|
|
|
$this->assertCount( 3, $obj_2->get_data() ); |
51
|
|
|
|
52
|
|
|
$obj_1->merge( $obj_2 ); |
53
|
|
|
|
54
|
|
|
$this->assertCount( 6, $obj_1->get_data() ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function test_create() { |
58
|
|
|
$source_lang = 'it_IT'; |
59
|
|
|
$dest_lang = 'de_DE'; |
60
|
|
|
$post_ids = $this->factory->post->create_many( 3 ); |
61
|
|
|
list( $creator_1, $creator_2, $creator_3 ) = array_map( function ( ObjectProphecy $c ) use ( $source_lang, $dest_lang, $post_ids ) { |
62
|
|
|
static $i; |
63
|
|
|
$i = $i === null ? 0 : ++$i; |
64
|
|
|
|
65
|
|
|
$c->save( [ $dest_lang => $post_ids[ $i ] ] )->shouldBeCalled(); |
66
|
|
|
$c->get_arg( Argument::type( 'int' ), $post_ids[ $i ] )->willReturn( $post_ids[ $i ] ); |
67
|
|
|
|
68
|
|
|
return $c; |
69
|
|
|
}, [ |
70
|
|
|
$this->prophesize( MslsOptions::class ), |
71
|
|
|
$this->prophesize( MslsOptions::class ), |
72
|
|
|
$this->prophesize( MslsOptions::class ), |
73
|
|
|
] ); |
74
|
|
|
$inverted = []; |
75
|
|
|
add_filter( 'msls_content_import_relation_local_to_source_create', function ( $_, $local_id, $source_id ) use ( &$inverted ) { |
|
|
|
|
76
|
|
|
$inverted[ ] = $local_id; |
77
|
|
|
return true; |
78
|
|
|
}, 10, 3 ); |
79
|
|
|
|
80
|
|
|
$obj = $this->make_instance(); |
81
|
|
|
|
82
|
|
|
$obj->should_create( $creator_1->reveal(), $dest_lang, $post_ids[0] ); |
83
|
|
|
$obj->should_create( $creator_2->reveal(), $dest_lang, $post_ids[1] ); |
84
|
|
|
$obj->should_create( $creator_3->reveal(), $dest_lang, $post_ids[2] ); |
85
|
|
|
|
86
|
|
|
$obj->create(); |
87
|
|
|
|
88
|
|
|
$this->assertEquals( $post_ids, $inverted ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
function setUp() { |
92
|
|
|
parent::setUp(); |
93
|
|
|
$this->import_coordinates = $this->prophesize( ImportCoordinates::class ); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.