# cookiebot/2.4.1/addons/tests/unit/test-get-option-name.php

Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA &amp; Google Consent Mode, version 2.4.1. 86 lines.

- Page: https://pluginprobe.com/plugins/cookiebot/2.4.1/code/addons/tests/unit/test-get-option-name.php
- Raw: https://pluginprobe.com/plugins/cookiebot/2.4.1/raw/addons/tests/unit/test-get-option-name.php
- Modified: 2018-11-18T21:31:22+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/cookiebot/2.4.1/code/addons/tests/unit/test-get-option-name.php#L10-L20`.

```php
<?php

namespace cookiebot_addons\tests\unit;

class Test_Get_Option_Name extends \WP_UnitTestCase {

	/**
	 * The file path of addons json
	 *
	 * @var string
	 */
	protected $file_path;

	/**
	 * The list of all addons, json encoded
	 *
	 * @var string
	 */
	protected $file;

	/**
	 * Get the plugins
	 *
	 * @since 1.8.0
	 */
	public function setUp() {
		$this->get_plugins();
	}

	/**
	 * Load the addons through json file.
	 *
	 * @since 1.8.0
	 */
	private function get_plugins() {
		$this->file_path = dirname( dirname( __DIR__ ) ) . '/addons.json';
		$this->file      = file_get_contents( $this->file_path );
		$this->plugins   = json_decode( $this->file );
	}

	/**
	 * Validate if the plugins in addons.json do exist as a class in addons controller directory.
	 *
	 * @since 1.8.0
	 */
	public function test_plugins_are_valid() {
		foreach ( $this->plugins as $plugin ) {
			$check = is_object( $plugin ) && class_exists( $plugin->class );
			$this->assertTrue( $check );
		}
	}

	/**
	 * Check if get_option_name is unique in every addon.
	 * @covers \cookiebot_addons\lib\Settings_Service_Interface
	 * @covers \cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface
	 * @covers \cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface
	 * @covers \cookiebot_addons\lib\buffer\Buffer_Output_Interface
	 *
	 * @version 2.1.3
	 * @since 1.8.0
	 */
	public function test_get_option_name_unique() {
		$options = array();

		$settingsMock        = $this->getMockBuilder( 'cookiebot_addons\lib\Settings_Service_Interface' )->getMock();
		$scriptLoaderTagMock = $this->getMockBuilder( 'cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface' )->getMock();
		$cookieConsentMock   = $this->getMockBuilder( 'cookiebot_addons\lib\Cookie_Consent_Interface' )->getMock();
		$bufferOutputMock    = $this->getMockBuilder( 'cookiebot_addons\lib\buffer\Buffer_Output_Interface' )->getMock();

		foreach ( $this->plugins as $plugin ) {
			$p = new $plugin->class( $settingsMock, $scriptLoaderTagMock, $cookieConsentMock, $bufferOutputMock );

			// if it doesn't have parent class
			if ( get_parent_class( $p ) === false ) {
				// test if the option_name exists in the options array
				$this->assertNotContains( $p->get_option_name(), $options );

				// add name to options array
				$options[] = $p->get_option_name();
			}

		}
	}

}
```
