| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright Copyright (C) eZ Systems AS. All rights reserved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license For full copyright and license information view LICENSE file distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace eZ\Publish\Core\Persistence\Legacy\Tests\Notification; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use eZ\Publish\Core\Persistence\Legacy\Notification\Mapper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use eZ\Publish\SPI\Persistence\Notification\Notification; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use eZ\Publish\SPI\Persistence\Notification\UpdateStruct; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class MapperTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** @var \eZ\Publish\Core\Persistence\Legacy\Notification\Mapper */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private $mapper; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     protected function setUp() | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         $this->mapper = new Mapper(); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Mapper::extractNotificationsFromRows | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function testExtractNotificationsFromRows() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $rows = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                 'id' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 'owner_id' => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                 'type' => 'FOO', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                 'created' => 1529913161, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 'is_pending' => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                 'data' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 'id' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 'owner_id' => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 'type' => 'BAR', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 'created' => 1529910161, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 'is_pending' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 'data' => json_encode([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                     'foo' => 'Foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                     'bar' => 'Bar', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                     'baz' => ['B', 'A', 'Z'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $objects = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             new Notification([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 'id' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 'ownerId' => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 'type' => 'FOO', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 'created' => 1529913161, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 'isPending' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                 'data' => [], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             new Notification([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 'id' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 'ownerId' => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 'type' => 'BAR', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 'created' => 1529910161, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                 'isPending' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 'data' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                     'foo' => 'Foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                     'bar' => 'Bar', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                     'baz' => ['B', 'A', 'Z'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             ]), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->assertEquals($objects, $this->mapper->extractNotificationsFromRows($rows)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Mapper::extractNotificationsFromRows | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @expectedException \RuntimeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     public function testExtractNotificationsFromRowsThrowsRuntimeException() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $rows = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 'id' => 1, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 'owner_id' => 5, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                 'type' => 'FOO', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 'created' => 1529913161, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                 'is_pending' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 'data' => '{ InvalidJSON }', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $this->mapper->extractNotificationsFromRows($rows); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @covers \eZ\Publish\Core\Persistence\Legacy\Notification\Mapper::createNotificationFromUpdateStruct | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     public function testCreateNotificationFromUpdateStruct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $updateStruct = new UpdateStruct([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             'isPending' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         ]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $this->assertEquals(new Notification([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             'isPending' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         ]), $this->mapper->createNotificationFromUpdateStruct($updateStruct)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 113 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |  |