ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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.

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(ProviderFactoryInterface::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 ]
94 );
95 }
$r
Definition: example_031.php:79

References $r.

◆ testCore()

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

Definition at line 98 of file IdentificationFactoryTest.php.

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

◆ testFactoryMustReturnCorrectTypeCore()

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

Definition at line 152 of file IdentificationFactoryTest.php.

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

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

◆ testFactoryMustReturnCorrectTypePlugin()

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

Definition at line 166 of file IdentificationFactoryTest.php.

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

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

◆ testPlugin()

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

Definition at line 105 of file IdentificationFactoryTest.php.

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

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

◆ testSerializingCore()

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

Definition at line 115 of file IdentificationFactoryTest.php.

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

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

◆ testUnserializingCore()

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

Definition at line 123 of file IdentificationFactoryTest.php.

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

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

◆ testUnserializingFailsSinceNobpbyCanhandleTheString()

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

Definition at line 144 of file IdentificationFactoryTest.php.

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

◆ testUnserializingPlugin()

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

Definition at line 133 of file IdentificationFactoryTest.php.

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

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: