ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest Class Reference

Class IdentificationFactoryTest. More...

+ Inheritance diagram for ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest:
+ Collaboration diagram for ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest:

Public Member Functions

 testAvailableMethods ()
 
 testCore ()
 
 testPlugin ()
 
 testSerializingCore ()
 
 testUnserializingCore ()
 
 testUnserializingPlugin ()
 
 testUnserializingFailsSinceNobpbyCanhandleTheString ()
 
 testFactoryMustReturnCorrectTypeCore ()
 
 testFactoryMustReturnCorrectTypePlugin ()
 

Data Fields

const MOCKED_PROVIDER_CLASSNAME = 'Mockery_1_ILIAS_GlobalScreen_Provider_Provider'
 

Protected Member Functions

 setUp ()
 @inheritDoc More...
 

Protected Attributes

 $provider_factory
 
 $provider_mock
 
 $plugin_mock
 
 $identification
 

Detailed Description

Class IdentificationFactoryTest.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

@runTestsInSeparateProcesses @preserveGlobalState disabled @backupGlobals disabled @backupStaticAttributes disabled

Definition at line 34 of file IdentificationFactoryTest.php.

Member Function Documentation

◆ setUp()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::setUp ( )
protected

@inheritDoc

Definition at line 59 of file IdentificationFactoryTest.php.

59 : void
60 {
61 parent::setUp();
62
63 $this->plugin_mock = Mockery::mock(ilPlugin::class);
64
65 $this->provider_mock = Mockery::mock(Provider::class);
66 $this->provider_mock->shouldReceive('getProviderNameForPresentation')->andReturn('Provider')->byDefault();
67
68 $this->provider_factory = Mockery::mock(ProviderFactory::class);
69 $this->provider_factory->shouldReceive('getProviderByClassName')->with(self::MOCKED_PROVIDER_CLASSNAME)->andReturn($this->provider_mock);
70 $this->provider_factory->shouldReceive('isInstanceCreationPossible')->andReturn(true);
71 $this->provider_factory->shouldReceive('isRegistered')->andReturn(true);
72
73 $this->identification = new IdentificationFactory($this->provider_factory);
74 }

◆ testAvailableMethods()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::testAvailableMethods ( )

Definition at line 77 of file IdentificationFactoryTest.php.

78 {
79 $r = new ReflectionClass($this->identification);
80
81 $methods = [];
82 foreach ($r->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
83 $methods[] = $method->getName();
84 }
85 sort($methods);
86 $this->assertEquals(
87 $methods,
88 [
89 0 => '__construct',
90 1 => 'core',
91 2 => 'fromSerializedIdentification',
92 3 => 'plugin',
93 4 => 'tool'
94 ]
95 );
96 }

◆ testCore()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::testCore ( )

Definition at line 99 of file IdentificationFactoryTest.php.

100 {
101 $this->assertInstanceOf(IdentificationProviderInterface::class, $this->identification->core($this->provider_mock));
102 $this->assertInstanceOf(IdentificationInterface::class, $this->identification->core($this->provider_mock)->identifier('dummy'));
103 }

◆ testFactoryMustReturnCorrectTypeCore()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::testFactoryMustReturnCorrectTypeCore ( )

Definition at line 153 of file IdentificationFactoryTest.php.

154 {
156 $internal_identifier = "internal_identifier";
157
158 $string_core = "{$class_name}|{$internal_identifier}";
159 $identification = $this->identification->fromSerializedIdentification($string_core);
160
161 $this->assertInstanceOf(CoreIdentification::class, $identification);
162 $this->assertEquals($identification->getClassName(), $class_name);
163 $this->assertEquals($identification->getInternalIdentifier(), $internal_identifier);
164 }

References ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest\$identification, and ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest\MOCKED_PROVIDER_CLASSNAME.

◆ testFactoryMustReturnCorrectTypePlugin()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::testFactoryMustReturnCorrectTypePlugin ( )

Definition at line 167 of file IdentificationFactoryTest.php.

168 {
170 $internal_identifier = "internal_identifier";
171
172 // $this->markTestSkipped('I currently have absolutely no idea why this test does not work since this seems to be identical zo the test testUnserializingCore :(');
173 $string_plugin = "xdemo|{$class_name}|{$internal_identifier}";
174 $identification = $this->identification->fromSerializedIdentification($string_plugin);
175
176 $this->assertInstanceOf(PluginIdentification::class, $identification);
177 $this->assertEquals($identification->getClassName(), $class_name);
178 $this->assertEquals($identification->getInternalIdentifier(), $internal_identifier);
179 }

References ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest\$identification, and ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest\MOCKED_PROVIDER_CLASSNAME.

◆ testPlugin()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::testPlugin ( )

Definition at line 106 of file IdentificationFactoryTest.php.

107 {
108 $this->plugin_mock->shouldReceive('getId')->once()->andReturn('xdemo');
109 $identification_provider = $this->identification->plugin($this->plugin_mock->getId(), $this->provider_mock);
110 $this->assertInstanceOf(IdentificationProviderInterface::class, $identification_provider);
111 $identification = $identification_provider->identifier('dummy');
112 $this->assertInstanceOf(IdentificationInterface::class, $identification);
113 }

References ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest\$identification.

◆ testSerializingCore()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::testSerializingCore ( )

Definition at line 116 of file IdentificationFactoryTest.php.

117 {
118 $identification = $this->identification->core($this->provider_mock)->identifier('dummy');
119 $this->assertInstanceOf(Serializable::class, $identification);
120 $this->assertEquals($identification->serialize(), get_class($this->provider_mock) . "|dummy");
121 }

References ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest\$identification.

◆ testUnserializingCore()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::testUnserializingCore ( )

Definition at line 124 of file IdentificationFactoryTest.php.

125 {
126 $identification = $this->identification->core($this->provider_mock)->identifier('dummy');
127 $serialized_identification = $identification->serialize();
128
129 $new_identification = $this->identification->fromSerializedIdentification($serialized_identification);
130 $this->assertEquals($identification, $new_identification);
131 }

References ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest\$identification.

◆ testUnserializingFailsSinceNobpbyCanhandleTheString()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::testUnserializingFailsSinceNobpbyCanhandleTheString ( )

Definition at line 145 of file IdentificationFactoryTest.php.

146 {
147 $this->expectException(InvalidArgumentException::class);
148 $this->expectExceptionMessage("Nobody can handle serialized identification 'ThisStringWillNobodyHandle'.");
149 $this->identification->fromSerializedIdentification("ThisStringWillNobodyHandle");
150 }

◆ testUnserializingPlugin()

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::testUnserializingPlugin ( )

Definition at line 134 of file IdentificationFactoryTest.php.

135 {
136 $this->plugin_mock->shouldReceive('getId')->once()->andReturn('xdemo');
137 $identification = $this->identification->plugin($this->plugin_mock->getId(), $this->provider_mock)->identifier('dummy');
138 $serialized_identification = $identification->serialize();
139 $this->provider_mock->shouldReceive('getProviderNameForPresentation')->andReturn('Provider');
140 $new_identification = $this->identification->fromSerializedIdentification($serialized_identification);
141 $this->assertEquals($identification, $new_identification);
142 }

References ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest\$identification.

Field Documentation

◆ $identification

◆ $plugin_mock

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::$plugin_mock
protected

Definition at line 49 of file IdentificationFactoryTest.php.

◆ $provider_factory

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::$provider_factory
protected

Definition at line 41 of file IdentificationFactoryTest.php.

◆ $provider_mock

ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::$provider_mock
protected

Definition at line 45 of file IdentificationFactoryTest.php.

◆ MOCKED_PROVIDER_CLASSNAME

const ILIAS\GlobalScreen\MainMenu\IdentificationFactoryTest::MOCKED_PROVIDER_CLASSNAME = 'Mockery_1_ILIAS_GlobalScreen_Provider_Provider'

The documentation for this class was generated from the following file: