| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright Aimeos (aimeos.org), 2018-2022 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Aimeos\Controller\Jobs\Subscription\Export\Csv; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class StandardTest extends \PHPUnit\Framework\TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	private $aimeos; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	private $context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	private $object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	protected function setUp() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$this->aimeos = \TestHelper::getAimeos(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		$this->context = \TestHelper::context(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$this->object = new \Aimeos\Controller\Jobs\Subscription\Export\Csv\Standard( $this->context, $this->aimeos ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	protected function tearDown() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		unset( $this->object, $this->context, $this->aimeos ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	public function testGetName() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		$this->assertEquals( 'Subscription export CSV', $this->object->getName() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	public function testGetDescription() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$this->assertEquals( 'Exports subscriptions to CSV file', $this->object->getDescription() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	public function testRun() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		$mqmStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Manager\\Standard' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			->setConstructorArgs( [[]] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 			->setMethods( ['get'] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		$mqStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Standard' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			->setMethods( ['getQueue'] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$queueStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Queue\\Standard' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			->setMethods( ['del', 'get'] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 		$msgStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Message\\Standard' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 			->disableOriginalConstructor() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			->setMethods( ['getBody'] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			->getMock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$this->context->setMessageQueueManager( $mqmStub ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		$mqmStub->expects( $this->once() )->method( 'get' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			->will( $this->returnValue( $mqStub ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$mqStub->expects( $this->once() )->method( 'getQueue' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 			->will( $this->returnValue( $queueStub ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		$queueStub->expects( $this->exactly( 2 ) )->method( 'get' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			->will( $this->onConsecutiveCalls( $msgStub, null ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		$queueStub->expects( $this->once() )->method( 'del' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		$msgStub->expects( $this->once() )->method( 'getBody' ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			->will( $this->returnValue( '{"sitecode":"unittest"}' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		$this->object->run(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$jobManager = \Aimeos\MAdmin::create( $this->context, 'job' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$jobSearch = $jobManager->filter(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		$jobSearch->setConditions( $jobSearch->compare( '=~', 'job.label', 'subscription-export_' ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 		$jobItems = $jobManager->search( $jobSearch ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 		$jobManager->delete( $jobItems->toArray() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		$this->assertEquals( 1, count( $jobItems ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		$filename = dirname( dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) ) . '/tmp/' . $jobItems->first()->getLabel(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		$fp = fopen( $filename, 'r' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		$subscription = fgetcsv( $fp ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		$address1 = fgetcsv( $fp ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 		$address2 = fgetcsv( $fp ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		$product1 = fgetcsv( $fp ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 		fclose( $fp ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		unlink( $filename ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 		$this->assertEquals( 'subscription', $subscription[0] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 		$this->assertEquals( 'address', $address1[0] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 		$this->assertEquals( 'address', $address2[0] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 		$this->assertEquals( 'product', $product1[0] ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 116 |  |  |  |